Skip to content

Instantly share code, notes, and snippets.

@JCBurnside
Last active December 2, 2020 00:33
Show Gist options
  • Save JCBurnside/35c4b74cc2dfbc904ec9bbe50fcf2399 to your computer and use it in GitHub Desktop.
Save JCBurnside/35c4b74cc2dfbc904ec9bbe50fcf2399 to your computer and use it in GitHub Desktop.
aoc2020 day 1
use std::fs;
use std::io::{BufRead, BufReader, Error};
fn main() -> anyhow::Result<()> {
let data_file = fs::File::open("data.txt")?;
let numbers =BufReader::new(data_file)
.lines()
.map(|l| Ok(l?.parse()?))
.collect::<anyhow::Result<Vec<u32>>>()?;
println!("part one");
'part1: for num0 in &numbers
{
for num1 in &numbers
{
if num0 + num1 == 2020
{
println!("{} and {} make {}", num0, num1, num0 * num1);
break 'part1;
}
}
}
println!("part two");
'part2: for num0 in &numbers
{
for num1 in &numbers
{
for num2 in &numbers {
if num0 + num1 + num2 == 2020
{
println!("{} and {} and {} make {}", num0, num1, num2, num0 * num1 * num2);
break 'part2;
}
}
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment