aboutsummaryrefslogtreecommitdiff
path: root/day15/part1
blob: 067ee059ee59d8046f18b265d40c4ceeaba47ceb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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