Skip to content

Instantly share code, notes, and snippets.

@bhill77
Created September 27, 2017 07:37
Show Gist options
  • Save bhill77/0ce915cd67ced58a248842e54d3f53b1 to your computer and use it in GitHub Desktop.
Save bhill77/0ce915cd67ced58a248842e54d3f53b1 to your computer and use it in GitHub Desktop.
jawaban
<?php
function munculSeklali($string)
{
$arr = str_split($string);
foreach ($arr as $key => $val) {
$tmp[$val] = isset($tmp[$val]) ? false : true;
}
$out = array_filter($tmp);
var_dump(array_keys($out));
}
<?php
function pesan_rahasia($message)
{
$messageLength = strlen($message);
$K = ceil(sqrt($messageLength));
$squareLength = pow($K, 2);
$newMessage = str_pad($message, $squareLength, '*');
$arrMessage = str_split($newMessage);
$chunk = array_chunk($arrMessage, $K);
$trans = array_map(null, ...$chunk);
foreach ($trans as $key => $value) {
$out[$key] = array_reverse($value);
$out[$key] = implode('', $out[$key]);
}
$out = implode('', $out);
$out = str_replace('*', '', $out);
echo $out . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment