This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e5fecb
commit c2c43d4
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#lang typed/racket | ||
(define (freq l) | ||
(define h (make-vector 10 0)) | ||
(define tot | ||
(for/fold ([tot 0]) ([e (in-list l)]) | ||
(dict-update! h e add1) | ||
(add1 tot))) | ||
(for/list ([(e c) (in-dict h)]) | ||
(cons e (/ c tot)))) | ||
(define nums->digits | ||
(curry map | ||
(compose string->number | ||
string | ||
(λ (x) (string-ref x 0)) | ||
number->string | ||
(λ (x) (if (x . < . 0) (- x) x))))) | ||
(define (sk l) | ||
(freq (nums->digits l))) | ||
(define (sort-em l) | ||
(sort l >= #:key cdr)) | ||
|
||
(equal? | ||
(sort-em | ||
(sk (list 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 0.10 | ||
11 12 13 -14 15 16 17 18 19 | ||
21 -22 23 24 25 26 27 28 | ||
31 32 -33 34 35 36 37 | ||
41 42 43 44 45 46 | ||
51 -52 54 54 55 | ||
61 62 -63 64 | ||
71 -72 73 | ||
81 82 | ||
91))) | ||
(for/list ([i (in-range 10)]) | ||
(cons i | ||
(/ (- 10 i) | ||
(+ 10 9 8 7 6 5 4 3 2 1))))) |