024 Lexicographic permutations.sf 356 B

123456789101112131415161718192021
  1. #!/usr/bin/ruby
  2. # Author: Trizen
  3. # https://github.com/trizen
  4. # What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?
  5. # https://projecteuler.net/problem=24
  6. # Runtime: 5.387s (previously: 7.307s)
  7. var i = 0
  8. var arr = @(0..9)
  9. arr.permutations { |*p|
  10. if (++i == 1e6) {
  11. say p.join
  12. break
  13. }
  14. }