You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
883 B

const INPUT: &str = include_str!("../../data/day1");
fn main() {
let expenses: Vec<_> = INPUT.split_whitespace().map(|s| s.parse::<u32>().unwrap()).collect();
'outer: for (pos, &exp1) in expenses.iter().enumerate() {
for &exp2 in expenses[pos+1..].iter() {
if exp1 + exp2 == 2020 {
println!(
"Found: {exp1} + {exp2} = 2020; {exp1} * {exp2} = {}",
exp1 * exp2,
exp1 = exp1,
exp2 = exp2,
);
break 'outer;
}
}
}
'outer2: for (pos, &exp1) in expenses.iter().enumerate() {
for (pos2, &exp2) in expenses[pos+1..].iter().enumerate() {
for &exp3 in expenses[pos2+1..].iter() {
if exp1 + exp2 + exp3 == 2020 {
println!(
"Found: {exp1} + {exp2} + {exp3} = 2020; {exp1} * {exp2} * {exp3} = {}",
exp1 * exp2 * exp3,
exp1 = exp1,
exp2 = exp2,
exp3 = exp3,
);
break 'outer2;
}
}
}
}
}