Hey - I'm working on the problems in Rust this year, too! I'm putting all mine in Github, but will share here, too.
(I found a cool cargo plugin that provides helpful macros and makes doing AoC stuff easier - cargo-aoc)
useaoc_runner_derive::{aoc,aoc_generator};#[aoc_generator(day1)]fnparse_input_day1(input:&str)->Vec<usize>{input.lines().map(|v|v.parse().expect("Failed to parse input!")).collect()}#[aoc(day1,part1)]fnfind_2020_entries(input:&Vec<usize>)->usize{letpair=input.iter().enumerate().find_map(|(idx,&item)|{matchinput.iter().enumerate().find(|(idx2,&second)|idx2!=&idx&&(item+second==2020)){Some((_,second))=>Some(item*second),None=>None,}});pair.unwrap_or(1)}#[aoc(day1,part2)]fnfind_2020_entries_with_three(input:&Vec<usize>)->usize{letresult=input.iter().enumerate().find_map(|(idx,&item)|{input.iter().enumerate().find_map(|(idx2,&second)|{matchinput.iter().enumerate().find(|(idx3,&third)|{idx2!=idx&&&idx!=idx3&&&idx2!=idx3&&(item+second+third==2020)}){Some((_,third))=>Some(item*second*third),None=>None,}})});result.unwrap_or(1)}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Here is my solution in rust (minus all the code required to grab the input and parse it)
Hey - I'm working on the problems in Rust this year, too! I'm putting all mine in Github, but will share here, too.
(I found a cool cargo plugin that provides helpful macros and makes doing AoC stuff easier - cargo-aoc)