Created
August 25, 2018 08:02
-
-
Save dbhalling/15a04d589a5ecc848cd75a4ca83fb941 to your computer and use it in GitHub Desktop.
Codility34 ChocolatesByNumbers
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
#Codility34 ChocolatesByNumbers | |
n = 10 | |
m = 4 | |
def solution(n, m) | |
step= 0 | |
stepArray = [0] | |
check = false | |
while check == false | |
step += m | |
if step >= n | |
step = step.modulo(n) | |
end | |
puts step | |
if stepArray.include?(step) | |
check = true | |
else | |
stepArray.push(step) | |
end | |
end | |
p stepArray | |
p stepArray.sort | |
return stepArray.count | |
end | |
puts "The number of chocolates you will eat is #{solution(n, m)}" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment