|
|
@ -1,14 +1,5 @@
|
|
|
|
input = ARGF.readlines(chomp: true).map(&:chars)
|
|
|
|
input = ARGF.readlines(chomp: true).map(&:chars)
|
|
|
|
|
|
|
|
|
|
|
|
# part one
|
|
|
|
|
|
|
|
p input.transpose
|
|
|
|
|
|
|
|
.map {|col| col.chunk_while { [_1, _2].tally.fetch(?#, 0).even? }}
|
|
|
|
|
|
|
|
.map {|col| col.flat_map { _1.sort.reverse }}
|
|
|
|
|
|
|
|
.transpose
|
|
|
|
|
|
|
|
.reverse
|
|
|
|
|
|
|
|
.each.with_index
|
|
|
|
|
|
|
|
.sum {|row, i| row.count(?O) * (i+1) }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# always tilts left
|
|
|
|
# always tilts left
|
|
|
|
def tilt(platform)
|
|
|
|
def tilt(platform)
|
|
|
|
platform
|
|
|
|
platform
|
|
|
@ -16,6 +7,15 @@ def tilt(platform)
|
|
|
|
.map {|row| row.flat_map { _1.sort.reverse }}
|
|
|
|
.map {|row| row.flat_map { _1.sort.reverse }}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load(platform)
|
|
|
|
|
|
|
|
platform.reverse
|
|
|
|
|
|
|
|
.each.with_index
|
|
|
|
|
|
|
|
.sum {|row, i| row.count(?O) * (i+1) }
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# part one
|
|
|
|
|
|
|
|
p load(tilt(input.transpose).transpose)
|
|
|
|
|
|
|
|
|
|
|
|
def spin_cycle(platform)
|
|
|
|
def spin_cycle(platform)
|
|
|
|
return enum_for(__method__, platform) unless block_given?
|
|
|
|
return enum_for(__method__, platform) unless block_given?
|
|
|
|
|
|
|
|
|
|
|
@ -41,6 +41,7 @@ spin = spin_cycle(input)
|
|
|
|
seen = {}
|
|
|
|
seen = {}
|
|
|
|
(1_000_000_000).times do |i|
|
|
|
|
(1_000_000_000).times do |i|
|
|
|
|
platform = spin.next
|
|
|
|
platform = spin.next
|
|
|
|
|
|
|
|
|
|
|
|
if seen.has_key?(platform.hash)
|
|
|
|
if seen.has_key?(platform.hash)
|
|
|
|
start, _ = seen.fetch(platform.hash)
|
|
|
|
start, _ = seen.fetch(platform.hash)
|
|
|
|
i = (1_000_000_000 - start) % (i+1 - start) + start
|
|
|
|
i = (1_000_000_000 - start) % (i+1 - start) + start
|
|
|
@ -48,9 +49,6 @@ seen = {}
|
|
|
|
exit
|
|
|
|
exit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
load = platform.reverse
|
|
|
|
seen[platform.hash] = [i+1, load(platform)]
|
|
|
|
.each.with_index
|
|
|
|
|
|
|
|
.sum {|row, i| row.count(?O) * (i+1) }
|
|
|
|
|
|
|
|
seen[platform.hash] = [i+1, load]
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|