this repo has no description
at master 896 B view raw
1<!-- vim:set ft=markdown: --> 2 3<!-- livebook:{"persist_outputs":true} --> 4 5# Day 6 6 7## Section 8 9```elixir 10initial = for i <- 0..8, into: %{}, do: {i, 0} 11 12counts = 13 File.read!("day6.txt") 14 |> String.trim() 15 |> String.split(",") 16 |> Enum.map(&String.to_integer/1) 17 |> Enum.frequencies() 18 |> Map.merge(initial, fn _, a, _ -> a end) 19 20defmodule Day6 do 21 def next(%{0 => next} = population) do 22 1..8 23 |> Map.new(&{&1 - 1, population[&1]}) 24 |> Map.merge(%{6 => next, 8 => next}, fn _, v1, v2 -> v1 + v2 end) 25 end 26end 27``` 28 29```output 30{:module, Day6, <<70, 79, 82, 49, 0, 0, 7, ...>>, {:next, 1}} 31``` 32 33## Task 1 34 35```elixir 361..80 37|> Enum.reduce(counts, fn _, acc -> Day6.next(acc) end) 38|> Map.values() 39|> Enum.sum() 40``` 41 42```output 43343441 44``` 45 46## Task 2 47 48```elixir 491..256 50|> Enum.reduce(counts, fn _, acc -> Day6.next(acc) end) 51|> Map.values() 52|> Enum.sum() 53``` 54 55```output 561569108373832 57```