Skip to content

Instantly share code, notes, and snippets.

@justyntemme
Created June 19, 2018 15:55
Show Gist options
  • Save justyntemme/b505d02765ec273e405ba70fa52d640f to your computer and use it in GitHub Desktop.
Save justyntemme/b505d02765ec273e405ba70fa52d640f to your computer and use it in GitHub Desktop.
<?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