Look And Say Sequence – PHP 7.4

<?php

$num = "011223333";
$res = preg_replace_callback(
    '/(\d)\1*/', fn($match) => strlen($match[0]) . $match[0][0], $num
);

var_dump($res); //102243

Leave a Reply