Created
December 5, 2019 04:38
-
-
Save mgates/e5ff63153c75ebbbe68b4309e69cfac9 to your computer and use it in GitHub Desktop.
advent 2019 day 3
This file contains hidden or 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
| class Thing | |
| def do_it(pos_1, pos_2, *input) | |
| nums = input.dup | |
| nums[1] = pos_1 | |
| nums[2] = pos_2 | |
| pos = 0 | |
| while true | |
| case nums[pos] | |
| when 99 | |
| return nums | |
| when 1 | |
| (nums[nums[pos + 3]] = nums[nums[pos + 1]] + nums[nums[pos + 2]]) | |
| pos += 4 | |
| when 2 | |
| (nums[nums[pos + 3]] = nums[nums[pos + 1]] * nums[nums[pos + 2]]) | |
| pos += 4 | |
| end | |
| end | |
| end | |
| def do_it_better(*nums) | |
| (0..99).each do |a| | |
| (0..99).each do |b| | |
| puts [a,b].inspect | |
| raise [a, b] if do_it(a,b, *nums)[0] == 19690720 | |
| end | |
| end | |
| end | |
| end | |
| #Thing.new.do_it(12, 2, *ARGF.read.chomp.split(",").map(&:to_i)) | |
| Thing.new.do_it_better(*ARGF.read.chomp.split(",").map(&:to_i)) |
This file contains hidden or 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
| 1,0,0,3,1,1,2,3,1,3,4,3,1,5,0,3,2,13,1,19,1,6,19,23,2,6,23,27,1,5,27,31,2,31,9,35,1,35,5,39,1,39,5,43,1,43,10,47,2,6,47,51,1,51,5,55,2,55,6,59,1,5,59,63,2,63,6,67,1,5,67,71,1,71,6,75,2,75,10,79,1,79,5,83,2,83,6,87,1,87,5,91,2,9,91,95,1,95,6,99,2,9,99,103,2,9,103,107,1,5,107,111,1,111,5,115,1,115,13,119,1,13,119,123,2,6,123,127,1,5,127,131,1,9,131,135,1,135,9,139,2,139,6,143,1,143,5,147,2,147,6,151,1,5,151,155,2,6,155,159,1,159,2,163,1,9,163,0,99,2,0,14,0 |
This file contains hidden or 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
| 99 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment