This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://adventofcode.com/2017/day/2 | |
| defmodule Day2 do | |
| def checksum1(rows), do: | |
| rows | |
| |> Enum.map(&row_checksum1/1) | |
| |> Enum.sum() | |
| defp row_checksum1(row) do | |
| {min, max} = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://adventofcode.com/2017/day/3 | |
| defmodule Day3 do | |
| require Integer | |
| def part1(square) do | |
| final_point = | |
| memory_points() | |
| |> Stream.drop_while(&(&1.square != square)) | |
| |> Enum.take(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # http://adventofcode.com/2017/day/4 | |
| defmodule Day4 do | |
| def part1(), do: | |
| passphrases() | |
| |> Stream.map(&words/1) | |
| |> Stream.reject(&any_duplicate?/1) | |
| |> Enum.count() | |
| def part2(), do: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day5 do | |
| def moves(instruction_changer), do: | |
| File.stream!("input.txt") | |
| |> Stream.map(&String.trim/1) | |
| |> Stream.map(&String.to_integer/1) | |
| |> maze_path(instruction_changer) | |
| |> Enum.count() | |
| def instruction_change_1(instruction), do: instruction + 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day6 do | |
| def part1(banks), do: | |
| run_debugger(banks).steps | |
| def part2(banks), do: | |
| run_debugger(banks).cycle_size | |
| defp run_debugger(banks), do: | |
| debug_loop(banks, length(banks), %{}, 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day7 do | |
| def part1(), do: | |
| root(read_programs_map()).name | |
| def part2() do | |
| programs_map = read_programs_map() | |
| {:error, {:unbalanced, unbalanced_info}} = total_weight(programs_map, root(programs_map)) | |
| unbalanced_info.program.weight + unbalanced_info.missing_weight | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day8 do | |
| def part1(), do: | |
| instructions() | |
| |> register_states() | |
| |> last() | |
| |> Map.values() | |
| |> Enum.max() | |
| def part2(), do: | |
| instructions() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day9 do | |
| def part1(), do: | |
| score_groups(input()) | |
| def part2(), do: | |
| count_garbage(input()) | |
| defp input() do | |
| {groups, "\n"} = parse(zero_or_more(group()), File.read!("input.txt")) | |
| groups |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day10 do | |
| import Bitwise | |
| def part1(input) do | |
| lengths = input |> String.split(",") |> Enum.map(&String.to_integer/1) | |
| [first, second | _rest] = round(initial_state(), lengths).elements | |
| first * second | |
| end | |
| def part2(input), do: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| defmodule Day11 do | |
| def part1(), do: | |
| start_pos() | |
| |> positions(directions()) | |
| |> last() | |
| |> distance(start_pos()) | |
| def part2(), do: | |
| start_pos() | |
| |> positions(directions()) |