Skip to content

Commit

Permalink
template
Browse files Browse the repository at this point in the history
  • Loading branch information
mdr committed Dec 2, 2024
1 parent d865a1e commit 0fb84af
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Aoc2024/Day03/Examples.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def exampleInput :=
"..."
15 changes: 15 additions & 0 deletions Aoc2024/Day03/Main.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Aoc2024.Day03.Solve
import Aoc2024.CustomMonadLift

def solve (name: String) (inputPath: String) : IO Unit := do
IO.println name
let input <- IO.FS.readFile inputPath
IO.println s!"Part 1: {<- parseAndSolvePart1 input}"
IO.println s!"Part 2: {<- parseAndSolvePart2 input}"

def main : IO Unit := do
IO.println "Day 03"
IO.println ""
solve "Example" "Aoc2024/Day03/inputs/example.txt"
IO.println ""
solve "Puzzle" "Aoc2024/Day03/inputs/input.txt"
10 changes: 10 additions & 0 deletions Aoc2024/Day03/Parser.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Aoc2024.Day03.Examples
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/Day03/Solve.lean
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Aoc2024.Utils
import Aoc2024.Day03.Examples
import Aoc2024.Day03.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/Day03/Types.lean
Empty file.
Empty file.
Empty file added Aoc2024/Day03/inputs/input.txt
Empty file.
30 changes: 30 additions & 0 deletions make-day.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash

if [ "$#" -ne 1 ]; then
echo "Usage: $0 NN"
exit 1
fi

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

# Ensure the target day is in the correct format
if [[ ! $day_number =~ ^[0-9]{2}$ ]]; then
echo "Error: target day must be in the format 'NN' where NN is a two-digit number."
exit 1
fi

# Copy directory to new location
cp -R "$source_dir" "$target_dir"

# Replace XX with NN in file contents
find "$target_dir" -type f -exec sed -i '' "s/XX/${day_number}/g" {} +

# # Rename files and directories containing XX
# find "$target_dir" -depth -name "*XX*" | while read path; do
# new_path=$(echo "$path" | sed "s/XX/${target_dir:3}/g")
# mv "$path" "$new_path"
# done

echo "Directory $source_dir successfully copied to $target_dir and updated."

0 comments on commit 0fb84af

Please sign in to comment.