2018-12-02 22:40:03 -08:00
|
|
|
{:ok, content} = File.read("input-2")
|
|
|
|
content = content
|
|
|
|
|> String.split("\n", trim: true)
|
|
|
|
|> Enum.map(fn n -> String.graphemes(n) end)
|
|
|
|
|
|
|
|
count2 = 0
|
|
|
|
count3 = 0
|
2018-12-02 23:42:23 -08:00
|
|
|
sum2 = for line <- content do
|
2018-12-02 22:40:03 -08:00
|
|
|
Enum.reduce(line, %{}, fn char, acc ->
|
|
|
|
Map.put(acc, char, (acc[char] || 0)+ 1)
|
|
|
|
end)
|
2018-12-02 23:42:23 -08:00
|
|
|
|> Map.values
|
2018-12-02 22:40:03 -08:00
|
|
|
end
|
2018-12-02 23:42:23 -08:00
|
|
|
|
|
|
|
|
|
|
|
sum3 = for sum <- sum2 do
|
|
|
|
Enum.filter(sum, fn x -> x == 3 end) # need to split and count occurance of 2 and 3 seperately
|
|
|
|
|> (fn x -> [ 0 | x] end).() #so the accumulator starts with 0
|
|
|
|
|> Enum.reduce(fn _, acc -> acc + 1 end) #if x == 2 do acc + 1 end end)
|
|
|
|
end
|
|
|
|
|
|
|
|
sum3= sum3
|
|
|
|
|> Enum.sum
|
|
|
|
|> IO.inspect
|
|
|
|
|
|
|
|
sum2 = sum2
|
|
|
|
|> Enum.filter(fn x -> Enum.member?(x, 2) end)# need to split and count occurance of 2 and 3 seperately
|
|
|
|
|> (fn x -> [ 0 | x] end).() #so the accumulator starts with 0
|
|
|
|
|> Enum.reduce(fn _, acc -> acc + 1 end) #if x == 2 do acc + 1 end end)
|
|
|
|
|
|
|
|
sum2 = sum2
|
2018-12-02 22:40:03 -08:00
|
|
|
|> IO.inspect
|
|
|
|
|
2018-12-02 23:42:23 -08:00
|
|
|
sum1 = sum3 * sum2
|
|
|
|
IO.puts(sum1)
|
|
|
|
#IO.puts(count2)
|
|
|
|
#IO.puts(count3)
|
2018-12-02 22:40:03 -08:00
|
|
|
|
|
|
|
# File.stream!("input-2")
|
|
|
|
# |> Stream.map(&String.trim/1)
|
|
|
|
# |> Stream.map(fn n -> String.graphemes(n) end)
|
|
|
|
# |> Enum.reduce(%{}, fn char, acc ->
|
|
|
|
# Map.update(acc, char, 1, &(&1 + 1))
|
|
|
|
# end)
|
|
|
|
# |> IO.puts
|