From e4657f1f087c91d4b7ca008fb8e5ad799cb610b7 Mon Sep 17 00:00:00 2001 From: Jeff Yates Date: Thu, 10 Dec 2020 12:08:38 -0500 Subject: [PATCH] solved part 2 --- day10/solution2.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100755 day10/solution2.rb diff --git a/day10/solution2.rb b/day10/solution2.rb new file mode 100755 index 0000000..e2f6294 --- /dev/null +++ b/day10/solution2.rb @@ -0,0 +1,36 @@ +#!/bin/env ruby +require 'pry' +numbers = File.read('./input').split("\n").map(&:to_i).sort +numbers.prepend(0) +numbers.push(numbers[-1] + 3) +#binding.pry +solution = numbers.map.with_index do |num, i| + next if i == 0 + num - numbers[i-1] +end +solution.compact! +count = [0] +count_i = 0 +solution.each.with_index do |num, i| + next if i == 0 + if num == 3 + count_i += 1 + count.push(0) + next + end + count[count_i] += 1 if solution[i-1] == 1 +end + +count.delete(0) +count.map! do |num| + case num + when 1 + 2 + when 2 + 4 + when 3 + 7 + end +end + +p count.reduce(:*) \ No newline at end of file