Created
December 4, 2022 16:42
-
-
Save cjavdev/864bec6b1b6bc423be487d234009f9bf to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# data = DATA.readlines | |
data = File.readlines(ARGV.first) | |
# PART 1 | |
# result = data | |
# .map(&:chomp) | |
# .map(&:chars) | |
# .map { _1.each_slice(_1.length / 2).to_a } | |
# .map {|(left, right)| left & right } | |
# .flatten | |
# .map { _1 =~ /[A-Z]/ ? _1.ord - 38 : _1.ord - 96 } | |
# .sum | |
# PART 2 | |
result = data | |
.map(&:chomp) | |
.each_slice(3) | |
.map { _1.map(&:chars) } | |
.map { _1 & _2 & _3 } | |
.flatten | |
.map { _1 =~ /[A-Z]/ ? _1.ord - 38 : _1.ord - 96 } | |
.sum | |
p result | |
__END__ | |
vJrwpWtwJgWrhcsFMMfFFhFp | |
jqHRNqRjqzjGDLGLrsFMfFZSrLrFZsSL | |
PmmdzqPrVvPwwTWBwg | |
wMqvLMZHhHMvwLHjbvcjnnSBnvTQFn | |
ttgJtRGJQctTZtZT | |
CrZsJsPPZsGzwwsLwLmpwMDw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Lol, I need to get away from the bytes!
I just made a points map.
If you use the logical & operator between arrays, it will show the join of each array.
w%(a b c d e) & w%(h i j k a) #=> ['a']