[2024][ruby][17.2] refactored

main
Alpha Chen 4 days ago
parent a91994d28d
commit 41ecc75d62
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -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

Loading…
Cancel
Save