blob: 546a7c25d0324f2895bc7e9283c4e7b7bdbef88a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
; P11 (*) Modified run-length encoding.
; Modify the result of problem P10 in such a way that if an element has
; no duplicates it is simply copied into the result list. Only elements
; with duplicates are transferred as (N E) lists.
(use "p10.neb")
(func encode-modified (lst)
(map
(lambda (item)
(if (eq? 1 (length item))
(first item)
(list (length item) (first item))))
lst))
(func encode-squish (lst)
(map
(lambda (item)
(if (eq? 1 (first item))
(last item)
item))
lst))
(print (concat "from result of P09: " (->string (encode-modified (pack-dup a)))))
(print (concat "from result of P10: " (->string (encode-squish (encode (pack-dup a))))))
|