aboutsummaryrefslogtreecommitdiff
path: root/day15/part1
diff options
context:
space:
mode:
authorNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-15 23:14:10 +0000
committerNat Lasseter <Nat Lasseter nathan@bytemark.co.uk>2017-12-15 23:14:10 +0000
commit999db74bb78ccded11230933ff5d247c51040a29 (patch)
treea80b1a59489ff48a904f5a06630f8dd0a93faa97 /day15/part1
parent630bb4d3527eb5ae2f9789cb689088558a6173a8 (diff)
Day15
Diffstat (limited to 'day15/part1')
-rwxr-xr-xday15/part131
1 files changed, 31 insertions, 0 deletions
diff --git a/day15/part1 b/day15/part1
new file mode 100755
index 0000000..067ee05
--- /dev/null
+++ b/day15/part1
@@ -0,0 +1,31 @@
+#!/usr/bin/env ruby
+
+class Generator
+ def initialize(iv, factor)
+ @value = iv
+ @factor = factor
+ end
+
+ def next
+ n = (@value * @factor) % 2147483647
+ @value = n
+ return n
+ end
+end
+
+input = $stdin.readlines.map(&:chomp)
+
+ga = Generator.new(input[0].split[4].to_i, 16807)
+gb = Generator.new(input[1].split[4].to_i, 48271)
+
+matches = 0
+
+Mask = 2**16
+
+40_000_000.times do
+ a = ga.next % Mask
+ b = gb.next % Mask
+ matches += 1 if a == b
+end
+
+p matches