-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
259 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def exampleInput := | ||
"....#..... | ||
.........# | ||
.......... | ||
..#....... | ||
.......#.. | ||
.......... | ||
.#..^..... | ||
........#. | ||
#......... | ||
......#..." |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Aoc2024.Day06.Solve | ||
import Aoc2024.CustomMonadLift | ||
|
||
def main : IO Unit := do | ||
IO.println "Day 06" | ||
IO.println "" | ||
IO.println "Part 1" | ||
let exampleInput <- IO.FS.readFile "Aoc2024/Day06/inputs/example.txt" | ||
let puzzleInput <- IO.FS.readFile "Aoc2024/Day06/inputs/input.txt" | ||
IO.println s!"Example: {<- parseAndSolvePart1 exampleInput}" | ||
let answerPart1 <- parseAndSolvePart1 puzzleInput | ||
IO.println s!"Puzzle: {answerPart1}" | ||
assert! (answerPart1 == -1) | ||
IO.println "" | ||
IO.println "Part 2" | ||
IO.println s!"Example: {<- parseAndSolvePart2 exampleInput}" | ||
let answerPart2 <- parseAndSolvePart2 puzzleInput | ||
IO.println s!"Puzzle: {answerPart2}" | ||
assert! (answerPart2 == -1) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import Aoc2024.Day06.Examples | ||
import Aoc2024.Day06.Types | ||
import Aoc2024.Utils | ||
import Std | ||
open Std.Internal.Parsec.String | ||
open Std.Internal.Parsec | ||
open Std (HashSet) | ||
|
||
-- private def inputParser : Parser (List Int) := sorry | ||
|
||
private def decorateWithCoordinates (s: String): List (Point × Char) := | ||
s.splitOn "\n" |>.enum |>.bind (λ ⟨y, line⟩ => | ||
line.toList.enum.map (λ ⟨x, c⟩ => (⟨x, y⟩, c)) | ||
) | ||
|
||
def parseInput (s: String): Except String PuzzleInput := do | ||
let decoratedChars := decorateWithCoordinates s | ||
let obstacles := decoratedChars.filterMap (λ ⟨p, c⟩ => (c == '#').toOption p) |>.toSet | ||
let start <- decoratedChars.filterMap (λ ⟨p, c⟩ => (c == '^').toOption p) |>.head? |>.getOrThrow "no start found" | ||
let (xs, ys) := decoratedChars.map (·.1.toPair) |>.unzip | ||
let width <- xs.toArray.max?.map (· + 1 |>.toNat) |>.getOrThrow "empty input" | ||
let height <- ys.toArray.max?.map (· + 1 |>.toNat) |>.getOrThrow "empty input" | ||
pure { obstacles, start, width, height } | ||
|
||
-- #guard parseReports exampleInput == Except.ok 42 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Aoc2024.Utils | ||
import Aoc2024.Day06.Examples | ||
import Aoc2024.Day06.Parser | ||
|
||
private def solvePart1 (input : PuzzleInput) : Int := sorry | ||
|
||
def parseAndSolvePart1 (s : String): Except String Int := parseInput s |>.map solvePart1 | ||
|
||
-- #guard parseAndSolvePart1 exampleInput == Except.ok 41 | ||
|
||
private def solvePart2 (input : PuzzleInput) : Int := sorry | ||
|
||
def parseAndSolvePart2 (s : String): Except String Int := parseInput s |>.map solvePart2 | ||
|
||
-- #guard parseAndSolvePart2 exampleInput == Except.ok -1 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Std | ||
open Std (HashSet) | ||
|
||
structure Point where | ||
x : Int | ||
y : Int | ||
deriving BEq, Hashable, Repr | ||
|
||
def Point.toPair (p : Point) : (Int × Int) := (p.x, p.y) | ||
|
||
inductive Direction where | ||
| Up | ||
| Right | ||
| Down | ||
| Left | ||
|
||
structure PuzzleInput where | ||
obstacles : HashSet Point | ||
width : Nat | ||
height : Nat | ||
start : Point | ||
deriving Repr |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
....#..... | ||
.........# | ||
.......... | ||
..#....... | ||
.......#.. | ||
.......... | ||
.#..^..... | ||
........#. | ||
#......... | ||
......#... |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
This file contains 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