-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.rs
23 lines (22 loc) · 806 Bytes
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
pub fn main() {
let input = include_bytes!("../input.txt");
let newline = input.iter().position(|b| b == &b'\n').unwrap();
println!(
"{}",
input[11..newline]
.split(|b| b == &b' ')
.flat_map(atoi::atoi::<usize>)
.zip(
input[newline + 12..]
.split(|b| b == &b' ')
.flat_map(atoi::atoi::<usize>),
)
.map(|(t, d)| {
// Modified quadratic formula: <https://en.wikipedia.org/wiki/Quadratic_formula>
let a = (t - f64::sqrt((t * t - 4 * d) as f64) as usize) / 2;
let b = t - a;
b - (b * (t - b) <= d) as usize - a - (a * (t - a) <= d) as usize + 1
})
.product::<usize>()
);
}