mirror of
https://github.com/bertptrs/adventofcode.git
synced 2025-12-25 21:00:31 +01:00
Off by one
This commit is contained in:
@@ -54,7 +54,7 @@ fn ways(time: u64, distance: u64) -> u64 {
|
|||||||
while min < max {
|
while min < max {
|
||||||
let mid = min + (max - min) / 2;
|
let mid = min + (max - min) / 2;
|
||||||
|
|
||||||
if mid * (time - mid) < distance {
|
if mid * (time - mid) <= distance {
|
||||||
min = mid + 1;
|
min = mid + 1;
|
||||||
} else {
|
} else {
|
||||||
max = mid;
|
max = mid;
|
||||||
@@ -94,6 +94,13 @@ mod tests {
|
|||||||
|
|
||||||
const SAMPLE: &[u8] = include_bytes!("samples/06.txt");
|
const SAMPLE: &[u8] = include_bytes!("samples/06.txt");
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn individual_samples() {
|
||||||
|
assert_eq!(ways(7, 9), 4);
|
||||||
|
assert_eq!(ways(15, 40), 8);
|
||||||
|
assert_eq!(ways(30, 200), 9);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn sample_part1() {
|
fn sample_part1() {
|
||||||
assert_eq!(part1(SAMPLE).unwrap(), "288");
|
assert_eq!(part1(SAMPLE).unwrap(), "288");
|
||||||
|
|||||||
Reference in New Issue
Block a user