diff options
author | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-12-25 15:26:01 +0100 |
---|---|---|
committer | Marcin Chrzanowski <marcin.j.chrzanowski@gmail.com> | 2020-12-25 15:26:01 +0100 |
commit | 5a28775f19a8a48b67fc41e048c2a3958afa1e42 (patch) | |
tree | 8cababf438ee509ccb51a2023430891876cc2d88 /10 | |
parent | 15c6d8d79d9ec00a7abb14f90bd65547893c76f2 (diff) |
Add day 10
Diffstat (limited to '10')
-rw-r--r-- | 10/a.rb | 10 | ||||
-rw-r--r-- | 10/b.rb | 7 | ||||
-rw-r--r-- | 10/input.txt | 102 |
3 files changed, 119 insertions, 0 deletions
@@ -0,0 +1,10 @@ +lines = File.readlines('input.txt').map { |l| l.to_i } +lines.sort! +lines.unshift(0) +lines.push(lines.last + 3) +diffs = Hash.new 0 +lines.each_cons 2 do |chargers| + diffs[chargers[1] - chargers[0]] += 1 +end + +puts diffs[1] * diffs[3] @@ -0,0 +1,7 @@ +lines = File.readlines('input.txt').map { |l| l.to_i }.unshift(0).sort! +arrs = Hash.new 0 +arrs[0] = 1 +lines.slice(1, lines.size).each do |line| + arrs[line] += arrs[line - 1] + arrs[line - 2] + arrs[line - 3] +end +puts arrs[lines.last] diff --git a/10/input.txt b/10/input.txt new file mode 100644 index 0000000..5b0d755 --- /dev/null +++ b/10/input.txt @@ -0,0 +1,102 @@ +153 +17 +45 +57 +16 +147 +39 +121 +75 +70 +85 +134 +128 +115 +51 +139 +44 +65 +119 +168 +122 +72 +105 +31 +103 +89 +154 +114 +55 +25 +48 +38 +132 +157 +84 +71 +113 +143 +83 +64 +109 +129 +120 +100 +151 +79 +125 +22 +161 +167 +19 +26 +118 +142 +4 +158 +11 +35 +56 +18 +40 +7 +150 +99 +54 +152 +60 +27 +164 +78 +47 +82 +63 +46 +91 +32 +135 +3 +108 +10 +159 +127 +69 +110 +126 +133 +28 +15 +104 +138 +160 +98 +90 +144 +1 +2 +92 +41 +86 +66 +95 +12 |