From dab1679ad75f4e82dbfa420f86b633ce8c139910 Mon Sep 17 00:00:00 2001 From: Ross Baird Date: Sun, 2 Dec 2018 20:09:21 +1300 Subject: [PATCH] Finally cracked day 23 part 2 --- 2017/23/README.md | 13 +++++++++++++ 2017/23/part2.rb | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 2017/23/part2.rb diff --git a/2017/23/README.md b/2017/23/README.md index a75cadd..e9fb483 100644 --- a/2017/23/README.md +++ b/2017/23/README.md @@ -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? diff --git a/2017/23/part2.rb b/2017/23/part2.rb new file mode 100644 index 0000000..dde9f48 --- /dev/null +++ b/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)} +