this repo has no description
3
fork

Configure Feed

Select the types of activity you want to include in your feed.

ft: add day 01.2022

+51
+51
2022/day01.livemd
··· 1 + # Day 01 2 + 3 + ```elixir 4 + Mix.install([ 5 + {:kino_aoc, git: "https://github.com/ljgago/kino_aoc"} 6 + ]) 7 + ``` 8 + 9 + ## Setup 10 + 11 + <!-- livebook:{"attrs":{"day":"1","session_secret":"ADVENT_OF_CODE_SESSION","variable":"puzzle_input","year":"2022"},"kind":"Elixir.KinoAOC.HelperCell","livebook_object":"smart_cell"} --> 12 + 13 + ```elixir 14 + {:ok, puzzle_input} = 15 + KinoAOC.download_puzzle("2022", "1", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION")) 16 + ``` 17 + 18 + ```elixir 19 + elves = 20 + puzzle_input 21 + |> String.split("\n") 22 + |> Enum.chunk_while( 23 + [], 24 + fn 25 + "", acc -> {:cont, Enum.reverse(acc), []} 26 + val, acc -> {:cont, [String.to_integer(val) | acc]} 27 + end, 28 + fn 29 + [] -> {:cont, []} 30 + acc -> {:cont, Enum.reverse(acc), []} 31 + end 32 + ) 33 + ``` 34 + 35 + ## Task 1 36 + 37 + ```elixir 38 + elves 39 + |> Enum.map(&Enum.sum/1) 40 + |> Enum.max() 41 + ``` 42 + 43 + ## Task 2 44 + 45 + ```elixir 46 + elves 47 + |> Enum.map(&Enum.sum/1) 48 + |> Enum.sort(:desc) 49 + |> Enum.take(3) 50 + |> Enum.sum() 51 + ```