#!/bin/sh -e YEAR=${YEAR:-$(date +%Y)} DAY=${DAY:-$(TZ=EST date '+%d')} GIT_USER=$(git config --get 'user.name') GIT_EMAIL=$(git config --get 'user.email') CARGO=$( sed "s/^#\(.*${DAY}\)/\1/" <"${YEAR}/rust/Cargo.toml") echo "${CARGO}" >"${YEAR}/rust/Cargo.toml" cd "${YEAR}/rust" mkdir "day${DAY}" || : cd "day${DAY}" cargo init --bin cat > 'Cargo.toml' << END_OF_TOML [package] name = "day${DAY}" version = "0.1.0" authors = ["${GIT_USER} <${GIT_EMAIL}>"] edition = "2021" [dependencies] aoc = { path = "../../../common/rust/aoc" } anyhow = "1.0" END_OF_TOML cat > 'src/main.rs' << END_OF_SRC use { anyhow::{ anyhow, Context, Result, }, std::{ env::args, fs::File, io::{ BufRead, BufReader, }, path::Path, }, }; fn read_input>(filename: T) -> Result> { let reader = BufReader::new(File::open(filename)?); reader.lines().map( |v| { let s = v?; let n = s.parse()?; Ok(n) } ).collect() } fn part1<'a, I: IntoIterator>(_input: I) -> Result { Ok(0) } fn part2<'a, I: IntoIterator>(_input: I) -> Result { Ok(0) } fn main() -> Result<()> { let ( do_part_1, do_part_2 ) = aoc::do_parts(); let filename = args().nth(1).ok_or(anyhow!("Missing input filename"))?; let input = read_input(filename).context("Could not read input")?; if do_part_1 { let solution = part1(&input).context("No solution for part 1")?; println!("Part1, solution found to be: {}", solution); } if do_part_2 { let solution = part2(&input).context("No solution for part 2")?; println!("Part2, solution found to be: {}", solution); } Ok(()) } END_OF_SRC