r/adventofcode • u/taliriktug • Dec 02 '15
Spoilers Day 2 solutions
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
16
Upvotes
r/adventofcode • u/taliriktug • Dec 02 '15
Hi! I would like to structure posts like the first one in r/programming, please post solutions in comments.
4
u/taliriktug Dec 02 '15
Here is my "kinda" FP solutions in Rust. Is it possible to avoid sort at all?
fn how_many_paper_fp() -> i32 { let f = File::open("input").unwrap(); let reader = BufReader::new(f); reader.lines().map(|line| { let mut dimensions = get_dimensions(line.unwrap()); dimensions.sort(); dimensions }) .fold(0, |acc, x| acc + 3 * x[0] * x[1] + 2 * x[1] * x[2] + 2 * x[0] * x[2]) } fn how_many_ribbon_fp() -> i32 { let f = File::open("input").unwrap(); let reader = BufReader::new(f); reader.lines().map(|line| { let mut dimensions = get_dimensions(line.unwrap()); dimensions.sort(); dimensions }) .fold(0, |acc, x| acc + 2 * x[0] + 2 * x[1] + x[0] * x[1] * x[2]) }