Created
December 6, 2023 07:55
-
-
Save rondreas/bf763ce706477ca3d96315a2667e3e76 to your computer and use it in GitHub Desktop.
Advent of Code 2023 Day 6: Wait For It
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn main() { | |
// test input | |
let times = [7u64, 15u64, 30u64]; | |
let distances = [9u64, 40u64, 200u64]; | |
for time_held in 1..6 { | |
let time_left = 7 - time_held; | |
let distace_travelled = time_held * time_left; | |
if distace_travelled > 9 { | |
} | |
} | |
let mut v: Vec<u64> = Vec::with_capacity(3); | |
for i in 0..3 { | |
let time = times[i]; | |
let dist = distances[i]; | |
let mut wins = 0; | |
for time_held in 1..time-1 { | |
let time_left = time - time_held; | |
let distace_travelled = time_held * time_left; | |
if distace_travelled > dist { | |
wins += 1; | |
} | |
} | |
v.push(wins); | |
} | |
println!("Test results: {}", v.iter().product::<u64>()); | |
let times = [59u64, 79u64, 65u64, 75u64]; | |
let distances = [597u64, 1234u64, 1032u64, 1328u64]; | |
let mut v: Vec<u64> = Vec::with_capacity(4); | |
for i in 0..4 { | |
let time = times[i]; | |
let dist = distances[i]; | |
let mut wins = 0; | |
for time_held in 1..time-1 { | |
let time_left = time - time_held; | |
let distace_travelled = time_held * time_left; | |
if distace_travelled > dist { | |
wins += 1; | |
} | |
} | |
v.push(wins); | |
} | |
println!("Part one: {}", v.iter().product::<u64>()); | |
// think this is how to get the min-max range to try | |
let time = 71530u128; | |
let dist = 940200u128; | |
let x = dist / time; | |
// bruteforcing the second test | |
let mut wins = 0; | |
for time_held in x..=time-x { | |
let time_left = time - time_held; | |
let distace_travelled = time_held * time_left; | |
if distace_travelled > dist { | |
wins += 1; | |
} | |
} | |
println!("Part two test: {}", wins); | |
let time = 59_796_575u128; | |
let dist = 597_123_410_321_328u128; | |
let x = dist / time; | |
wins = 0; | |
for time_held in x..=time-x { | |
let time_left = time - time_held; | |
let distace_travelled = time_held * time_left; | |
if distace_travelled > dist { | |
wins += 1; | |
} | |
} | |
println!("Part two: {}", wins); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment