Advent of Code Solutions
advent-of-code aoc
1
fork

Configure Feed

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

misc: run erlfmt

yemou b94ae7d2 7b830410

+32 -20
+2 -4
2015/01/solution.erl
··· 1 1 #!/usr/bin/env escript 2 2 3 3 % --- Part 1 Code 4 - 5 4 part1(Input) -> 6 5 io:format("Part 1: ~b~n", [destination(0, Input)]). 7 6 ··· 13 12 end. 14 13 15 14 % --- Part 2 Code 16 - 17 15 part2(Input) -> 18 16 io:format("Part 2: ~b~n", [basement_enter(0, 0, Input)]). 19 17 ··· 25 23 case {_, Rest} = next_char(Input) of 26 24 {"(", _} -> basement_enter(Position + 1, Floor + 1, Rest); 27 25 {")", _} -> basement_enter(Position + 1, Floor - 1, Rest); 28 - {"\n", _} -> halt(1) % If we get here, our puzzle input is impossible 26 + % If we get here, our puzzle input is impossible 27 + {"\n", _} -> halt(1) 29 28 end 30 29 end. 31 30 32 31 % --- Generic Helper Functions 33 - 34 32 next_char([Char | String]) -> {[Char], String}. 35 33 36 34 read_input() -> read_input("").
+1
2015/02/solution.erl
··· 1 1 #!/usr/bin/env escript 2 + 2 3 % --- Part 1 Code 3 4 part1(Input) -> 4 5 io:format("Part 1: ~b~n", [calculate_wpaper(0, Input)]).
+29 -16
2015/03/solution.erl
··· 1 1 #!/usr/bin/env escript 2 + 2 3 % --- Part 1 Code 3 4 part1(Input) -> 4 5 InitialPosition = {0, 0}, 5 6 InitialMap = #{InitialPosition => 1}, 6 - io:format("Part 1: ~b~n", [length(maps:keys(process_instructions(InitialMap, InitialPosition, Input)))]). 7 + io:format("Part 1: ~b~n", [ 8 + length(maps:keys(process_instructions(InitialMap, InitialPosition, Input))) 9 + ]). 7 10 8 11 visit_house(HouseMap, Position) -> 9 12 CurrentValue = maps:get(Position, HouseMap, 0), ··· 13 16 HouseMap; 14 17 process_instructions(HouseMap, Position, Input) -> 15 18 {CurrentX, CurrentY} = Position, 16 - NewPos = case {_, Rest} = next_char(Input) of 17 - {"^", _} -> {CurrentX, CurrentY + 1}; 18 - {"<", _} -> {CurrentX - 1, CurrentY}; 19 - {"v", _} -> {CurrentX, CurrentY - 1}; 20 - {">", _} -> {CurrentX + 1, CurrentY} 21 - end, 19 + NewPos = 20 + case {_, Rest} = next_char(Input) of 21 + {"^", _} -> {CurrentX, CurrentY + 1}; 22 + {"<", _} -> {CurrentX - 1, CurrentY}; 23 + {"v", _} -> {CurrentX, CurrentY - 1}; 24 + {">", _} -> {CurrentX + 1, CurrentY} 25 + end, 22 26 process_instructions(visit_house(HouseMap, NewPos), NewPos, Rest). 23 27 24 28 % --- Part 2 Code ··· 26 30 InitialPositionMap = #{santa => {0, 0}, robo_santa => {0, 0}}, 27 31 InitialMap = #{{0, 0} => 2}, 28 32 Mover = santa, 29 - io:format("Part 2: ~b~n", [length(maps:keys(process_instructions(InitialMap, InitialPositionMap, Mover, Input)))]). 33 + io:format("Part 2: ~b~n", [ 34 + length(maps:keys(process_instructions(InitialMap, InitialPositionMap, Mover, Input))) 35 + ]). 30 36 31 37 update_position(PositionMap, Mover, Movement) -> 32 38 {CurrentX, CurrentY} = maps:get(Mover, PositionMap), ··· 40 46 process_instructions(HouseMap, _, _, "\n") -> 41 47 HouseMap; 42 48 process_instructions(HouseMap, PositionMap, Mover, Input) -> 43 - NextMover = case Mover of santa -> robo_santa; robo_santa-> santa end, 44 - NewPosMap = case {_, Rest} = next_char(Input) of 45 - {"^", _} -> update_position(PositionMap, Mover, up); 46 - {"<", _} -> update_position(PositionMap, Mover, left); 47 - {"v", _} -> update_position(PositionMap, Mover, down); 48 - {">", _} -> update_position(PositionMap, Mover, right) 49 - end, 50 - process_instructions(visit_house(HouseMap, maps:get(Mover, NewPosMap)), NewPosMap, NextMover, Rest). 49 + NextMover = 50 + case Mover of 51 + santa -> robo_santa; 52 + robo_santa -> santa 53 + end, 54 + NewPosMap = 55 + case {_, Rest} = next_char(Input) of 56 + {"^", _} -> update_position(PositionMap, Mover, up); 57 + {"<", _} -> update_position(PositionMap, Mover, left); 58 + {"v", _} -> update_position(PositionMap, Mover, down); 59 + {">", _} -> update_position(PositionMap, Mover, right) 60 + end, 61 + process_instructions( 62 + visit_house(HouseMap, maps:get(Mover, NewPosMap)), NewPosMap, NextMover, Rest 63 + ). 51 64 52 65 % --- Generic Helper Functions 53 66 next_char([Char | String]) -> {[Char], String}.