Skip to content

Instantly share code, notes, and snippets.

@barakpinchovski
Last active September 10, 2019 07:24
Show Gist options
  • Save barakpinchovski/547d73e3c905d7aebba515ec838ecd90 to your computer and use it in GitHub Desktop.
Save barakpinchovski/547d73e3c905d7aebba515ec838ecd90 to your computer and use it in GitHub Desktop.
<?php
$s = 'kmretasscityylpdhuwjirnqimlkcgxubxmsxpypgzxtenweirknjtasxtvxemtwxuarabssvqdnktqadhyktagjxoanknhgilnm';
$n = 736778906400;
echo repeatedString($s, $n);
function repeatedString($s, $n) {
Define('CHAR', 'a');
if (!gettype($n) === 'integer' || !gettype($s) === 'string' || !$s || $n <= 0) {
return 0;
}
if (!strcasecmp($s, CHAR)) {
return $n;
}
$len = strlen($s);
$occurrences = substr_count($s, CHAR);
$occurrences *= floor($n / $len);
$occurrences += substr_count(substr($s, 0, $n % $len), CHAR);
return $occurrences;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment