Alright so im going to force myself to create a post for this daily and maybe this will help force me to actually learn Elixir this year.
Please use Spoiler tags for your code snippets if they reveal answers.
Day 1 was interesting. Elixir is different, but it kinda reminds me of doing functional JavaScript but is wayyyyy nicer. It has so many tools to do stuff and the pattern matching is very powerful.
If anyone else wants me to tag them I can do that but I think @Enjoyer_of_Games@hexbear.net was the only one.
Heres my solution for Part 1:
spoiler
"input"
|> File.read!()
|> String.split("\n")
|> Enum.map(&String.split/1)
|> Enum.filter(fn list -> length(list) == 2 end)
|> Enum.map(fn [a, b] -> {String.to_integer(a), String.to_integer(b)} end)
|> Enum.unzip()
|> Tuple.to_list()
|> Enum.map(&Enum.sort/1)
|> Enum.zip()
|> Enum.map(fn {a, b} -> abs(a - b) end)
|> Enum.sum()
Ill post Part 2 later if I get time. I had time, heres part 2:
spoiler
"input"
|> File.read!()
|> String.split("\n")
|> Enum.map(&String.split/1)
|> Enum.filter(fn list -> length(list) == 2 end)
|> Enum.map(fn [a, b] -> {String.to_integer(a), String.to_integer(b)} end)
|> Enum.unzip()
|> Tuple.to_list()
|> Enum.map(&Enum.sort/1)
|> (fn [list1, list2] -> {list1, Enum.frequencies(list2)} end).()
|> (fn {list1, freqs} ->
list1
|> Enum.map(&{&1, Map.get(freqs, &1, 0)})
|> Enum.filter(fn {_, count} -> count != 0 end)
|> Enum.map(fn {value, count} -> value * count end)
end).()
|> Enum.sum()
Can do o7