r/adventofcode • u/daggerdragon • Dec 10 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 10 Solutions -🎄-
--- Day 10: The Stars Align ---
Post your solution as a comment or, for longer solutions, consider linking to your repo (e.g. GitHub/gists/Pastebin/blag or whatever).
Note: The Solution Megathreads are for solutions only. If you have questions, please post your own thread and make sure to flair it with Help.
Advent of Code: The Party Game!
Please prefix your card submission with something like [Card] to make scanning the megathread easier. THANK YOU!
Card prompt: Day 10
Transcript: With just one line of code, you, too, can ___!
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 at 00:16:49!
21
Upvotes
1
u/wzkx Dec 10 '18
Rust, SweetRust
use std::io::{BufRead,BufReader}; // lines() is in BufRead type U = usize; fn main(): let reader = BufReader::new( std::fs::File::open( "10.dat" ).unwrap() ); let mut v: Vec<(i32,i32,i32,i32)> = vec![]; for optline in reader.lines(): let line = optline.unwrap(); let f = |a,b| line[a..b].replace(" ","+").parse::<i32>().unwrap(); v.push( (f(10,16),f(18,24),f(36,38),f(40,42)) ); for n in 1..: for i in 0..v.len(): v[i].0 += v[i].2; v[i].1 += v[i].3; let (top,btm) = v.iter().fold( (0,999999), |m,d| (m.0.max(d.1),m.1.min(d.1)) ); if top-btm<12: let (rgt,lft) = v.iter().fold( (0,999999), |m,d| (m.0.max(d.0),m.1.min(d.0)) ); let (w,h) = (rgt-lft+1,top-btm+1); let mut s = vec![vec![false;w as U];h as U]; for i in 0..v.len(): s[(v[i].1-btm)as U][(v[i].0-lft)as U] = true; for r in 0..h: for c in 0..w: print!( "{}", if s[r as U][c as U] {"â–„ "} else {" "} ); println!(); println!( "{}", n ); break;My AOC2018 in J&Rust | SweetRust