diff options
Diffstat (limited to '')
-rw-r--r-- | 2023/day06.pl | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/2023/day06.pl b/2023/day06.pl index 92dd798..723ae89 100644 --- a/2023/day06.pl +++ b/2023/day06.pl @@ -6,15 +6,18 @@ while (<>) { @times = split(/ +/) if s/^Time: +//; @dists = split(/ +/) if s/^Distance: +//; } -my $ways = 1; -for (my $race = 0; $race < scalar(@times); $race++) { - my $time = $times[$race]; - my $dist = $dists[$race]; +sub wins { + my ($time, $dist) = @_; my $wins = 0; for my $hold (1 .. $time - 1) { my $travel = $hold * ($time - $hold); $wins++ if $travel > $dist; } - $ways *= $wins; + $wins; +} +my $ways = 1; +for (my $race = 0; $race < scalar(@times); $race++) { + $ways *= wins($times[$race], $dists[$race]); } print $ways, "\n"; +print wins(int(join("", @times)), int(join("", @dists))), "\n"; |