RosettaCodeData/Task/Next-highest-int-from-digits/Mathematica/next-highest-int-from-digits.math
2023-07-01 13:44:08 -04:00

8 lines
323 B
Text

ClearAll[NextHighestIntFromDigits]
NextHighestIntFromDigits[n_Integer?NonNegative]:=Module[{digs},
digs=IntegerDigits[n];
digs=FromDigits/@Permutations[digs];
digs=Select[digs,GreaterEqualThan[n]];
If[Length[digs]==1,First[digs],RankedMin[digs,2]]
]
NextHighestIntFromDigits/@{0,9,12,21,12453,738440,45072010,95322020}