From 41ecc75d622abd90672f28e446fcd6341637a38b Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Wed, 18 Dec 2024 12:31:44 -0800 Subject: [PATCH] [2024][ruby][17.2] refactored --- 2024/ruby/day_17.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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