-
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
10 changed files
with
191 additions
and
29 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,2 @@ | ||
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.Day09.Solve | ||
import Aoc2024.CustomMonadLift | ||
|
||
def main : IO Unit := do | ||
IO.println "Day 09" | ||
IO.println "" | ||
IO.println "Part 1" | ||
let exampleInput <- IO.FS.readFile "Aoc2024/Day09/inputs/example.txt" | ||
let puzzleInput <- IO.FS.readFile "Aoc2024/Day09/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,12 @@ | ||
import Aoc2024.Day09.Examples | ||
import Aoc2024.Day09.Types | ||
import Aoc2024.Utils | ||
import Std | ||
open Std.Internal.Parsec.String | ||
open Std.Internal.Parsec | ||
|
||
private def inputParser : Parser (List Int) := sorry | ||
|
||
def parseInput : String -> Except String (List Int) := inputParser.run | ||
|
||
-- #guard parseInput 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,20 @@ | ||
import Aoc2024.Utils | ||
import Aoc2024.Day09.Examples | ||
import Aoc2024.Day09.Parser | ||
import Aoc2024.Day09.Types | ||
|
||
-- Part 1 | ||
|
||
private def solvePart1 (input : List Int) : Int := sorry | ||
|
||
def parseAndSolvePart1 (s : String): Except String Int := parseInput s |>.map solvePart1 | ||
|
||
-- #guard parseAndSolvePart1 exampleInput == Except.ok -1 | ||
|
||
-- Part 2 | ||
|
||
private def solvePart2 (input : List Int) : 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 @@ | ||
import Aoc2024.Utils |
Empty file.
Empty file.
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 |
---|---|---|
@@ -1,56 +1,71 @@ | ||
version: '3' | ||
|
||
tasks: | ||
default: task --list | ||
build: | ||
desc: Build | ||
sources: | ||
- Aoc2024/**/*.lean | ||
- Aoc2024/**/*.lean | ||
generates: | ||
- .lake/build/bin/* | ||
- .lake/build/bin/* | ||
cmds: | ||
- lake build | ||
- lake build | ||
make-day: | ||
desc: Template a day | ||
cmds: | ||
- ./make-day.sh {{.CLI_ARGS}} | ||
- ./make-day.sh {{.CLI_ARGS}} | ||
- ./add_day_to_taskfile.py {{.CLI_ARGS}} | ||
- ./add_day_to_lakefile.py {{.CLI_ARGS}} | ||
day1: | ||
desc: Run day 1 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day1 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day1 | ||
day2: | ||
desc: Run day 2 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day2 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day2 | ||
day3: | ||
desc: Run day 3 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day3 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day3 | ||
day4: | ||
desc: Run day 4 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day4 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day4 | ||
day5: | ||
desc: Run day 5 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day5 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day5 | ||
day6: | ||
desc: Run day 6 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day6 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day6 | ||
day7: | ||
desc: Run day 7 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day7 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day7 | ||
day8: | ||
desc: Run day 8 | ||
deps: [build] | ||
cmds: | ||
- .lake/build/bin/day8 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day8 | ||
day9: | ||
desc: Run day 9 | ||
deps: | ||
- build | ||
cmds: | ||
- .lake/build/bin/day9 |
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,52 @@ | ||
#!/usr/bin/env nix-shell | ||
#!nix-shell -i python -p python3Packages.toml | ||
|
||
import sys | ||
import toml | ||
|
||
def add_day_to_lakefile(file_path, day_number): | ||
try: | ||
with open(file_path, 'r') as file: | ||
lakefile = toml.load(file) | ||
|
||
# Update defaultTargets | ||
default_targets = lakefile.get('defaultTargets', []) | ||
new_target = f"day{day_number}" | ||
if new_target in default_targets: | ||
print(f"Target '{new_target}' already exists in defaultTargets.") | ||
else: | ||
default_targets.append(new_target) | ||
lakefile['defaultTargets'] = default_targets | ||
|
||
# Add new lean_exe entry | ||
lean_exes = lakefile.get('lean_exe', []) | ||
new_exe = { | ||
"name": f"day{day_number}", | ||
"root": f"Aoc2024.Day{day_number:02d}.Main" | ||
} | ||
if any(exe['name'] == new_exe['name'] for exe in lean_exes): | ||
print(f"Lean exe '{new_exe['name']}' already exists.") | ||
else: | ||
lean_exes.append(new_exe) | ||
lakefile['lean_exe'] = lean_exes | ||
|
||
# Write back to the file | ||
with open(file_path, 'w') as file: | ||
toml.dump(lakefile, file) | ||
|
||
print(f"Day {day_number} added successfully.") | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 3: | ||
print("Usage: python add_day_to_lakefile.py <lakefile.toml> <N>") | ||
sys.exit(1) | ||
|
||
file_path = sys.argv[1] | ||
try: | ||
day_number = int(sys.argv[2]) | ||
add_day_to_lakefile(file_path, day_number) | ||
except ValueError: | ||
print("Error: N must be an integer.") | ||
sys.exit(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,41 @@ | ||
#!/usr/bin/env nix-shell | ||
#!nix-shell -i python -p python3Packages.pyyaml | ||
|
||
import sys | ||
import yaml | ||
|
||
def add_day_to_taskfile(file_path, day_number): | ||
try: | ||
with open(file_path, 'r') as file: | ||
taskfile = yaml.safe_load(file) | ||
|
||
day_task_name = f"day{day_number}" | ||
if day_task_name in taskfile['tasks']: | ||
print(f"Task '{day_task_name}' already exists in {file_path}.") | ||
return | ||
|
||
taskfile['tasks'][day_task_name] = { | ||
'desc': f"Run day {day_number}", | ||
'deps': ['build'], | ||
'cmds': [f".lake/build/bin/day{day_number}"] | ||
} | ||
|
||
with open(file_path, 'w') as file: | ||
yaml.dump(taskfile, file, default_flow_style=False, sort_keys=False) | ||
|
||
print(f"Task '{day_task_name}' added successfully.") | ||
except Exception as e: | ||
print(f"Error: {e}") | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) != 3: | ||
print("Usage: python add_day_to_taskfile.py <Taskfile.yml> <N>") | ||
sys.exit(1) | ||
|
||
file_path = sys.argv[1] | ||
try: | ||
day_number = int(sys.argv[2]) | ||
add_day_to_taskfile(file_path, day_number) | ||
except ValueError: | ||
print("Error: N must be an integer.") | ||
sys.exit(1) |