052 Permuted multiples.sf 441 B

123456789101112131415161718192021
  1. #!/usr/bin/ruby
  2. # Author: Trizen
  3. # License: GPLv3
  4. # Website: https://github.com/trizen
  5. # Find the smallest positive integer, x, such that 2x, 3x, 4x, 5x, and 6x, contain the same digits.
  6. # https://projecteuler.net/problem=52
  7. # Runtime: 8.214s (previously: 9.650s)
  8. var x = 1
  9. loop {
  10. if ([String(2*x), String(3*x), String(4*x), String(5*x), String(6*x)].map{.sort}.join ~~ /^(\d+)\1{4}$/) {
  11. say x
  12. break
  13. }
  14. ++x
  15. }