Skip to content

Commit a0c4dec

Browse files
committed
2023.06
1 parent a0c17b4 commit a0c4dec

File tree

11 files changed

+106
-5
lines changed

11 files changed

+106
-5
lines changed

php/2023/01/01.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
$start = microtime(true);
4+
5+
36
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
47
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
58

@@ -13,4 +16,7 @@
1316
$sum += (int)$num;
1417
}
1518

16-
echo $sum, "\n";
19+
echo $sum, "\n";
20+
21+
echo microtime(true) - $start;
22+
echo "\n";

php/2023/01/02.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
<?php
22

3+
$start = microtime(true);
4+
35
#$lines = file('example2.txt', FILE_IGNORE_NEW_LINES);
46
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
57

68
$sum = 0;
79
foreach ($lines as $line) {
8-
echo $line, " > ";
10+
# echo $line, " > ";
911
$first = findDigitForward($line);
1012
$last = findDigitBackward($line);
1113
$num = $first . $last;
12-
echo $num, "\n";
14+
# echo $num, "\n";
1315
$sum += (int)$num;
1416
}
1517

1618
echo $sum, "\n";
1719

20+
echo microtime(true) - $start;
21+
echo "\n";
1822

1923

2024

@@ -60,8 +64,8 @@ function findDigitForward(string $line): int
6064
function findDigitBackward(string $line): int
6165
{
6266
for ($i = strlen($line); $i > 0; $i--) {
63-
echo $substr = substr($line, 0, $i);
64-
echo "\n";
67+
$substr = substr($line, 0, $i);
68+
#echo "\n";
6569
if (str_ends_with($substr, 'one') || str_ends_with($substr, '1')) {
6670
return 1;
6771
}

php/2023/02/01.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Year2023\Day02;
44

5+
$start = microtime(true);
6+
57
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
68
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
79

@@ -80,3 +82,6 @@ public function isValid(int $maxRed, int $maxGreen, int $maxBlue): bool
8082

8183
echo $sum, "\n";
8284
echo $totalPower, "\n";
85+
86+
echo microtime(true) - $start;
87+
echo "\n";

php/2023/03/01.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Year2023\Day03;
44

5+
$start = microtime(true);
6+
57
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
68
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
79

@@ -50,6 +52,10 @@
5052

5153
echo $sum, "\n";
5254

55+
echo microtime(true) - $start;
56+
echo "\n";
57+
58+
5359
# go round symbol and find digit
5460

5561
# go left and right from that digit and find the whole number

php/2023/03/02.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Year2023\Day03;
44

5+
$start = microtime(true);
6+
57
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
68
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
79

@@ -55,6 +57,9 @@
5557

5658
echo $sum, "\n";
5759

60+
echo microtime(true) - $start;
61+
echo "\n";
62+
5863
# go round symbol and find digit
5964

6065
# go left and right from that digit and find the whole number

php/2023/04/01.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Year2023\Day04;
44

5+
$start = microtime(true);
6+
57
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
68
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
79

@@ -58,3 +60,5 @@ public function getNumberOfMatches(): int
5860

5961
echo array_sum($counts), "\n";
6062

63+
echo microtime(true) - $start;
64+
echo "\n";

php/2023/05/01.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Year2023\Day05\Part1;
44

5+
$start = microtime(true);
6+
57
#$input = file_get_contents('example.txt');
68
$input = file_get_contents('input.txt');
79

@@ -75,3 +77,5 @@ public function convert(int $in): ?int
7577
echo "\n";
7678

7779

80+
echo microtime(true) - $start;
81+
echo "\n";

php/2023/06/01.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
namespace Year2023\Day06;
4+
5+
$start = microtime(true);
6+
7+
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
8+
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
9+
10+
$times = preg_split("/\s+/", $lines[0]);
11+
$records = preg_split("/\s+/", $lines[1]);
12+
13+
array_shift($times);
14+
array_shift($records);
15+
$waysToWin = [];
16+
17+
#print_r($records);
18+
19+
foreach ($times as $gameId => $time) {
20+
$wins = 0;
21+
# echo $record = $records[$gameId];
22+
$record = $records[$gameId];
23+
for ($msHold = 1; $msHold < $time; $msHold++) {
24+
if ($msHold * ($time - $msHold) > $record) {
25+
++$wins;
26+
}
27+
}
28+
$waysToWin[$gameId] = $wins;
29+
}
30+
31+
#print_r($waysToWin);
32+
33+
echo array_product($waysToWin);
34+
echo "\n";
35+
36+
echo microtime(true) - $start;
37+
echo "\n";
38+

php/2023/06/02.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Year2023\Day06;
4+
5+
$start = microtime(true);
6+
7+
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
8+
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
9+
10+
$time = preg_split("/:\s+/", $lines[0])[1];
11+
$record = preg_split("/:\s+/", $lines[1])[1];
12+
13+
$time = preg_replace("/\s+/", "", $time);
14+
$record = preg_replace("/\s+/", "", $record);
15+
16+
echo $time, " ", $record, "\n";
17+
18+
$wins = 0;
19+
for ($msHold = 1; $msHold < $time; $msHold++) {
20+
if ($msHold * ($time - $msHold) > $record) {
21+
++$wins;
22+
}
23+
}
24+
25+
echo $wins, "\n";
26+
27+
echo microtime(true) - $start;
28+
echo "\n";
29+

php/2023/06/example.txt

65 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy