summary refs log tree commit diff homepage
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2023-12-12 11:38:01 -0500
committerJune McEnroe <june@causal.agency>2023-12-12 11:38:01 -0500
commitfe22e05b9db4aa448cf38b22aede84137f8ebee5 (patch)
tree4817a5e559976024164c819373f1f67b5b728afd
parentSolve day 6 part 1 (diff)
downloadaoc-fe22e05b9db4aa448cf38b22aede84137f8ebee5.tar.gz
aoc-fe22e05b9db4aa448cf38b22aede84137f8ebee5.zip
Solve day 6 part 2
-rw-r--r--2023/day06.pl13
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";