Skip to content

Instantly share code, notes, and snippets.

@justyntemme
Created June 19, 2018 15:34
Show Gist options
  • Save justyntemme/37fdcfeb4a10f23a0496686f486d10fd to your computer and use it in GitHub Desktop.
Save justyntemme/37fdcfeb4a10f23a0496686f486d10fd to your computer and use it in GitHub Desktop.
<?php
function main($input)
{
$compressed = Array(Array());
for ($i = 0; i< strlen($input); $i++) {
echo $input[i];
if ($input[$i] == $input[$i+1]) {
if ($compressed[$i] == $input[$i]) {
$compressed[$i][0]++;
$input = substr($input, $i);
} else {
$compressed[$i] = $input[i];
$compressed[$i][0]++;
$input = substr($input, $i);
}
}
}
$RC = "";
echo count($compressed);
for ($i = 0; i < count($compressed); $i++) {
$RC = $RC . $compressed[$i] . $compressed[$i][0];
}
echo $RC;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment