033 Digit cancelling fractions.sf 593 B

123456789101112131415161718192021222324
  1. #!/usr/bin/ruby
  2. # Author: Daniel "Trizen" Șuteu
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
  6. # If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
  7. # https://projecteuler.net/problem=33
  8. # Runtime: 0.147s
  9. var prod = 1
  10. [1..10, 1..10, 1..10].cartesian { |i,j,k|
  11. next if (i == j)
  12. if ((10*i + j) / (10*j + k) == i/k) {
  13. prod *= i/k
  14. }
  15. }
  16. say prod.de