Created
June 19, 2018 15:34
-
-
Save justyntemme/37fdcfeb4a10f23a0496686f486d10fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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