Day 2 solution.

This commit is contained in:
Dan Chadwick
2024-11-24 10:03:05 -05:00
parent 5e5c726ebb
commit f39448a54e
4 changed files with 1113 additions and 12 deletions

View File

@@ -8,15 +8,12 @@
* Runtime: ~0.158ms
*/
function day1solution1() {
$start_time = microtime(true);
$instructions = file_get_contents('./2015/inputs/day1.txt');
$up_floors = substr_count($instructions, "(");
$down_floors = substr_count($instructions, ")");
$total = $up_floors - $down_floors;
echo "The answer is $total\n";
$end_time = microtime(true);
$execution_time = ($end_time - $start_time);
echo $execution_time * 1000 . "\n";
return $total;
}
/*
@@ -25,7 +22,6 @@ function day1solution1() {
* Runtime: ~.33ms
*/
function day1solution1b() {
$start_time = microtime(true);
$instructions = file_get_contents('./2015/inputs/day1.txt');
$chars = str_split($instructions);
$position = 1;
@@ -42,8 +38,6 @@ function day1solution1b() {
$position++;
}
};
echo "The position is $position\n";
$end_time = microtime(true);
$execution_time = ($end_time - $start_time);
echo $execution_time * 1000 . "\n";
return $position;
}