From 7dcc57442fcbaa83e40bf5f832799e235b6b2f57 Mon Sep 17 00:00:00 2001 From: Christian Neukirchen Date: Thu, 10 Dec 2015 14:26:15 +0100 Subject: day10 --- day10.k | 15 +++++++++++++++ day10.rb | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 day10.k create mode 100644 day10.rb 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 -- cgit 1.4.1