026 Reciprocal cycles.sf 398 B

123456789101112131415161718192021222324252627
  1. #!/usr/bin/ruby
  2. # Daniel "Trizen" Șuteu
  3. # Edit: 25 July 2021
  4. # https://github.com/trizen
  5. # Find the value of d < 1000 for which 1/d contains the longest recurring cycle in its decimal fraction part.
  6. # https://projecteuler.net/problem=26
  7. # Runtime: 0.196s
  8. var d = 1
  9. var max = 0
  10. for n in (2..1000) {
  11. var r = znorder(10, n)
  12. if (r > max) {
  13. max = r
  14. d = n
  15. }
  16. }
  17. say d