From 5a28775f19a8a48b67fc41e048c2a3958afa1e42 Mon Sep 17 00:00:00 2001 From: Marcin Chrzanowski Date: Fri, 25 Dec 2020 15:26:01 +0100 Subject: Add day 10 --- 10/a.rb | 10 ++++++ 10/b.rb | 7 ++++ 10/input.txt | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 119 insertions(+) create mode 100644 10/a.rb create mode 100644 10/b.rb create mode 100644 10/input.txt (limited to '10') diff --git a/10/a.rb b/10/a.rb new file mode 100644 index 0000000..34336ef --- /dev/null +++ b/10/a.rb @@ -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] diff --git a/10/b.rb b/10/b.rb new file mode 100644 index 0000000..d27f1ab --- /dev/null +++ b/10/b.rb @@ -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 -- cgit v1.2.3