21 lines
469 B
Text
21 lines
469 B
Text
func next_from_digits(n, b = 10) {
|
|
|
|
var a = n.digits(b).flip
|
|
|
|
while (a.next_permutation) {
|
|
with (a.flip.digits2num(b)) { |t|
|
|
return t if (t > n)
|
|
}
|
|
}
|
|
|
|
return 0
|
|
}
|
|
|
|
say 'Next largest integer able to be made from these digits, or zero if no larger exists:'
|
|
|
|
for n in (
|
|
0, 9, 12, 21, 12453, 738440, 3345333, 45072010,
|
|
95322020, 982765431, 9589776899767587796600,
|
|
) {
|
|
printf("%30s -> %s\n", n, next_from_digits(n))
|
|
}
|