Last active
October 1, 2015 15:08
-
-
Save ville6000/2013072 to your computer and use it in GitHub Desktop.
Given a number, find the next higher number that uses the same set of digits. For instance, given the number 38276, the next higher number that uses the digits 2 3 6 7 8 is 38627.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def next_permutation(value) | |
values = value.to_s(10).split(//).sort | |
newValue = value + 1 | |
while false == newValue.to_s(10).split(//).sort.eql?(values) | |
newValue = newValue + 1 | |
end | |
return newValue | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment