#Racket 97
Racket 97
97 points (87 +20 for two strings, -10 for sorting, no arrays)
(define(s n <)(string->number(list->string(sort(string->list(number->string n))<))))
This uses lists of chars so you need to give it a char comparison function like char<?
or char>?
. I feel this also passes as ungolfed since it's not much to do than add spaces and increase variable names. My old version is perhaps more honorable :)
Old version without strings:
110 points (120 bytes (utf-8) - 10 for allowing for changing sort order. It uses no strings and no arrays)
(define(S d <)(foldl(λ(x a)(+(* a 10)x))0(sort(let L((l'())(
d d))(if(= d 0)l(L(cons(modulo d 10)l)(quotient d 10))))<)))
Ungolfed:
(define (number-digit-sort number <)
(foldl (λ (x a) (+ (* a 10) x))
0
(sort (let loop ((acc '()) (number number))
(if (= number 0)
acc
(loop (cons (modulo number 10) acc)
(quotient number 10))))
<)))
I tested it with the 100,000th fibonacci number:
(number-digit-sort (fibonacci 100000) <)
;==> 1111... basically it's the digits:
; 1 2135 times
; 2 2149 times
; 3 2096 times
; 4 2023 times
; 5 2053 times
; 6 2051 times
; 7 2034 times
; 8 2131 times
; 9 2118 times
And the same in opposite order:
(number-digit-sort (fibonacci 100000) >)
; ==> 999... and the digest is
; 9 2118 times
; 8 2131 times
; 7 2034 times
; 6 2051 times
; 5 2053 times
; 4 2023 times
; 3 2096 times
; 2 2149 times
; 1 2135 times
; 0 2109 times