aboutsummaryrefslogtreecommitdiff
path: root/day09.rb
blob: ed764652847159c6684f44aa1e0090f47b90f7fd (plain) (blame)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
s = [0]

m = 1
i = 0

mp = 9
mr = 25

mp = 10
mr = 1618
=begin

mp = 13
mr = 7999

mp, mr =  File.read("day09").scan(/\d+/).map(&:to_i)
mr *= 100  # part 2

p mr
=end

scores = Hash.new(0)

catch(:done) {
loop {
  (1..mp).each { |p|
    print m, " ", i, " ", s.size, " "
    p s

    if m % 23 == 0
      scores[p] += m
      print "score1 #{p} #{m}\n"
      i = (i - 8) % s.size
      print "score2 #{p} #{s[i]}\n"
      scores[p] += s.delete_at(i)
      
      i = (i+1)%s.size
      m += 1
    else
      i += 1
      s.insert(i, m)
      i = (i+1)%s.size
      m += 1
    end

    p m  if m % 100000 == 0

    throw :done if m >= mr+1
  }
}
}

p scores
p scores.values.max  # 382055