about summary refs log tree commit diff
path: root/day09.rb
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-12-10 22:37:57 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2016-12-10 22:37:57 +0100
commiteef4018cca804ae67ea989970ff69ba90e9e1f05 (patch)
treea2b4b3603f5690e3d927acad660863c14c5a1437 /day09.rb
parent717e024fe828970d91b051d9e97fead019f1fd01 (diff)
downloadadventofcode2016-eef4018cca804ae67ea989970ff69ba90e9e1f05.tar.gz
adventofcode2016-eef4018cca804ae67ea989970ff69ba90e9e1f05.tar.xz
adventofcode2016-eef4018cca804ae67ea989970ff69ba90e9e1f05.zip
day09
Diffstat (limited to 'day09.rb')
-rw-r--r--day09.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/day09.rb b/day09.rb
new file mode 100644
index 0000000..eba5d58
--- /dev/null
+++ b/day09.rb
@@ -0,0 +1,28 @@
+s = File.read("day09").chomp
+
+o = ""
+while s =~ /\((\d+)x(\d+)\)/
+  o << $`
+  a, b = $1.to_i, $2.to_i
+  o << $'[0,a]*b
+  s = $'[a..-1]
+end
+o << s
+p o.size
+
+s = File.read("day09")
+
+def len(s)
+  o = 0
+  while s =~ /\((\d+)x(\d+)\)/
+    o += $`.size
+    r = $'
+    a, b = $1.to_i, $2.to_i
+    o += len(r[0,a])*b
+    s = r[a..-1]
+  end
+  o += s.size
+  o
+end
+
+p len(File.read("day09").chomp)