Compare commits
No commits in common. "d7d1cdc9392be476caf02619b493b2fd6588ac66" and "c6ca78cbef536101dc32480c6376141e36738e6b" have entirely different histories.
d7d1cdc939
...
c6ca78cbef
|
@ -24,7 +24,6 @@ dependencies = [
|
||||||
"aoc-parse",
|
"aoc-parse",
|
||||||
"chrono",
|
"chrono",
|
||||||
"dhat",
|
"dhat",
|
||||||
"itertools",
|
|
||||||
"num",
|
"num",
|
||||||
"pathfinding",
|
"pathfinding",
|
||||||
"pico-args",
|
"pico-args",
|
||||||
|
@ -165,12 +164,6 @@ dependencies = [
|
||||||
"thousands",
|
"thousands",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "either"
|
|
||||||
version = "1.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "equivalent"
|
name = "equivalent"
|
||||||
version = "1.0.1"
|
version = "1.0.1"
|
||||||
|
@ -237,15 +230,6 @@ dependencies = [
|
||||||
"num-traits",
|
"num-traits",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "itertools"
|
|
||||||
version = "0.12.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
|
|
||||||
dependencies = [
|
|
||||||
"either",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "itoa"
|
name = "itoa"
|
||||||
version = "1.0.9"
|
version = "1.0.9"
|
||||||
|
|
|
@ -30,5 +30,4 @@ dhat = { version = "0.3.2", optional = true }
|
||||||
num = "0.4.1"
|
num = "0.4.1"
|
||||||
pathfinding = "4.8.2"
|
pathfinding = "4.8.2"
|
||||||
pico-args = "0.5.0"
|
pico-args = "0.5.0"
|
||||||
tinyjson = "2.5.1"
|
tinyjson = "2.5.1"
|
||||||
itertools = "0.12.1"
|
|
|
@ -1,5 +0,0 @@
|
||||||
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,91 +1,10 @@
|
||||||
advent_of_code::solution!(24);
|
advent_of_code::solution!(24);
|
||||||
|
|
||||||
use aoc_parse::{parser, prelude::*};
|
pub fn part_one(input: &str) -> Option<u32> {
|
||||||
use itertools::Itertools;
|
None
|
||||||
|
|
||||||
struct Hail {
|
|
||||||
id: usize,
|
|
||||||
x: f64,
|
|
||||||
y: f64,
|
|
||||||
z: f64,
|
|
||||||
dx: f64,
|
|
||||||
dy: f64,
|
|
||||||
dz: f64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Hail {
|
pub fn part_two(input: &str) -> Option<u32> {
|
||||||
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
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +15,7 @@ mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_part_one() {
|
fn test_part_one() {
|
||||||
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
|
let result = part_one(&advent_of_code::template::read_file("examples", DAY));
|
||||||
assert_eq!(result, Some(2));
|
assert_eq!(result, None);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in New Issue