Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
14
Task/Run-length-encoding/Ol/run-length-encoding-1.ol
Normal file
14
Task/Run-length-encoding/Ol/run-length-encoding-1.ol
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
(define (RLE str)
|
||||
(define iter (string->list str))
|
||||
(let loop ((iter iter) (chr (car iter)) (n 0) (rle '()))
|
||||
(cond
|
||||
((null? iter)
|
||||
(reverse (cons (cons n chr) rle)))
|
||||
((char=? chr (car iter))
|
||||
(loop (cdr iter) chr (+ n 1) rle))
|
||||
(else
|
||||
(loop (cdr iter) (car iter) 1 (cons (cons n chr) rle))))))
|
||||
|
||||
(define (decode rle)
|
||||
(apply string-append (map (lambda (p)
|
||||
(make-string (car p) (cdr p))) rle)))
|
||||
8
Task/Run-length-encoding/Ol/run-length-encoding-2.ol
Normal file
8
Task/Run-length-encoding/Ol/run-length-encoding-2.ol
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
(define str "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")
|
||||
(print str)
|
||||
|
||||
(define rle (RLE str))
|
||||
(for-each (lambda (pair)
|
||||
(print (car pair) " : " (string (cdr pair))))
|
||||
rle)
|
||||
(print (decode rle))
|
||||
Loading…
Add table
Add a link
Reference in a new issue