Skip to content

Commit

Permalink
Finally cracked day 23 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
raspygold committed Dec 2, 2018
1 parent 1701c3a commit dab1679
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 2017/23/README.md
Expand Up @@ -12,3 +12,16 @@ Only the instructions listed above are used. The eight registers here, named a t
The coprocessor is currently set to some kind of debug mode, which allows for testing, but prevents it from doing any meaningful work.

If you run the program (your puzzle input), how many times is the mul instruction invoked?


--- Part Two ---

Now, it's time to fix the problem.

The debug mode switch is wired directly to register a. You flip the switch, which makes register a now start at 1 when the program is executed.

Immediately, the coprocessor begins to overheat. Whoever wrote this program obviously didn't choose a very efficient implementation. You'll need to optimize the program if it has any hope of completing before Santa needs that printer working.

The coprocessor's ultimate goal is to determine the final value left in register h once the program completes. Technically, if it had that... it wouldn't even need to run the program.

After setting register a to 1, if the program were to run to completion, what value would be left in register h?
10 changes: 10 additions & 0 deletions 2017/23/part2.rb
@@ -0,0 +1,10 @@
#!/usr/bin/env ruby
file_path = File.expand_path("../input", __FILE__)
input = File.readlines(file_path)

b = input.first.split(" ")[2].to_i * 100 + 100000
c = b + 17000

require "prime"
puts (b..c).step(17).count {|b| !Prime.prime?(b)}

0 comments on commit dab1679

Please sign in to comment.