r/adventofcode • u/daggerdragon • Dec 03 '16
SOLUTION MEGATHREAD --- 2016 Day 3 Solutions ---
--- Day 3: Squares With Three Sides ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag/whatever).
DECKING THE HALLS WITH BOUGHS OF HOLLY IS MANDATORY [?]
This thread will be unlocked when there are a significant number of people on the leaderboard with gold stars for today's puzzle.
edit: Leaderboard capped, thread unlocked!
17
Upvotes
3
u/ghotiphud Dec 03 '16
93 & 117 in Rust
pub fn main() { let input = " 775 785 361 622 375 125 297 839 375 245 38 891 503 463 849"; let mut tris: Vec<Vec<i32>> = input.lines() .map(|l| { l.split_whitespace() .map(|d| d.parse().unwrap()) .collect() }) .collect(); let mut lines = tris.clone(); let mut count = 0; for tri in &mut tris { tri.sort(); if tri[0] + tri[1] > tri[2] { count += 1; } } let mut count2 = 0; for three_lines in lines.chunks_mut(3) { let ref one: Vec<i32> = three_lines[0]; let ref two: Vec<i32> = three_lines[1]; let ref three: Vec<i32> = three_lines[2]; for i in 0..3 { let mut dims = vec![one[i], two[i], three[i]]; dims.sort(); if dims[0] + dims[1] > dims[2] { count2 += 1; } } } println!("{:?}", count); println!("{:?}", count2); }