Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Letter-frequency/Scheme/letter-frequency-1.ss
Normal file
21
Task/Letter-frequency/Scheme/letter-frequency-1.ss
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(use-modules (ice-9 format))
|
||||
|
||||
(define (char-freq port table)
|
||||
(if
|
||||
(eof-object? (peek-char port))
|
||||
table
|
||||
(char-freq port (add-char (read-char port) table))))
|
||||
|
||||
(define (add-char char table)
|
||||
(cond
|
||||
((null? table) (list (list char 1)))
|
||||
((eq? (caar table) char) (cons (list char (+ (cadar table) 1)) (cdr table)))
|
||||
(#t (cons (car table) (add-char char (cdr table))))))
|
||||
|
||||
(define (format-table table)
|
||||
(for-each (lambda (t) (format #t "~10s~10d~%" (car t) (cadr t))) table))
|
||||
|
||||
(define (print-freq filename)
|
||||
(format-table (char-freq (open-input-file filename) '())))
|
||||
|
||||
(print-freq "letter-frequency.scm")
|
||||
8
Task/Letter-frequency/Scheme/letter-frequency-2.ss
Normal file
8
Task/Letter-frequency/Scheme/letter-frequency-2.ss
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(with-input-from-string "foobar"
|
||||
(lambda ()
|
||||
(port-fold (lambda (x s)
|
||||
(alist-update x
|
||||
(add1 (alist-ref x s eq? 0))
|
||||
s))
|
||||
'()
|
||||
read-char)))
|
||||
Loading…
Add table
Add a link
Reference in a new issue