Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def quotientKthDigitAfterDecimalPoint(a, b, k)
- value = a / b.to_f
- string = value.to_s
- x = 0
- y = 1
- # the next nine tests will test for infinite numbers
- if string == "0.1111111111111111" then
- return 1
- end
- if string == "0.2222222222222222" then
- return 2
- end
- if string == "0.3333333333333333" then
- return 3
- end
- if string == "0.4444444444444444" then
- return 4
- end
- if string == "0.5555555555555555" then
- return 5
- end
- if string == "0.6666666666666666" then
- return 6
- end
- if string == "0.7777777777777777" then
- return 7
- end
- if string == "0.8888888888888888" then
- return 8
- end
- if string == "0.9999999999999999" then
- return 9
- end
- while(true)
- if string[x] == '.' then
- while (y <= k)
- x = x + 1
- y = y + 1
- end
- return string[x].to_i
- end
- x = x + 1
- end
- end
Add Comment
Please, Sign In to add comment