Added lists->hash to lib.rkt.
This commit is contained in:
parent
9ea0885bbe
commit
f047ab3cb1
10
lib.rkt
10
lib.rkt
|
@ -20,6 +20,7 @@
|
|||
vector-grid-update
|
||||
lists->vectors
|
||||
vectors->lists
|
||||
lists->hash
|
||||
hash->vectors
|
||||
show-list-grid
|
||||
show-vector-grid
|
||||
|
@ -122,6 +123,15 @@
|
|||
(define (vectors->lists vector-grid)
|
||||
(map vector->list (vector->list vector-grid)))
|
||||
|
||||
;; lists->hash : list-grid -> hash-grid
|
||||
(define (lists->hash list-grid)
|
||||
(let ([width (length (first list-grid))]
|
||||
[length (length list-grid)])
|
||||
(for*/fold ([hash-grid (hash)])
|
||||
([x (in-range width)]
|
||||
[y (in-range length)])
|
||||
(hash-set hash-grid (cons x y) (list-ref (list-ref list-grid y) x)))))
|
||||
|
||||
;; hash->vectors : hash-grid -> number -> vector-grid
|
||||
;; Where the position is not in the hash-grid,
|
||||
;; the vector-grid takes on the default value.
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
#lang curly-fn racket
|
||||
|
||||
(require threading
|
||||
(only-in 2htdp/batch-io
|
||||
read-lines))
|
||||
|
||||
(define (source-input n)
|
||||
(let* ([filename (~a n #:min-width 2 #:align 'right #:left-pad-string "0")]
|
||||
[path (string-append "src/" filename ".rkt")])
|
||||
(read-lines path)))
|
||||
|
||||
(define srcs
|
||||
(~>> (range 1 11)
|
||||
(map (λ~>> source-input
|
||||
(filter non-empty-string?)))))
|
||||
|
||||
(define src-lengths (map length srcs))
|
||||
|
||||
(define src-widths
|
||||
(~>> srcs
|
||||
(apply append)
|
||||
(map string-length)
|
||||
(sort _ <=)))
|
||||
|
||||
(define src-widths-string
|
||||
(string-join (map number->string src-widths) ","))
|
Loading…
Reference in New Issue