about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-10 14:26:15 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-10 14:26:15 +0100
commit7dcc57442fcbaa83e40bf5f832799e235b6b2f57 (patch)
tree0afbf081c9345105b2aeaa9386a4d3cfe6c00a62
parent4af2965c747210abb8ca2a405b45bcd1e513074e (diff)
downloadadventofcode2015-7dcc57442fcbaa83e40bf5f832799e235b6b2f57.tar.gz
adventofcode2015-7dcc57442fcbaa83e40bf5f832799e235b6b2f57.tar.xz
adventofcode2015-7dcc57442fcbaa83e40bf5f832799e235b6b2f57.zip
day10
-rw-r--r--day10.k15
-rw-r--r--day10.rb13
2 files changed, 28 insertions, 0 deletions
diff --git a/day10.k b/day10.k
new file mode 100644
index 0000000..0b86ba8
--- /dev/null
+++ b/day10.k
@@ -0,0 +1,15 @@
+d:"1113122113"
+
+/ r:{o:(x=*x)?0;:[o=#x;,x;(,(o#x)),_f[o _ x]]}
+r:{(0,1+&~=':x) _ x} / group consecutive elements
+
+l:{,/ {($#x),*x}' r x} / look-and-say, 1 step
+
+s:(40 l/d)
+
+v: #s
+
+s:(10 l/s) / 10 more steps
+/ for some reason this takes ages...
+
+v: #s
diff --git a/day10.rb b/day10.rb
new file mode 100644
index 0000000..a429aff
--- /dev/null
+++ b/day10.rb
@@ -0,0 +1,13 @@
+def ls(s)
+  n = ""
+  s.scan(/(\d)\1*/) {
+    n << "#{$&.size}#{$1}"
+  }
+  n
+end
+
+d = "1113122113"
+40.times { d = ls(d) }
+p d.size
+10.times { d = ls(d) }
+p d.size