fork download
  1. # den510
  2. # Daily Programmer
  3. # Given an integer, find the next largest integer using ONLY the digits from the given integer.
  4. "1234\n1243\n234765\n19000".split().each do |line|
  5. permutations = line.split('').permutation(line.length).to_a
  6. largest, number = ('9'*line.length).to_i, line.to_i
  7. permutations.each { |perm| largest = perm.join('').to_i if perm.join('').to_i > number and perm.join('').to_i < largest}
  8. puts number.to_s + ' >> ' + largest.to_s
  9. end
Success #stdin #stdout 0s 28688KB
stdin
Standard input is empty
stdout
1234 >> 1243
1243 >> 1324
234765 >> 235467
19000 >> 90001