From: alex <> Date: Tue, 1 Dec 2026 09:39:50 +0000 (+0100) Subject: initial setup X-Git-Url: https://aoc.elinar.fr/?a=commitdiff_plain;h=650c94db9fa154149d1a113140c81e1514e60fca;p=aoc_2026 initial setup --- 650c94db9fa154149d1a113140c81e1514e60fca diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..1bfbe2a --- /dev/null +++ b/Cargo.lock @@ -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 index 0000000..704e15c --- /dev/null +++ b/Cargo.toml @@ -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 index 0000000..6124536 --- /dev/null +++ b/aoc @@ -0,0 +1,76 @@ +#!/bin/bash + +usage() { + cat <... + +Options: + --run run the solution for the given (default) + --test run the tests for the given + --input retrieve the input file for the given (default) + --html retrieve the writeup for a given + --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 index 0000000..e650b27 --- /dev/null +++ b/src/main.rs @@ -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 = 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> { + 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(()) +}