diff options
Diffstat (limited to 'p99/p11.neb')
| -rw-r--r-- | p99/p11.neb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/p99/p11.neb b/p99/p11.neb new file mode 100644 index 0000000..546a7c2 --- /dev/null +++ b/p99/p11.neb @@ -0,0 +1,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)))))) |
