Created
October 1, 2012 13:22
-
-
Save jeremykendall/3811768 to your computer and use it in GitHub Desktop.
PHP solution for http://www.reddit.com/r/dailyprogrammer/comments/zx98u/9152012_challenge_98_intermediate_multiple_cycling/
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 multiple_cycle($limit, $numbers) | |
{ | |
$count = 0; | |
$index = 0; | |
$numbersLength = count($numbers); | |
for ($i = 1; $i <= $limit; $i++) { | |
if ($i % $numbers[$index] == 0) { | |
++$count; | |
++$index; | |
if ($index >= $numbersLength) { | |
$index = 0; | |
} | |
} | |
} | |
return $count; | |
} | |
var_dump(multiple_cycle(1000000000, array(5395, 7168, 2367, 9999, 3))); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Good first try, and you should get the right answer for smaller values of
$limit
. The question asks for the number of cycles required to reach$limit
using multiples of the values in$numbers
, right? Instead of counting up from 1 to$limit
by 1, try incrementing by the values in$numbers
instead.