New Numbers
A number is new if its digits are not a permutation of a smaller number. For instance, 789 is a new number because its permutations (879, 798, 897, 978, and 987) are all larger than it is. However, 645 is not a new number since 456 and 465 are smaller than it.
Write a function that takes an integer and returns true if it is a new number and false otherwise.
Examples
(new-number? 789) ;=> true
(new-number? 645) ;=> false
(new-number? 444) ;=> true (it's permutations are not smaller than it)
Bonus: You may find a clever way to write new-number?
. In addition to that implementation, implement it in such a way that the definition (no permutations are smaller) is clear from the code.
Thanks to this site for the problem idea, where it is rated Very Hard in Ruby. The problem has been modified.
Please submit your solutions as comments on this gist.
To subscribe: https://purelyfunctional.tv/newsletter/
Oooops, after reading all the judicious comments, I realize the permutations do matter specifically because of the position of zero when it appears. So any number with a zero in it must not be a new-number unless it has a single non-zero digit, correct?
Which would make 203, 1230, 100003 not new-numbers, but 10, 50000 would be.
Another way to interpret this would be to consider permutations with leading zeros not numbers, and therefore not relevant, in which case
102 and 1230 would be new-numbers, but I chose instead to allow them, i.e. 012 is number 12 (which the repl allows) and therefore 102 is not a new-number.
I revised my solution accordingly.