From 6946298ed7762bf132a2baa24f7a01bdf13b0622 Mon Sep 17 00:00:00 2001 From: Johannes Date: Tue, 10 Dec 2024 20:46:48 +0100 Subject: [PATCH] added script for new day --- newday.sh | 31 +++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/main.rs | 1 + src/template.rs | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100755 newday.sh diff --git a/newday.sh b/newday.sh new file mode 100755 index 0000000..865f693 --- /dev/null +++ b/newday.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Check if the correct number of arguments is provided +if [ "$#" -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Get the parameters +X="$1" + +# Validate that X is a two-digit number +if ! [[ "$X" =~ ^[0-9]{2}$ ]]; then + echo "Error: The parameter must be a two-digit number." + exit 1 +fi + +cp src/template.rs src/day$X.rs +touch input/day$X.txt + +# Define the placeholder you want to replace +PLACEHOLDER="{{day}}" + +# Use sed to replace the placeholder with the desired text +sed -i "s|$PLACEHOLDER|$X|g" "src/day$X.rs" +sed -i "s/.*\/\/ PLACEHOLDER.*/pub mod day$X;\n\/\/ PLACEHOLDER/" "src/lib.rs" +sed -i "s/.*\/\/ PLACEHOLDER.*/($X, day$X::day_main),\n\/\/ PLACEHOLDER/" "src/main.rs" + +cargo fmt + +echo "seems allright. created template for day $X" diff --git a/src/lib.rs b/src/lib.rs index 7bbcb98..ff40f6f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,4 +8,5 @@ pub mod day07; pub mod day08; pub mod day09; pub mod day10; +// PLACEHOLDER pub mod utils; diff --git a/src/main.rs b/src/main.rs index a206d00..f28af20 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,6 +15,7 @@ fn main() { (8, day08::day_main), (9, day09::day_main), (10, day10::day_main), + // PLACEHOLDER ]); let day: Option = args().nth(1).and_then(|a| a.parse().ok()); let Some(day) = day else { diff --git a/src/template.rs b/src/template.rs index 270ae99..5c6b148 100644 --- a/src/template.rs +++ b/src/template.rs @@ -1,7 +1,7 @@ use std::fs::read_to_string; pub fn day_main() { - let input = read_to_string("input/dayXX.txt").unwrap(); + let input = read_to_string("input/day{{day}}.txt").unwrap(); let input = input.trim(); println!(" part1: {}", part1(input)); println!(" part2: {}", part2(input));