--- /dev/null
+use std::error::Error;
+use std::path::Path;
+
+fn possible_values(operands: &[u64]) -> Vec<u64> {
+ let mut res: Vec<u64> = Vec::new();
+ for o in operands {
+ if res.is_empty() {
+ res.push(*o);
+ }
+ else {
+ let tmp = res.clone();
+ res = Vec::new();
+ for t in tmp {
+ res.push(t + o);
+ res.push(t * o);
+ }
+ }
+ }
+ res
+}
+
+fn run_part1(input: &str) -> Result<u64, Box<dyn Error>> {
+ println!("Running {} - part 1", get_day());
+
+ let res = input.lines()
+ .map(|l| {
+ let (tot, ops) = l.split_once(":").unwrap();
+ let ops = ops.trim().split(" ")
+ .map(|v| v.parse::<u64>().unwrap())
+ .collect::<Vec<u64>>();
+ (tot.parse::<u64>().unwrap(), ops)
+ })
+ .map(|(tot, ops)| {
+ let values = possible_values(&ops);
+ if values.contains(&tot) {
+ tot
+ }
+ else {
+ 0
+ }
+ })
+ .sum();
+
+ Ok(res)
+}
+
+fn run_part2(input: &str) -> Result<u64, Box<dyn Error>> {
+ println!("Running {} - part 2", get_day());
+
+ Ok(0)
+}
+
+pub fn run(input: &str) -> Result<(), Box<dyn Error>> {
+ let res = run_part1(&input)?;
+ println!("{res}");
+
+ let res = run_part2(&input)?;
+ println!("{res}");
+
+ Ok(())
+}
+
+fn get_day() -> String {
+ let filename = file!();
+ Path::new(filename).file_stem().unwrap().to_str().unwrap().to_string()
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ static TEXT_INPUT: &str = "\
+190: 10 19
+3267: 81 40 27
+83: 17 5
+156: 15 6
+7290: 6 8 6 15
+161011: 16 10 13
+192: 17 8 14
+21037: 9 7 18 13
+292: 11 6 16 20";
+
+ #[test]
+ fn test_part1() {
+ assert_eq!(3749, run_part1(TEXT_INPUT).unwrap());
+ }
+
+ #[test]
+ fn test_part2() {
+ assert_eq!(0, run_part2(TEXT_INPUT).unwrap());
+ }
+}
pub mod day04;
pub mod day05;
pub mod day06;
+pub mod day07;
fn main() {
let args: Vec<String> = env::args().collect();
"day04" => day04::run(&input)?,
"day05" => day05::run(&input)?,
"day06" => day06::run(&input)?,
+ "day07" => day07::run(&input)?,
_ => return Err(format!("unknown or unimplemented day \"{day}\"").into()),
}
Ok(())