Skip to content

Instantly share code, notes, and snippets.

@dbhalling
Created August 25, 2018 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbhalling/15a04d589a5ecc848cd75a4ca83fb941 to your computer and use it in GitHub Desktop.
Save dbhalling/15a04d589a5ecc848cd75a4ca83fb941 to your computer and use it in GitHub Desktop.
Codility34 ChocolatesByNumbers
#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