<?php
function isSequence3($num) {
if ($num < 123) return false;
$digits = str_split($num);
$seq = 1;
for($i=1; $i<count($digits); $i++) {
if ($digits[$i] == ($digits[$i - 1] + 1)) $seq++;
else $seq = 1;
}
return $seq > 2;
}
$sum = 0;
for ($n=1; $n<=10000; $n++) {
if (isSequence3($n)) $sum += $n;
}
printf("Sum: %d", $sum);
function isSeq3(int $number) : bool
{
$prevDigit = 0;
$seqLen = 0;
while ($number > 0) {
$digit = $number % 10;
if ($digit === $prevDigit - 1) {
$seqLen += 1;
} else {
$seqLen = 1;
}
if ($seqLen === 3) {
return true;
}
$number = intdiv($number, 10);
$prevDigit = $digit;
}
return false;
}