diff --git a/2024/ruby/day_17.rb b/2024/ruby/day_17.rb index 993b71f..dcf8120 100644 --- a/2024/ruby/day_17.rb +++ b/2024/ruby/day_17.rb @@ -96,21 +96,21 @@ end pp run(27334280).to_a.join(?,) -TARGET = "2412750317415530".chars.map(&:to_i) -def solve(a) +def solve(a, target) return [a] if a.size == 16 (0..7) .map { a + [_1] } .select {|a| - TARGET.reverse[0,a.size].zip( + target.reverse[0,a.size].zip( run(a.join.ljust(14, ?0).to_i(8)).to_a.reverse ).all? { _1 == _2 } - }.flat_map { solve(_1) } + }.flat_map { solve(_1, target) } end -pp solve([]).map(&:join).map { _1.to_i(8) }.min -pp run(190615597431823).to_a == program +a = solve([], program).map(&:join).map { _1.to_i(8) }.min +pp a +pp run(a).to_a == program __END__ Register A: 27334280