Skip to content

Commit ad49bbf

Browse files
day6
1 parent 89119ec commit ad49bbf

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Time: 53 89 76 98
2+
Distance: 313 1090 1214 1201
Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,32 @@
1-
use std::fs;
2-
3-
pub fn day6_part1(input: &str) -> usize {
4-
input.lines().count()
1+
pub fn day6_part1() -> usize {
2+
[(53, 313), (89, 1090), (76, 1214), (98, 1201)]
3+
.iter()
4+
.map(|race| {
5+
let mut num = 0;
6+
for t in 0..=race.0 {
7+
if race.1 < (race.0 - t) * t {
8+
num += 1;
9+
}
10+
}
11+
num
12+
})
13+
.product()
514
}
615

7-
pub fn day6_part2(input: &str) -> usize {
8-
input.lines().count()
16+
pub fn day6_part2() -> usize {
17+
let time = 53897698;
18+
let distance: u64 = 313109012141201;
19+
20+
let mut num = 0;
21+
for t in 0..=time {
22+
if distance < (time - t) * t {
23+
num += 1;
24+
}
25+
}
26+
num
927
}
1028

1129
fn main() {
12-
let input = fs::read_to_string("input/2023/day6.txt").unwrap();
13-
println!("Day 6, Part 1: {}", day6_part1(&input));
14-
println!("Day 6, Part 2: {}", day6_part2(&input));
30+
println!("Day 6, Part 1: {}", day6_part1());
31+
println!("Day 6, Part 2: {}", day6_part2());
1532
}

0 commit comments

Comments
 (0)