From a94eca12bfa36abf940b6fa3976193f800f56ec0 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sat, 9 Dec 2023 23:29:55 +0100 Subject: [PATCH] Completed 6.2 --- day_06/Cargo.toml | 1 - day_06/input.txt | 4 ++-- day_06/src/main.rs | 22 ++-------------------- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/day_06/Cargo.toml b/day_06/Cargo.toml index 2f57cbd..216c73c 100644 --- a/day_06/Cargo.toml +++ b/day_06/Cargo.toml @@ -6,4 +6,3 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -num-integer = "0.1.45" diff --git a/day_06/input.txt b/day_06/input.txt index 28f5ae9..3968d4a 100644 --- a/day_06/input.txt +++ b/day_06/input.txt @@ -1,2 +1,2 @@ -Time: 7 15 30 -Distance: 9 40 200 +Time: 53 91 67 68 +Distance: 250 1330 1081 1025 diff --git a/day_06/src/main.rs b/day_06/src/main.rs index e4ae126..483137d 100644 --- a/day_06/src/main.rs +++ b/day_06/src/main.rs @@ -1,7 +1,5 @@ use std::fs; -use num_integer::Roots; - fn main() { let data = fs::read_to_string("input.txt").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_record: i64 = record_str[9..].trim().replace(' ', "").parse().unwrap(); - /* - distance = held * (time - held) - - 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}"); + println!("{} {}", big_time, big_record); + println!("{}", beat(big_time, big_record)); } fn beat(time: i64, record: i64) -> i64 { @@ -46,12 +35,5 @@ fn beat(time: i64, record: i64) -> i64 { 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 }