about summary refs log tree commit diff
path: root/day09.rb
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2019-11-28 17:38:10 +0100
committerLeah Neukirchen <leah@vuxu.org>2019-11-28 17:38:10 +0100
commite12436c99bb04897d6344b6351d0336e4c627573 (patch)
tree74f8afb9de5d2a466e5fe6225df3661e1280519e /day09.rb
parent05050c3b5e20d5d475894788df6c31f867d2c51a (diff)
downloadadventofcode2018-e12436c99bb04897d6344b6351d0336e4c627573.tar.gz
adventofcode2018-e12436c99bb04897d6344b6351d0336e4c627573.tar.xz
adventofcode2018-e12436c99bb04897d6344b6351d0336e4c627573.zip
add rest HEAD master
Diffstat (limited to 'day09.rb')
-rw-r--r--day09.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/day09.rb b/day09.rb
new file mode 100644
index 0000000..ed76465
--- /dev/null
+++ b/day09.rb
@@ -0,0 +1,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