052 Permuted multiples -- v2.sf 397 B

1234567891011121314151617181920
  1. #!/usr/bin/ruby
  2. # Author: Trizen
  3. # Date: 19 April 2023
  4. # 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: 2.483s
  8. for x in (1..Inf) {
  9. var t = Str(2*x).sort
  10. if (t == Str(3*x).sort && [4,5,6].all {|k| Str(k*x).sort == t }) {
  11. say x
  12. break
  13. }
  14. }