this repo has no description
at master 8.2 kB view raw
1<!-- livebook:{"persist_outputs":true} --> 2 3# Day 17 4 5```elixir 6Mix.install([ 7 {:kino_aoc, git: "https://github.com/ljgago/kino_aoc"} 8]) 9``` 10 11<!-- livebook:{"output":true} --> 12 13``` 14* Getting kino_aoc (https://github.com/ljgago/kino_aoc) 15remote: Enumerating objects: 103, done. 16remote: Counting objects: 100% (103/103), done. 17remote: Compressing objects: 100% (68/68), done. 18remote: Total 103 (delta 40), reused 84 (delta 25), pack-reused 0 19origin/HEAD set to main 20Resolving Hex dependencies... 21Resolution completed in 0.336s 22New: 23 castore 1.0.3 24 finch 0.16.0 25 hpax 0.1.2 26 jason 1.4.1 27 kino 0.10.0 28 mime 2.0.5 29 mint 1.5.1 30 nimble_options 1.0.2 31 nimble_pool 1.0.0 32 req 0.3.10 33 table 0.1.2 34 telemetry 1.2.1 35* Getting kino (Hex package) 36* Getting req (Hex package) 37* Getting finch (Hex package) 38* Getting jason (Hex package) 39* Getting mime (Hex package) 40* Getting castore (Hex package) 41* Getting mint (Hex package) 42* Getting nimble_options (Hex package) 43* Getting nimble_pool (Hex package) 44* Getting telemetry (Hex package) 45* Getting hpax (Hex package) 46* Getting table (Hex package) 47==> table 48Compiling 5 files (.ex) 49Generated table app 50==> mime 51Compiling 1 file (.ex) 52Generated mime app 53==> nimble_options 54Compiling 3 files (.ex) 55Generated nimble_options app 56==> kino 57Compiling 41 files (.ex) 58Generated kino app 59===> Analyzing applications... 60===> Compiling telemetry 61==> jason 62Compiling 10 files (.ex) 63Generated jason app 64==> hpax 65Compiling 4 files (.ex) 66Generated hpax app 67==> nimble_pool 68Compiling 2 files (.ex) 69Generated nimble_pool app 70==> castore 71Compiling 1 file (.ex) 72Generated castore app 73==> mint 74Compiling 1 file (.erl) 75Compiling 19 files (.ex) 76Generated mint app 77==> finch 78Compiling 13 files (.ex) 79Generated finch app 80==> req 81Compiling 5 files (.ex) 82Generated req app 83==> kino_aoc 84Compiling 3 files (.ex) 85Generated kino_aoc app 86``` 87 88<!-- livebook:{"output":true} --> 89 90``` 91:ok 92``` 93 94## Section 95 96<!-- livebook:{"attrs":{"day":"17","session_secret":"ADVENT_OF_CODE_SESSION","variable":"puzzle_input","year":"2022"},"chunks":null,"kind":"Elixir.KinoAOC.HelperCell","livebook_object":"smart_cell"} --> 97 98```elixir 99{:ok, puzzle_input} = 100 KinoAOC.download_puzzle("2022", "17", System.fetch_env!("LB_ADVENT_OF_CODE_SESSION")) 101``` 102 103<!-- livebook:{"output":true} --> 104 105``` 106{:ok, 107 ">><<<>><<<<>>><>><>>><<<>>>><>>><<><<<>>>><<<><<<><<><<<>>>><<><<>>><<<<>><<>><<<><<<<>><<<<><>>><<<<>>><<<>>>><<<>>>><<<<>>><<>>><<>>>><<<<>>>><<<<>><>>>><<<<>>><<>><>>><>>><<<<>>><<>>><>><<<>>>><<>>>><<<>>><<<>>>><<<<><<<><<>>><>><<<<>><>><<><<<<>>><<>>><<<>>>><<<<>>><<>>>><<<<>><>><<<><<>><<<>>>><<<>><<<<>>>><<<><<<<>>><<><>>><<>><<<>>><<<<>>><<>>>><<<>>><<<<>>><<>>>><<<<>><<>>>><<<>>>><<>>><<><<<>>><<<<>>>><<<<>>><<<>>>><<<<>><<<>>>><>>><><<>>><<<><<>>>><<<>>>><<><<<<>>>><<<><<>><<<<>>>><<>>><>>>><<<<>><<>>><<>>><<>><>><><<<<>>>><<<>><<>>><<><<<<>>>><<<<><<<<>>>><><<>>><><>>><<>>><>>><>>>><<>><><<>><>>><<>>>><<>>>><<<<><<<>>>><>><>>>><<<<><<<><<<>>>><<><<>><<<>>><<<<>>><<<<><<>>><<<>>>><<><<<<>><<<<>><<<><>><>>>><><<<>>><<<<><<<<>><>>><<<>><<<<><<<>>>><<<>>>><<<>><<>><<<<>><<<<>><>>>><<>>>><<<<>>><<>>>><<>>>><>><<<>>>><<<<>>><<<<><>>>><<><<<>><<<<>>>><<<<>><>>>><<<>>>><<<<>>>><<<<>>><<<<>><>>><<<<><>>>><<><>>>><>><<>>>><>>>><<>><<>>><<<>>>><<><<<>>>><<><<>><<<<>>><<<>>><<<<>><<<><<<>>><<><<>>>><<<>>><<>>><<<><<<<>>><>>>><<<>>><<<>>>><<><><<>>>><<>>>><<>>>><<>>><<>><<><<<>>><>>><<<<>>>><>>>><<<>><>><<<<>>><<<<>>><<>>><<<<><<<>>><>>>><<>><<<<>><<<<>><<<<><>><<<<>>>><<>>><>><<<>><<>><<<<>><<>>><<<<>>><<<<>>><<><<<>>><<><<<><<>>>><>><<><<<<><<>><<<>>>><><<<<><><><>>><<<>>><<>>><<<>>>><<><<>><<>><<<><<<<>>>><>>>><<>>>><<<>>>><<>>>><<<>><>><<<>>><<>>>><<><<>>>><<<><<<<>>><<<>>>><<<>>><<<><>>><<>>><<<>>>><<<>>>><<<>>>><<<>><>><<<>>><<<<>>>><><<<>>>><<>>>><><>>><<>>>><<>><<>>>><<<>><<<>>>><<>>>><<<<>><<<>><<<>><<>><<<>>><<><>>><<><<><>>>><<<>>>><<<<>><<>>>><<<<>><><<<>>><<<<>><<>>><<<>><<>><<>><>>>><<><<>>>><>>>><<><><<<><<<<>>>><<<<>><<><<><<>>>><>>><<<><<<<><<>><<<><<>><><<><<<>>>><>>>><<>>>><>><><><<<><<><<>>><<<<><<>><<<>>>><<><<<<>>>><<<<>><><<<<>><<>><>><<<<>>>><<>>>><<<<><<<>><<>>><<<>>><>>><<>>>><<<><<<<><<>>>><<<<>><<<>>>><<<>><<<<><<<>><<<<>><<<>>>><<>>>><><>>><>>><<<>>>><<>>><<<>><>>>><<<>>>><<<<><<<>>><<<<>><<>><<>><<<><<<<>>><><>><<<><<<>>><<<><<<<>>>><><<<<>><<>><>>><<<>>>><<>>><<<>><<<<>>><<<>><<>><<>><<<<><<>>><>><<>>><<><<<><<<>><<<<>>><>><><<<<>>>><<<><<<>><>><<>>>><<<>>>><<<><<<>>><<>>><><>><<<>><>>>><<<<>>>><<<<>>><<<<>>><<<<>><<<<><><<>><>><<>>><<>><<><<<<>>>><<<<>>>><<>>>><<<<>>>><<>>>><>>>><<>><<><<<><><>><<<><<<<>>>><<<<>><<<>>>><<<<>>>><>>>><><<<<>><>>><<<<><<>>>><>><<<<>><<<><<<>>>><<>><<>>><>>>><<><>>>><<<<><<><<<>>>><<<>>>><<><>><<<>><<<>><<<<><<>>><>><<>>><<>>><>>>><<<>>><<>><<><><<>>>><<<>>><<<>><<<>>><<<>>>><<>>><>>>><>>>><>>><<>>>><<<>><<<<>><<<<>><<>>>><><>>>><<>>>><<<><<<<><<>>>><<<<>><<<<>>>><><<<><>><<<<>>>><>>>><<<<>>>><<><>><<<<><<<>>><<<<>><>><>>>><<>>>><>>><>>>><>><<>>><<<><>><>>>><<<>><<<>><<<<><<<<>>><<<>>><<<>>>><>><>>><<<<>><<<><<>>><>>><<><>>>><<<>>>><<<<>>>><><<<>>><<<<>>><>><>>>><<<>><<>>>><>>><<<<>>>><<<>><<<>>>><<<<>><<<>>><<<<><<<<>>>><><<<>>><<<<>>>><<<<>><<>><<<>>><>>><>><<>>><<<>><><<><>><<>><>><<<><<<<>>><<<>><<<><<<>>>><<>>><<<<><<><<<>>><<<<>>><<>><>>><>>><<<><<>>>><<<>><<<<><<<>><<<<>><>><<>><>>>><>>>><<>>><<<<>>><><><><<<>>><<<>><<>>><<<<>>>><>><<<>>>><<>><<<<>><<>><>><<<>>>><>>><<<<>>><>><<>>><<<>><<<<>>>><<<>><<>><>><<<<>><<<><<<>><>><<<><<<>>>><<<<>>><<><<<<><<<<>>>><<<><>><<><>>><<<><<><<<<>>><<>>>><>><<<<>><<<<>>><<>>>><>>><<<>>><<<>>>><<>>><>>>><<<<><>><<>>>><<<>>><>>><>><<<>>>><<><<<>>>><<><<<<>>>><<<<>>>><><<<<>>>><<<>>>><<><<<>>>><<>><>><>>><<<<><<<>>>><<<<>>>><<<><<>>>><<<><>>>><<<<>>>><>>><<<>><<<<><<>>><<>>><<>>><>>><<<><><><<<>>>><<>>>><<<<><>>>><<<>><<>>>><<><<<<><<<<>><><<<<><<>>>><<<>><<<<>><<>><<><<>>>><<><<<><<<<><<<<>>><<<>>>><<<<>>><><<<>>><>>>><>>><<<<>>><<<>>><<<<><<<<><<>><><<<>>><>>><<><<><<>><<<<>>>><<<>><<<><<<<>>><<<<>>><<>><<<<>><>>>><>><<<><>>>><<<>>><<><<>><<<><<<>><<<<>><<<<>><<<<><>>>><<><<<>><<<><<<>><<<<><<>>>><<<>><<<><<<>>><<<><<<<>>>><<>>>><<<>><<<<>>><<><<<<>>>><<<<>>>><<>><<><<>>><<>>>><<>>><<>>><<<>>>><<>>><<><<>>><<<>><<<<>>><<>>><<<>>><<<>>><>>>><<<>>>><<<<>>>><>>>><<<>>>><<<>>>><>>>><>>>><<<><<>><><>><<>><><<<>>>><><>>>><><<<><>>><<<>>><<<>>><<<<>><<<<><<<>>><<>><<<<>>><<<>><<>>>><<><<<<>>><>><<<>>>><<>><<<<>>><<<<>>><>>>><<>" <> ...} 108``` 109 110```elixir 111well = [0, 0, 0, 0, 0, 0, 0] 112``` 113 114<!-- livebook:{"output":true} --> 115 116``` 117[0, 0, 0, 0, 0, 0, 0] 118``` 119 120```elixir 121defmodule Tetris do 122 def fit(well, n, :dash) when n in 0..3 do 123 max = 124 well 125 |> Enum.drop(n) 126 |> Enum.take(4) 127 |> Enum.max() 128 129 well 130 |> List.replace_at(n, max + 1) 131 |> List.replace_at(n + 1, max + 1) 132 |> List.replace_at(n + 2, max + 1) 133 |> List.replace_at(n + 3, max + 1) 134 end 135 136 def fit(well, n, :plus) when n in 0..4 do 137 bottom = 138 well 139 |> Enum.drop(n) 140 |> Enum.take(3) 141 |> case do 142 [a, b, c] when b < a and b < c -> max(a, b) - 1 143 [_, b, _] -> b 144 end 145 146 well 147 |> List.replace_at(n, bottom + 2) 148 |> List.replace_at(n + 1, bottom + 3) 149 |> List.replace_at(n + 2, bottom + 2) 150 end 151 152 def fit(well, n, :l), do: well 153 154 def fit(well, n, :i), do: well 155 156 def fit(well, n, :o), do: well 157end 158``` 159 160<!-- livebook:{"output":true} --> 161 162``` 163warning: variable "n" is unused (if the variable is not meant to be used, prefix it with an underscore) 164 2022/day17.livemd#cell:yqwk3yzwldnf4hstvs2cj6qm5r3go5yp:32: Tetris.fit/3 165 166warning: variable "n" is unused (if the variable is not meant to be used, prefix it with an underscore) 167 2022/day17.livemd#cell:yqwk3yzwldnf4hstvs2cj6qm5r3go5yp:34: Tetris.fit/3 168 169warning: variable "n" is unused (if the variable is not meant to be used, prefix it with an underscore) 170 2022/day17.livemd#cell:yqwk3yzwldnf4hstvs2cj6qm5r3go5yp:36: Tetris.fit/3 171 172``` 173 174<!-- livebook:{"output":true} --> 175 176``` 177{:module, Tetris, <<70, 79, 82, 49, 0, 0, 10, ...>>, {:fit, 3}} 178``` 179 180```elixir 181Tetris.fit([2, 1, 2, 0, 0, 0, 0], 0, :plus) 182``` 183 184<!-- livebook:{"output":true} --> 185 186``` 187[3, 4, 3, 0, 0, 0, 0] 188```