1
0

added script for new day

This commit is contained in:
2024-12-10 20:46:48 +01:00
parent 934dc5cb7f
commit 6946298ed7
4 changed files with 34 additions and 1 deletions

31
newday.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <two_digit_number>"
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"

View File

@@ -8,4 +8,5 @@ pub mod day07;
pub mod day08;
pub mod day09;
pub mod day10;
// PLACEHOLDER
pub mod utils;

View File

@@ -15,6 +15,7 @@ fn main() {
(8, day08::day_main),
(9, day09::day_main),
(10, day10::day_main),
// PLACEHOLDER
]);
let day: Option<u8> = args().nth(1).and_then(|a| a.parse().ok());
let Some(day) = day else {

View File

@@ -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));