about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-12-15 20:49:31 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-12-15 20:49:31 +0100
commitf50c04e071ededa9ddbe74e072caffd8e3d0cbec (patch)
tree56dea8addfaa95eb3e1de85c8383542a89760bfd
parent5e19826f9e3ba429e20e5b6f835a17b98ece47ce (diff)
downloadadventofcode2016-f50c04e071ededa9ddbe74e072caffd8e3d0cbec.tar.gz
adventofcode2016-f50c04e071ededa9ddbe74e072caffd8e3d0cbec.tar.xz
adventofcode2016-f50c04e071ededa9ddbe74e072caffd8e3d0cbec.zip
day15
-rw-r--r--day156
-rw-r--r--day15.k14
-rw-r--r--day15.rb15
3 files changed, 35 insertions, 0 deletions
diff --git a/day15 b/day15
new file mode 100644
index 0000000..396cee2
--- /dev/null
+++ b/day15
@@ -0,0 +1,6 @@
+Disc #1 has 13 positions; at time=0, it is at position 10.
+Disc #2 has 17 positions; at time=0, it is at position 15.
+Disc #3 has 19 positions; at time=0, it is at position 17.
+Disc #4 has 7 positions; at time=0, it is at position 1.
+Disc #5 has 5 positions; at time=0, it is at position 0.
+Disc #6 has 3 positions; at time=0, it is at position 1.
diff --git a/day15.k b/day15.k
new file mode 100644
index 0000000..7741439
--- /dev/null
+++ b/day15.k
@@ -0,0 +1,14 @@
+{n::x;p::y}.+{.:'x 3 11}'" "\'0:"day15"
+{n::x;p::y}..:''(+" "\'0:"day15")@3 11
+
+-1+{0<+/n!'p+x+!#p}(1+)/0	/ 203660
+-1+{(0<+/x!'y+(!#y)+)(1+)/0}..:''(+" "\'0:"day15")@3 11
+{m::*/x;m!+/(x-x!'y+1+!#y)*{v*(~1=x!(v:m%x)*)(1+)/1}'x}..:''(+" "\'0:"day15")@3 11
+-1+0{(0<y[1]!y[0]+)(y[2]+)/x}/{(+(y+!#y;x;-1_1,*\x))}..:''(+" "\'0:"day15")@3 11
+
+n,:11; p,:0
+
+-1+{0<+/n!'p+x+!#p}(1+)/0	/ 2408135
+-1+{(0<+/x!'y+(!#y)+)(1+)/0}.(.:''(+" "\'0:"day15")@3 11),'11 0
+{m::*/x;m!+/(x-x!'y+1+!#y)*{v*(~1=x!(v:m%x)*)(1+)/1}'x}.(.:''(+" "\'0:"day15")@3 11),'11 0
+-1+0{(0<y[1]!y[0]+)(y[2]+)/x}/{(+(y+!#y;x;-1_1,*\x))}.(.:''(+" "\'0:"day15")@3 11),'11 0
diff --git a/day15.rb b/day15.rb
new file mode 100644
index 0000000..f108b61
--- /dev/null
+++ b/day15.rb
@@ -0,0 +1,15 @@
+t = 0
+step = 1
+
+(IO.readlines("day15") << "Disc #7 has 11 positions; at time=0, it is at position 0."
+).each.with_index { |line, i|
+  size, pos = line.scan(/ \d+/).map(&:to_i)
+  
+  while (i+pos+t) % size != 0
+    t += step
+  end
+  
+  step *= size
+}
+
+p t-1