]> aoc.elinar.fr Git - aoc_2026/commitdiff
initial setup
authoralex <>
Tue, 1 Dec 2026 09:39:50 +0000 (10:39 +0100)
committeralex <>
Tue, 1 Dec 2026 09:39:50 +0000 (10:39 +0100)
Cargo.lock [new file with mode: 0644]
Cargo.toml [new file with mode: 0644]
aoc [new file with mode: 0755]
src/main.rs [new file with mode: 0644]

diff --git a/Cargo.lock b/Cargo.lock
new file mode 100644 (file)
index 0000000..1bfbe2a
--- /dev/null
@@ -0,0 +1,7 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+version = 4
+
+[[package]]
+name = "aoc_2026"
+version = "0.1.0"
diff --git a/Cargo.toml b/Cargo.toml
new file mode 100644 (file)
index 0000000..704e15c
--- /dev/null
@@ -0,0 +1,6 @@
+[package]
+name = "aoc_2026"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/aoc b/aoc
new file mode 100755 (executable)
index 0000000..6124536
--- /dev/null
+++ b/aoc
@@ -0,0 +1,76 @@
+#!/bin/bash
+
+usage() {
+    cat <<EOF
+usage: aoc [options] <DAY>...
+
+Options:
+  --run           run the solution for the given <DAY> (default)
+  --test          run the tests for the given <DAY>
+  --input         retrieve the input file for the given <DAY> (default)
+  --html          retrieve the writeup for a given <DAY>
+  --help          print this help and exit
+EOF
+}
+
+read_cookie() {
+    [ ! -f .cookie ] && echo "Missing .cookie file" && exit 1
+    COOKIE=$(cat .cookie)
+    [ -z "$COOKIE" ] && echo "Cookie file is empty" && exit 1
+}
+
+get_input() {
+    [ -f input/$DAY.txt ] && return
+    read_cookie
+    curl -o input/$DAY.txt \
+        -H "Cookie: session=$COOKIE" \
+        "https://adventofcode.com/2026/day/${N}/input"
+}
+
+get_html() {
+    read_cookie
+    curl -o html/$DAY.html \
+        -H "Cookie: session=$COOKIE" \
+        "https://adventofcode.com/2026/day/${N}"
+}
+
+do_test() {
+    cargo test $DAY::tests
+}
+
+do_run() {
+    cargo run --release $DAY input/$DAY.txt
+}
+
+COOKIE=""
+
+DAY=""
+DO_RUN=1
+DO_TEST=0
+DO_INPUT=1
+DO_HTML=0
+
+while [ $# -ge 1 ]; do
+    case $1 in
+        "--run") DO_RUN=1; DO_TEST=0 ;;
+        "--test") DO_RUN=0; DO_TEST=1; DO_INPUT=0 ;;
+        "--input") DO_INPUT=1; DO_RUN=0 ;;
+        "--html") DO_HTML=1; DO_RUN=0 ;;
+        "--help"|"-h") usage && exit 0 ;;
+        -*) echo "Unknown or missing option: $1" && usage && exit 1 ;;
+        *) break ;;
+    esac
+    shift
+done
+
+while [ $# -ge 1 ]; do
+    DAY=$1
+    echo "day: $DAY"
+    N=${DAY/day0/}
+    N=${N/day/}
+    [ $DO_HTML -eq 1 ] && get_html
+    [ $DO_INPUT -eq 1 ] && get_input
+    [ $DO_RUN -eq 1 ] && do_run
+    [ $DO_TEST -eq 1 ] && do_test
+    shift
+done
diff --git a/src/main.rs b/src/main.rs
new file mode 100644 (file)
index 0000000..e650b27
--- /dev/null
@@ -0,0 +1,27 @@
+use std::env;
+use std::process;
+use std::error::Error;
+use std::fs::File;
+use std::io::Read;
+
+//pub mod day01;
+
+fn main() {
+    let args: Vec<String> = env::args().collect();
+    if let Err(e) = run(&args[1], &args[2]) {
+        println!("Error: {e}");
+        process::exit(2);
+    }
+}
+
+fn run(day: &str, input_file: &str) -> Result<(), Box<dyn Error>> {
+    let mut f = File::open(input_file)?;
+    let mut input = String::new();
+    f.read_to_string(&mut input)?;
+
+    match day {
+        //"day01" => day01::run(&input)?,
+        _ => return Err(format!("unknown or unimplemented day \"{day}\"").into()),
+    }
+    Ok(())
+}