-
Notifications
You must be signed in to change notification settings - Fork 0
/
d25_1.php
75 lines (65 loc) · 1.53 KB
/
d25_1.php
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
$tape = [];
$cur = 0;
$state = 'A';
for ($i = 0; $i < 12861455; $i++) {
if (!isset($tape[$cur])) $tape[$cur] = 0;
switch ($state) {
case 'A':
if ($tape[$cur] === 0) {
$tape[$cur] = 1;
$cur++;
} else {
$tape[$cur] = 0;
$cur--;
}
$state = 'B';
break;
case 'B':
if ($tape[$cur] === 0) {
$tape[$cur] = 1;
$cur--;
$state = 'C';
} else {
$tape[$cur] = 0;
$cur++;
$state = 'E';
}
break;
case 'C':
if ($tape[$cur] === 0) {
$tape[$cur] = 1;
$cur++;
$state = 'E';
} else {
$tape[$cur] = 0;
$cur--;
$state = 'D';
}
break;
case 'D':
$tape[$cur] = 1;
$cur--;
$state = 'A';
break;
case 'E':
if ($tape[$cur] === 0) {
$state = 'A';
} else {
$state = 'F';
}
$tape[$cur] = 0;
$cur++;
break;
case 'F':
if ($tape[$cur] === 0) {
$state = 'E';
} else {
$state = 'A';
}
$tape[$cur] = 1;
$cur++;
break;
}
}
var_dump(array_count_values($tape)[1]);