Skip to content

Instantly share code, notes, and snippets.

@ville6000
Last active October 1, 2015 15:08
Show Gist options
  • Save ville6000/2013072 to your computer and use it in GitHub Desktop.
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.
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