-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8b59b22
commit d96b50e
Showing
2 changed files
with
23 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
abcde | ||
fghij | ||
klmno | ||
pqrst | ||
fguij | ||
axcye | ||
wvxyz |