about summary refs log tree commit diff
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2015-12-17 14:44:04 +0100
committerChristian Neukirchen <chneukirchen@gmail.com>2015-12-17 14:44:04 +0100
commit2c1f146376d708959defa553cb8e3b9a0a6ae60e (patch)
treee827a1de3aff9d9ccabdfe9decbbae4920ac07cc
parent24182ea87ccea37d00ffa4c15583ac1b97e613e5 (diff)
downloadadventofcode2015-2c1f146376d708959defa553cb8e3b9a0a6ae60e.tar.gz
adventofcode2015-2c1f146376d708959defa553cb8e3b9a0a6ae60e.tar.xz
adventofcode2015-2c1f146376d708959defa553cb8e3b9a0a6ae60e.zip
day17
-rw-r--r--day1720
-rw-r--r--day17.k6
-rw-r--r--day17.rb29
3 files changed, 55 insertions, 0 deletions
diff --git a/day17 b/day17
new file mode 100644
index 0000000..6b25a72
--- /dev/null
+++ b/day17
@@ -0,0 +1,20 @@
+33
+14
+18
+20
+45
+35
+16
+35
+1
+13
+18
+13
+50
+44
+48
+6
+24
+41
+30
+42
diff --git a/day17.k b/day17.k
new file mode 100644
index 0000000..aaecf70
--- /dev/null
+++ b/day17.k
@@ -0,0 +1,6 @@
+d:0$'0:"day17";
+g:150;
+
+s:{x@&150=+/'x}@d@&:'!(#d)#2 / brute-force: subsets with sum g
+#s
+#&{x=&/x}@#:'s
diff --git a/day17.rb b/day17.rb
new file mode 100644
index 0000000..465b485
--- /dev/null
+++ b/day17.rb
@@ -0,0 +1,29 @@
+d = File.readlines("day17").map { |x| x.to_i }
+t = 150
+
+d.sort!
+
+$c = 0
+$cs = Hash.new(0)
+
+def r(u, s, a, t)
+  if s == t
+    p u
+    $c += 1
+    $cs[u.size] += 1
+  elsif s > t
+    # too high
+  else
+    a.each_index { |i|
+      r(u + [a[i]], s+a[i], a[i+1..-1], t)
+    }
+  end
+end
+
+p d
+
+r([], 0, d, t)
+p $c
+p $cs
+
+# 313265 too high