Compare commits
2 Commits
c6ca78cbef
...
d7d1cdc939
Author | SHA1 | Date |
---|---|---|
Andrew Coleman | d7d1cdc939 | |
Andrew Coleman | 8d1554b542 |
|
@ -24,6 +24,7 @@ dependencies = [
|
|||
"aoc-parse",
|
||||
"chrono",
|
||||
"dhat",
|
||||
"itertools",
|
||||
"num",
|
||||
"pathfinding",
|
||||
"pico-args",
|
||||
|
@ -164,6 +165,12 @@ dependencies = [
|
|||
"thousands",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.1"
|
||||
|
@ -230,6 +237,15 @@ dependencies = [
|
|||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.9"
|
||||
|
|
|
@ -30,4 +30,5 @@ dhat = { version = "0.3.2", optional = true }
|
|||
num = "0.4.1"
|
||||
pathfinding = "4.8.2"
|
||||
pico-args = "0.5.0"
|
||||
tinyjson = "2.5.1"
|
||||
tinyjson = "2.5.1"
|
||||
itertools = "0.12.1"
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
19, 13, 30 @ -2, 1, -2
|
||||
18, 19, 22 @ -1, -1, -2
|
||||
20, 25, 34 @ -2, -2, -4
|
||||
12, 31, 28 @ -1, -2, -1
|
||||
20, 19, 15 @ 1, -5, -3
|
|
@ -1,10 +1,91 @@
|
|||
advent_of_code::solution!(24);
|
||||
|
||||
pub fn part_one(input: &str) -> Option<u32> {
|
||||
None
|
||||
use aoc_parse::{parser, prelude::*};
|
||||
use itertools::Itertools;
|
||||
|
||||
struct Hail {
|
||||
id: usize,
|
||||
x: f64,
|
||||
y: f64,
|
||||
z: f64,
|
||||
dx: f64,
|
||||
dy: f64,
|
||||
dz: f64,
|
||||
}
|
||||
|
||||
pub fn part_two(input: &str) -> Option<u32> {
|
||||
impl Hail {
|
||||
fn intersect(self: &Self, other: &Hail) -> bool {
|
||||
let bt = ((other.x - self.x) / self.dx - (other.y - self.y) / self.dy)
|
||||
/ (other.dy / self.dy - other.dx / self.dx);
|
||||
let at = (other.x + bt * other.dx - self.x) / self.dx;
|
||||
let ix = self.x + self.dx * at;
|
||||
let iy = self.y + self.dy * at;
|
||||
bt >= 0.0
|
||||
&& at >= 0.0
|
||||
&& ix >= TARGET.0
|
||||
&& ix <= TARGET.1
|
||||
&& iy >= TARGET.0
|
||||
&& iy <= TARGET.1
|
||||
}
|
||||
}
|
||||
|
||||
fn parse(input: &str) -> Vec<Hail> {
|
||||
let p = parser!(lines(f64 ", " f64 ", " f64 " @ " f64 ", " f64 ", " f64));
|
||||
p.parse(input)
|
||||
.unwrap()
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(index, h)| Hail {
|
||||
id: index,
|
||||
x: h.0,
|
||||
y: h.1,
|
||||
z: h.2,
|
||||
dx: h.3,
|
||||
dy: h.4,
|
||||
dz: h.5,
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
}
|
||||
|
||||
#[cfg(not(test))]
|
||||
const TARGET: (f64, f64) = (200000000000000., 400000000000000.);
|
||||
|
||||
#[cfg(test)]
|
||||
const TARGET: (f64, f64) = (7., 27.);
|
||||
|
||||
pub fn part_one(input: &str) -> Option<usize> {
|
||||
let stones = parse(input);
|
||||
|
||||
let c = stones
|
||||
.iter()
|
||||
.combinations(2)
|
||||
.filter(|st| st[0].intersect(&st[1]))
|
||||
.count();
|
||||
Some(c)
|
||||
}
|
||||
|
||||
fn elim(matrix: Vec<f64>) {}
|
||||
|
||||
pub fn part_two(input: &str) -> Option<usize> {
|
||||
let stones = parse(input);
|
||||
let xymatrix = stones
|
||||
.iter()
|
||||
.map(|s| vec![-s.dy, s.dx, s.y, -s.x, s.y * s.dx - s.x * s.dy])
|
||||
.collect::<Vec<_>>();
|
||||
let lastxy = &xymatrix[xymatrix.len() - 1];
|
||||
let xydiff = xymatrix
|
||||
.iter()
|
||||
.take(4)
|
||||
.map(|r| r.iter().zip_eq(lastxy).map(|(a, b)| a - b));
|
||||
let zmatrix = stones
|
||||
.iter()
|
||||
.map(|s| vec![-s.z, s.dz, s.y, -s.z, s.y * s.dz - s.z * s.dy])
|
||||
.collect::<Vec<_>>();
|
||||
let lastz = &zmatrix[zmatrix.len() - 1];
|
||||
let zdiff = zmatrix
|
||||
.iter()
|
||||
.take(4)
|
||||
.map(|r| r.iter().zip_eq(lastz).map(|(a, b)| a - b));
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -15,7 +96,7 @@ mod tests {
|
|||
#[test]
|
||||
fn test_part_one() {
|
||||
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
|
||||
assert_eq!(result, None);
|
||||
assert_eq!(result, Some(2));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in New Issue