From 68fa7fa6f533a8b91a0c56866ec64813454bf8f4 Mon Sep 17 00:00:00 2001 From: Tobias Marschner Date: Sun, 11 Feb 2024 12:46:21 +0100 Subject: [PATCH] Add template + setup script to get started quickly --- 2022/aoc_template/Cargo.toml | 8 ++++++++ 2022/aoc_template/src/main.rs | 21 +++++++++++++++++++++ 2022/setup.sh | 12 ++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 2022/aoc_template/Cargo.toml create mode 100644 2022/aoc_template/src/main.rs create mode 100755 2022/setup.sh diff --git a/2022/aoc_template/Cargo.toml b/2022/aoc_template/Cargo.toml new file mode 100644 index 0000000..580877c --- /dev/null +++ b/2022/aoc_template/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "aoc_template" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/2022/aoc_template/src/main.rs b/2022/aoc_template/src/main.rs new file mode 100644 index 0000000..f57eb96 --- /dev/null +++ b/2022/aoc_template/src/main.rs @@ -0,0 +1,21 @@ +fn main() { + // Use command line arguments to specify the input filename. + let args: Vec = std::env::args().collect(); + if args.len() < 2 { + panic!("Usage: ./main \nNo input file provided. Exiting."); + } + + // Next, read the contents of the input file into a string for easier processing. + let input = std::fs::read_to_string(&args[1]).expect("Error opening file"); + // Line-by-line processing is easiest. + let input = input.lines(); + + // --- TASK BEGIN --- + let mut result = 0; + + for line in input { + } + + println!("Result: {}", result); +} + diff --git a/2022/setup.sh b/2022/setup.sh new file mode 100755 index 0000000..0119650 --- /dev/null +++ b/2022/setup.sh @@ -0,0 +1,12 @@ +#!/bin/bash +set -euo pipefail + +if [[ "$#" != "1" ]]; then + echo " Usage: ./setup.sh " + echo "Example: ./setup.sh 13" + exit 1 +fi + +ident="day${1}-part1" +cp -r aoc_template "$ident" +sed -i -e "s/aoc_template/$ident/g" "$ident/Cargo.toml"