|
|
@ -96,21 +96,21 @@ end
|
|
|
|
|
|
|
|
|
|
|
|
pp run(27334280).to_a.join(?,)
|
|
|
|
pp run(27334280).to_a.join(?,)
|
|
|
|
|
|
|
|
|
|
|
|
TARGET = "2412750317415530".chars.map(&:to_i)
|
|
|
|
def solve(a, target)
|
|
|
|
def solve(a)
|
|
|
|
|
|
|
|
return [a] if a.size == 16
|
|
|
|
return [a] if a.size == 16
|
|
|
|
|
|
|
|
|
|
|
|
(0..7)
|
|
|
|
(0..7)
|
|
|
|
.map { a + [_1] }
|
|
|
|
.map { a + [_1] }
|
|
|
|
.select {|a|
|
|
|
|
.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
|
|
|
|
run(a.join.ljust(14, ?0).to_i(8)).to_a.reverse
|
|
|
|
).all? { _1 == _2 }
|
|
|
|
).all? { _1 == _2 }
|
|
|
|
}.flat_map { solve(_1) }
|
|
|
|
}.flat_map { solve(_1, target) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
pp solve([]).map(&:join).map { _1.to_i(8) }.min
|
|
|
|
a = solve([], program).map(&:join).map { _1.to_i(8) }.min
|
|
|
|
pp run(190615597431823).to_a == program
|
|
|
|
pp a
|
|
|
|
|
|
|
|
pp run(a).to_a == program
|
|
|
|
|
|
|
|
|
|
|
|
__END__
|
|
|
|
__END__
|
|
|
|
Register A: 27334280
|
|
|
|
Register A: 27334280
|
|
|
|