Completed 6.2

This commit is contained in:
Crispy 2023-12-09 23:29:55 +01:00
parent ddc128f877
commit a94eca12bf
3 changed files with 4 additions and 23 deletions

View file

@ -6,4 +6,3 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies] [dependencies]
num-integer = "0.1.45"

View file

@ -1,2 +1,2 @@
Time: 7 15 30 Time: 53 91 67 68
Distance: 9 40 200 Distance: 250 1330 1081 1025

View file

@ -1,7 +1,5 @@
use std::fs; use std::fs;
use num_integer::Roots;
fn main() { fn main() {
let data = fs::read_to_string("input.txt").unwrap(); let data = fs::read_to_string("input.txt").unwrap();
let (time_str, record_str) = data.split_once('\n').unwrap(); let (time_str, record_str) = data.split_once('\n').unwrap();
@ -25,17 +23,8 @@ fn main() {
let big_time: i64 = time_str[7..].replace(' ', "").parse().unwrap(); let big_time: i64 = time_str[7..].replace(' ', "").parse().unwrap();
let big_record: i64 = record_str[9..].trim().replace(' ', "").parse().unwrap(); let big_record: i64 = record_str[9..].trim().replace(' ', "").parse().unwrap();
/* println!("{} {}", big_time, big_record);
distance = held * (time - held) println!("{}", beat(big_time, big_record));
held * (time - held) = record
held*time - held*held = record
held*time - held*held - record = 0
held*held - held*time + record = 0
*/
// let lower = ((time * time / 4) - record).sqrt() - time / 2;
// let upper = -((time * time / 4) - record).sqrt() - time / 2;
// println!("{lower} -> {upper}");
} }
fn beat(time: i64, record: i64) -> i64 { fn beat(time: i64, record: i64) -> i64 {
@ -46,12 +35,5 @@ fn beat(time: i64, record: i64) -> i64 {
variants += 1; variants += 1;
} }
} }
let time = time as f64;
let record = record as f64;
let lower = ((time * time / 4.0) - record).sqrt() - time / 2.0;
let upper = -((time * time / 4.0) - record).sqrt() - time / 2.0;
println!("{lower} -> {upper}");
variants variants
} }