Skip to content

Commit

Permalink
Year 2018 Day 2
Browse files Browse the repository at this point in the history
  • Loading branch information
tudorpavel committed Oct 29, 2024
1 parent 8b59b22 commit d96b50e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 2018/day02.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ids = STDIN.read.split("\n")

def count_for(ids, size)
ids.count { |id| id.chars.tally.values.include?(size) }
end

puts count_for(ids, 2) * count_for(ids, 3)

def part2(ids)
ids.combination(2).each do |(a, b)|
pairs = a.chars.zip(b.chars)
same = pairs.filter { |(x, y)| x == y }
return same.map(&:first).join if same.size == pairs.size - 1
end
end
puts part2(ids)
7 changes: 7 additions & 0 deletions 2018/examples/day02.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
abcde
fghij
klmno
pqrst
fguij
axcye
wvxyz

0 comments on commit d96b50e

Please sign in to comment.