diff options
author | Leah Neukirchen <leah@vuxu.org> | 2018-12-11 14:28:18 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2018-12-11 14:28:18 +0100 |
commit | 116b36c06e24e3fc9bac5c2bbe0385305f0fc148 (patch) | |
tree | fd9b68e5ac19696742d113271673caa8a3f874d3 | |
parent | b3d780a4dba7edc1cbd151528d36761e936c4ce8 (diff) | |
download | adventofcode2018-116b36c06e24e3fc9bac5c2bbe0385305f0fc148.tar.gz adventofcode2018-116b36c06e24e3fc9bac5c2bbe0385305f0fc148.tar.xz adventofcode2018-116b36c06e24e3fc9bac5c2bbe0385305f0fc148.zip |
day06
-rw-r--r-- | day06 | 50 | ||||
-rw-r--r-- | day06.k | 3 | ||||
-rw-r--r-- | day06.rs | 48 |
3 files changed, 101 insertions, 0 deletions
diff --git a/day06 b/day06 new file mode 100644 index 0000000..e544bbd --- /dev/null +++ b/day06 @@ -0,0 +1,50 @@ +195, 221 +132, 132 +333, 192 +75, 354 +162, 227 +150, 108 +46, 40 +209, 92 +153, 341 +83, 128 +256, 295 +311, 114 +310, 237 +99, 240 +180, 337 +332, 176 +212, 183 +84, 61 +275, 341 +155, 89 +169, 208 +105, 78 +151, 318 +92, 74 +146, 303 +184, 224 +285, 348 +138, 163 +216, 61 +277, 270 +130, 155 +297, 102 +197, 217 +72, 276 +299, 89 +357, 234 +136, 342 +346, 221 +110, 188 +82, 183 +271, 210 +46, 198 +240, 286 +128, 95 +111, 309 +108, 54 +258, 305 +241, 157 +117, 162 +96, 301 diff --git a/day06.k b/day06.k new file mode 100644 index 0000000..cbe9cf2 --- /dev/null +++ b/day06.k @@ -0,0 +1,3 @@ +d:.:'1:`day06 +c@*(>c:#:'=,/r)^,/(*r;*|r;*+r;*|+r:{d@*<+/'v|-v:x-/:d}''500 500#+!500 500) / 3882 ++/~9999<(+//{x|-x}d-\:)'+!500 500 / 43852 diff --git a/day06.rs b/day06.rs new file mode 100644 index 0000000..02d5ffc --- /dev/null +++ b/day06.rs @@ -0,0 +1,48 @@ +use std::fs::File; +use std::collections::{HashMap, HashSet}; +use std::io::{BufRead, BufReader}; + +fn l1(a: (i32, i32), b: (i32, i32)) -> i32 { + (a.0 - b.0).abs() + (a.1 - b.1).abs() +} + +fn main() { + let f = File::open("day06").unwrap(); + + let v: Vec<Vec<i32>> = BufReader::new(&f) + .lines() + .map(|l| { + l.unwrap().split(", ").map(|x| x.parse().unwrap()).collect() + }) + .collect(); + + let mut c = HashMap::new(); + let mut b = HashSet::new(); + + let mut s = 0; + + for x in 0..500 { + for y in 0..500 { + let next = v.iter() + .min_by_key(|p| l1((x, y), (p[0], p[1]))).unwrap(); + *c.entry(next).or_insert(0) += 1; + + if x == 0 || x == 499 || y == 0 || y == 499 { + b.insert(next); + } + + if v.iter().map(|p| l1((x, y), (p[0], p[1]))).sum::<i32>() < 10000 { + s += 1; + } + } + } + + println!( + "{}", + c.iter() + .filter(|(k, _)| !b.contains(*k)) + .max_by_key(|(_, v)| *v) + .unwrap().1 + ); + println!("{}", s); +} |