Skip to content

Commit

Permalink
templating
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Dec 4, 2024
1 parent c80f7d0 commit 3bcef59
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Aoc2024/Day05/Examples.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def exampleInput :=
"..."
19 changes: 19 additions & 0 deletions Aoc2024/Day05/Main.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Aoc2024.Day05.Solve
import Aoc2024.CustomMonadLift

def main : IO Unit := do
IO.println "Day 05"
IO.println ""
IO.println "Part 1"
let exampleInput <- IO.FS.readFile "Aoc2024/Day05/inputs/example.txt"
let puzzleInput <- IO.FS.readFile "Aoc2024/Day05/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)
12 changes: 12 additions & 0 deletions Aoc2024/Day05/Parser.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Aoc2024.Day05.Examples
import Aoc2024.Day05.Types
import Aoc2024.Utils
import Std
open Std.Internal.Parsec.String
open Std.Internal.Parsec

private def inputParser : Parser (List Int) := sorry

def parseThings : String -> Except String (List Int) := inputParser.run

-- #guard parseReports exampleInput == Except.ok 42
15 changes: 15 additions & 0 deletions Aoc2024/Day05/Solve.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Aoc2024.Utils
import Aoc2024.Day05.Examples
import Aoc2024.Day05.Parser

private def solvePart1 (things : List Int) : Int := sorry

def parseAndSolvePart1 (s : String): Except String Int := parseThings s |>.map solvePart1

-- #guard parseAndSolvePart1 exampleInput == Except.ok 2

private def solvePart2 (things : List Int) : Int := sorry

def parseAndSolvePart2 (s : String): Except String Int := parseThings s |>.map solvePart2

-- #guard parseAndSolvePart2 exampleInput == Except.ok 4
Empty file added Aoc2024/Day05/Types.lean
Empty file.
Empty file.
Empty file added Aoc2024/Day05/inputs/input.txt
Empty file.
8 changes: 4 additions & 4 deletions DayXX/Main.lean
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ def main : IO Unit := do
IO.println "Part 1"
let exampleInput <- IO.FS.readFile "Aoc2024/DayXX/inputs/example.txt"
let puzzleInput <- IO.FS.readFile "Aoc2024/DayXX/inputs/input.txt"
IO.println s!"Example: {solvePart1 exampleInput}"
let answerPart1 := solvePart1 puzzleInput
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: {solvePart2 exampleInput}"
let answerPart2 := solvePart2 puzzleInput
IO.println s!"Example: {<- parseAndSolvePart2 exampleInput}"
let answerPart2 <- parseAndSolvePart2 puzzleInput
IO.println s!"Puzzle: {answerPart2}"
assert! (answerPart2 == -1)
5 changes: 5 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,10 @@ tasks:
deps: [build]
cmds:
- .lake/build/bin/day4
day5:
desc: Run day 5
deps: [build]
cmds:
- .lake/build/bin/day5


8 changes: 4 additions & 4 deletions lakefile.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "aoc2024"
version = "0.1.0"
defaultTargets = ["day1", "day2", "day3", "day4"]
defaultTargets = ["day1", "day2", "day3", "day4", "day5"]

[[lean_lib]]
name = "Aoc2024"
Expand All @@ -21,9 +21,9 @@ root = "Aoc2024.Day03.Main"
name = "day4"
root = "Aoc2024.Day04.Main"

#[[lean_exe]]
#name = "dayXX"
#root = "Aoc2024.DayXX.Main"
[[lean_exe]]
name = "day5"
root = "Aoc2024.Day05.Main"

[[require]]
name = "Regex"
Expand Down
2 changes: 1 addition & 1 deletion make-day.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ if [ "$#" -ne 1 ]; then
fi

day_number=$(printf "%02d" "$1")
source_dir="Aoc2024/DayXX"
source_dir="DayXX"
target_dir="Aoc2024/Day$day_number"

# Ensure the target day is in the correct format
Expand Down

0 comments on commit 3bcef59

Please sign in to comment.