Created
December 6, 2019 14:28
-
-
Save klebervirgilio/989a0b37af154ca2bf0288fce4b6416d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
INPUT = [ | |
1,12,2,3, | |
1,1,2,3, | |
1,3,4,3, | |
1,5,0,3, | |
2,10,1,19, | |
1,5,19,23, | |
1,23,5,27, | |
1,27,13,31, | |
1,31,5,35, | |
1,9,35,39, | |
2,13,39,43, | |
1,43,10,47, | |
1,47,13,51, | |
2,10,51,55, | |
1,55,5,59, | |
1,59,5,63, | |
1,63,13,67, | |
1,13,67,71, | |
1,71,10,75, | |
1,6,75,79, | |
1,6,79,83, | |
2,10,83,87, | |
1,87,5,91, | |
1,5,91,95, | |
2,95,10,99, | |
1,9,99,103, | |
1,103,13,107, | |
2,10,107,111, | |
2,13,111,115, | |
1,6,115,119, | |
1,119,10,123, | |
2,9,123,127, | |
2,127,9,131, | |
1,131,10,135, | |
1,135,2,139, | |
1,10,139,0,99, | |
2,0,14,0] | |
B = INPUT.dup | |
def opcode_1(input, p1, p2, p3) | |
input[p3] = input[p1] + input[p2] | |
end | |
def opcode_2(input, p1, p2, p3) | |
input[p3] = input[p1] * input[p2] | |
end | |
(0..99).to_a.permutation(2).each do |verb, noun| | |
run = INPUT.dup | |
run[1] = verb | |
run[2] = noun | |
run.each_slice(4) do |(opcde, p1, p2, output)| | |
if opcde == 1 | |
opcode_1(run, p1, p2, output) | |
next | |
end | |
if opcde == 2 | |
opcode_2(run, p1, p2, output) | |
next | |
end | |
break if opcde == 99 | |
end | |
puts run[0] | |
if run[0] == 19690720 | |
puts [verb, noun].join(" << | >> ") | |
break | |
end | |
end | |
# puts B.join(", ") | |
# puts INPUT.join(", ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment