finished 2
This commit is contained in:
parent
5d18a4a2e8
commit
36d89965b5
31
2.exs
31
2.exs
|
@ -5,19 +5,36 @@ content = content
|
||||||
|
|
||||||
count2 = 0
|
count2 = 0
|
||||||
count3 = 0
|
count3 = 0
|
||||||
for line <- content do
|
sum2 = for line <- content do
|
||||||
Enum.reduce(line, %{}, fn char, acc ->
|
Enum.reduce(line, %{}, fn char, acc ->
|
||||||
Map.put(acc, char, (acc[char] || 0)+ 1)
|
Map.put(acc, char, (acc[char] || 0)+ 1)
|
||||||
end)
|
end)
|
||||||
|> Map.values
|
|> Map.values
|
||||||
|> Enum.filter(fn x -> x == 2 || x == 3 end)
|
|
||||||
# need to split and count occurance of 2 and 3 seperately
|
|
||||||
|> Enum.reduce(0, fn x, acc -> if x == 2 do acc + 1 end end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
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
|
|> IO.inspect
|
||||||
|
|
||||||
IO.puts(count2)
|
sum2 = sum2
|
||||||
IO.puts(count3)
|
|> 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
|
||||||
|
|> IO.inspect
|
||||||
|
|
||||||
|
sum1 = sum3 * sum2
|
||||||
|
IO.puts(sum1)
|
||||||
|
#IO.puts(count2)
|
||||||
|
#IO.puts(count3)
|
||||||
|
|
||||||
# File.stream!("input-2")
|
# File.stream!("input-2")
|
||||||
# |> Stream.map(&String.trim/1)
|
# |> Stream.map(&String.trim/1)
|
||||||
|
|
Loading…
Reference in a new issue