DEV Community

Discussion on: Advent of Code 2020 Solution Megathread - Day 10: Adapter Array

Collapse
 
craigontour profile image
craigontour

I also use Ruby (if I have time try to replicate in Python for learning) and found part 1 ok.

 input = File.read('day10.txt').split("\n").map(&:to_i).sort!.insert(0, 0)
 input.push(input[-1]+3)

 puts "Part 1:"
 puts (0...(input.length-1)).each
                            .map { |a| input[a+1]-input[a] }
                            .group_by { |n| n }
                            .map { |e, v| v.length }
                            .reduce(:*)
Enter fullscreen mode Exit fullscreen mode

But Part 2 stumped me. I got the general gist of the problem, but couldn't get started on a solution.