Created
September 27, 2017 07:37
-
-
Save bhill77/0ce915cd67ced58a248842e54d3f53b1 to your computer and use it in GitHub Desktop.
jawaban
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 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)); | |
} |
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 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