solved part 1

master
s00ner 2021-11-10 14:01:05 -05:00
parent 7044bcdc23
commit 536f505093
1 changed files with 13 additions and 0 deletions

13
day02/solution.rb Normal file
View File

@ -0,0 +1,13 @@
#!/bin/env ruby
ids = File.readlines('./input').map(&:strip)
checksum = {twos: 0, threes: 0}
ids.map! { |id| id.each_char.tally.delete_if { |char, count| count==1 }}
ids.each do |id|
checksum[:twos] += 1 if id.has_value?(2)
checksum[:threes] += 1 if id.has_value?(3)
end
puts checksum[:twos] * checksum[:threes]