summaryrefslogtreecommitdiff
path: root/2023/day06.rs
diff options
context:
space:
mode:
Diffstat (limited to '2023/day06.rs')
-rw-r--r--2023/day06.rs17
1 files changed, 7 insertions, 10 deletions
diff --git a/2023/day06.rs b/2023/day06.rs
index 92a631a..839c798 100644
--- a/2023/day06.rs
+++ b/2023/day06.rs
@@ -1,17 +1,14 @@
-#![allow(dead_code)]
-#![allow(unused_variables)]
-#![allow(unused_mut)]
+#![allow(non_snake_case)]
use std::fs::File;
use std::io::Read;
fn get_opts(t: u64, d: u64) -> u64 {
- let mut opts = 0;
- for wait in 0..t {
- if wait * (t - wait) > d {
- opts += 1;
- }
- }
- return opts;
+ let t = t as f64;
+ let d = d as f64;
+ let D = f64::sqrt((t * t - 4. * d) as f64);
+ let x1 = ((-t - D) / 2.).floor();
+ let x2 = ((-t + D) / 2.).floor();
+ (x2 - x1) as u64
}
fn main() {