Skip to content

Instantly share code, notes, and snippets.

@rtacconi
Last active August 29, 2015 14:17
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 rtacconi/08bbe7c6d8536e23d6b1 to your computer and use it in GitHub Desktop.
Save rtacconi/08bbe7c6d8536e23d6b1 to your computer and use it in GitHub Desktop.
Codility coding challenge
# 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