As in most programming languages, strings are represented as binary code points in Elixir. The ? operator can be used to match on a range of characters, and the <<>> can be used to get the code of a string.
For the first part, I split each line in half and checked to see if each item in the first half was in the second half using a reduce. As soon as a match is found, the value is calculated and replaces the accumulator. Any subsequent calls to reduce simply return the accumulator as is if it is already an integer.
For the second part, I chunked the lines by three. For each group of three, I got rid of duplicates within each sack and flattened all three into a single list. Then I calculated the frequencies of each character and found the character with a frequency of three.
Top comments (0)