Last active
August 29, 2015 14:17
-
-
Save rtacconi/08bbe7c6d8536e23d6b1 to your computer and use it in GitHub Desktop.
Codility coding challenge
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
# https://codility.com/demo/results/demoKSSE8R-5B3/ | |
# A small frog wants to get to the other side of the road | |
# two solutions, this one gets 33% of scores: | |
def solution(x, y, d) | |
y % d > 0 ? ((y - x) / d) + 1 : (y - x) / d | |
end | |
# this gets 100% scores: | |
def solution(x, y, d) | |
dis = y-x | |
(dis/d.to_f).ceil | |
end | |
# d should not be zero otherwise you will get FloatDomainError: Infinity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment