-
Notifications
You must be signed in to change notification settings - Fork 0
/
day10.php
46 lines (44 loc) · 820 Bytes
/
day10.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
<?php
$input = '3113322113';
$output = '';
$rounds = 50;
for($i = 0; $i < $rounds; $i++)
{
if($i == 0)
{
$output = process($input);
} else
{
$output = process($output);
}
}
echo strlen($output) . ' ' . $output . '<br>';
function process($input)
{
$out = '';
$arr = str_split($input);
$length = count($arr);
for($i = 0; $i < $length; $i++)
{
if($arr[$i] != $arr[$i+1]) {
$out .= '1' . $arr[$i];
}
else if($arr[$i+1] != $arr[$i+2]) {
$out .= '2' . $arr[$i];
$i = $i + 1;
}
else if($arr[$i+2] != $arr[$i+3]) {
$out .= '3' . $arr[$i];
$i = $i + 2;
}
else if($arr[$i+3] != $arr[$i+4]) {
$out .= '4' . $arr[$i];
$i = $i + 3;
}
else if($arr[$i+4] != $arr[$i+5]) {
$out .= '5' . $arr[$i];
$i = $i + 4;
}
}
return $out;
}