You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

44 lines
683 B

<?php
$in = file("input.txt");
foreach ($in as &$inv) {
$inv = (int)trim($inv);
}
$ans = array();
//Add Zero for the source
array_push($in,0);
sort($in);
//Add +3 for the source device
array_push($in,end($in) + 3);
$x = 0;
while ($x < count($in) - 1) {
array_push($ans, $in[$x + 1] - $in[$x]);
$x++;
}
$data = implode($ans);
$data = explode("3", $data);
$data = array_filter($data);
$data_final = array();
foreach ($data as $t) {
if (strlen($t) > 1) {
array_push($data_final, strlen($t));
}
}
sort($data_final);
$a = array(
2=>2,
3=>4,
4=>7,
);
foreach ($data_final as &$t) {
$t = $a[$t];
}
echo array_product($data_final). "\n";