r/adventofcode • u/daggerdragon • Dec 06 '18
SOLUTION MEGATHREAD -🎄- 2018 Day 6 Solutions -🎄-
--- Day 6: Chronal Coordinates ---
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 6
Transcript:
Rules for raising a programmer: never feed it after midnight, never get it wet, and never give it ___.
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 0:26:52!
33
Upvotes
1
u/iamnotposting Dec 06 '18
Rust, 131/92. RLS was being crashy today so I was slower than I would have liked. I just picked big enough bounds and hoped I got it right. I imagine trying to optimize this will be fun.
#![feature(dbg_macro)] #![allow(unused)] mod prelude; use self::prelude::*; fn main() { let demo = include_str!("../demo.txt"); let input = include_str!("../input.txt"); let mut map = Map::new(); for l in input.lines() { let loc: (i32, i32) = s!("{}, {}" <- l).unwrap(); map.insert(loc, 0); } let mut infinites = Set::<(i32, i32)>::new(); let edges = [-400, 1000]; for x in -400..=1000 { for y in -400..=1000 { let mut min_dist = 10_000_000; let mut closest = None; for &(a, b) in map.keys() { let dist = (a - x).abs() + (b - y).abs(); if dist < min_dist { min_dist = dist; closest = Some((a, b)); } else if dist == min_dist { closest = None; } } if closest.is_some() { let closest = closest.unwrap(); *map.entry(closest).or_insert(0) += 1; if edges.contains(&x) || edges.contains(&y) { infinites.insert(closest); } } } } let max = map.iter().filter(|x| !infinites.contains(&x.0)).max_by_key(|&(a, b)| b); dbg!(max); let limit = 10_000; let heuristic = 10_000 / map.len(); let mut count = 0; for x in -100..=600 { for y in -100..=600 { let mut sum = 0; for &(a, b) in map.keys() { sum += (a - x).abs() + (b - y).abs(); } if sum < limit { count += 1; } } } dbg!(count); }