Skip to content

Commit a0c24a4

Browse files
committed
2024.04.2
1 parent a0c249e commit a0c24a4

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

php/2024/04/02.php

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
$start = microtime(true);
4+
5+
6+
#$lines = file('example.txt', FILE_IGNORE_NEW_LINES);
7+
$lines = file('input.txt', FILE_IGNORE_NEW_LINES);
8+
9+
10+
$map = [];
11+
foreach ($lines as $line) {
12+
$map[] = str_split($line);
13+
}
14+
15+
$variants = [
16+
[
17+
['find' => 'M', 'col' => -1, 'row' => -1],
18+
['find' => 'M', 'col' => -1, 'row' => 1],
19+
['find' => 'S', 'col' => 1, 'row' => -1],
20+
['find' => 'S', 'col' => 1, 'row' => 1],
21+
],
22+
[
23+
['find' => 'M', 'col' => -1, 'row' => -1],
24+
['find' => 'S', 'col' => -1, 'row' => 1],
25+
['find' => 'M', 'col' => 1, 'row' => -1],
26+
['find' => 'S', 'col' => 1, 'row' => 1],
27+
],
28+
[
29+
['find' => 'S', 'col' => -1, 'row' => -1],
30+
['find' => 'S', 'col' => -1, 'row' => 1],
31+
['find' => 'M', 'col' => 1, 'row' => -1],
32+
['find' => 'M', 'col' => 1, 'row' => 1],
33+
],
34+
[
35+
['find' => 'S', 'col' => -1, 'row' => -1],
36+
['find' => 'M', 'col' => -1, 'row' => 1],
37+
['find' => 'S', 'col' => 1, 'row' => -1],
38+
['find' => 'M', 'col' => 1, 'row' => 1],
39+
],
40+
];
41+
42+
43+
$count = 0;
44+
foreach ($map as $rowNum => $row) {
45+
foreach ($row as $colNum => $char) {
46+
if ('A' !== $char) {
47+
continue;
48+
}
49+
foreach ($variants as $variant) {
50+
foreach ($variant as $target) {
51+
$searchCol = $colNum + $target['col'];
52+
$searchRow = $rowNum + $target['row'];
53+
if (!isset($map[$searchRow][$searchCol]) || $map[$searchRow][$searchCol] !== $target['find']) {
54+
continue 2;
55+
}
56+
}
57+
++$count;
58+
break;
59+
}
60+
}
61+
}
62+
63+
64+
echo $count, "\n";
65+
66+
echo microtime(true) - $start;
67+
echo "\n";

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