-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathphpTest.php
More file actions
61 lines (49 loc) · 1.22 KB
/
phpTest.php
File metadata and controls
61 lines (49 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
function solution($R) {
// write your code in PHP7.0
$h = 1;
$v = 0;
$tiles = 0;
$cC = $cR = 0;
$rowX = array();
$rC = 0;
$tilesScanned = array();
for($i=0;$i<sizeof($R);$i++) {
$rowContent = str_split($R[$i], 1);
$xPos = strpos($R[$i], 'X');
$rowX[] = $xPos;
if($h == 1 && $rC == 0) {
foreach($rowContent as $j => $tile) {
if($tile == 'X') break;
$tilesScanned[] = $i.$j;
}
$h = 0;
$v = 1;
}
if($v == 1 && $rC == 0) {
if($R[$i][$j] == "X") {
$v = 0;
$h = 1;
$cR = $i;
$rC = 1;
} else {
$tilesScanned[] = $i.$j;
}
}
if($h == 1 && $rC == 1) {
$xPos = strpos($R[$i][$cR], 'X');
if($cC > $xPos) {
$tiles += $xPos;
$h = 0;
$v = 1;
}
}
if($v == 1 && $rC == 1) {
$tiles++;
}
}
return sizeof($tilesScanned);
}
$A = ['....X..', 'X......', '.....X.', '.......'];
$result = solution($A);
print_r($result);