Created
June 19, 2018 15:55
-
-
Save justyntemme/b505d02765ec273e405ba70fa52d640f 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 = [[]]; | |
echo 'strlen of input' . strlen($input); | |
echo '\n'; | |
for ($i = 0; $i< strlen($input); $i++) { | |
echo $input[$i]; | |
if ($input[$i] == $input[$i++]) { | |
if ($compressed[$i][1] == $input[$i]) { | |
$compressed[$i][0]++; | |
$input = substr($input, $i); | |
} else { | |
$compressed[$i][1] = $input[$i]; | |
$compressed[$i][0] = 1; | |
$input = substr($input, $i); | |
} | |
} | |
} | |
$RC = ""; | |
echo '\n'; | |
echo 'count of compressed' . count($compressed); | |
for ($i = 0; $i < count($compressed); $i++) { | |
echo $compressed[$i][1]; | |
echo $compressed[$i][0]; | |
$RC = $RC . $compressed[$i]['1'] . $compressed[$i]['0']; | |
} | |
echo '\n'; | |
echo 'RC' . $RC; | |
} | |
main($argv[1]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment