Data update

This commit is contained in:
Ingy döt Net 2024-10-16 18:07:41 -07:00
parent 81fd053722
commit 52a6ef48dd
10248 changed files with 63654 additions and 6775 deletions

View file

@ -0,0 +1,21 @@
H
,p
g/\([a-zA-Z]\)\1\1\1\1\1\1\1\1/s//9\1/g
g/\([a-zA-Z]\)\1\1\1\1\1\1\1/s//8\1/g
g/\([a-zA-Z]\)\1\1\1\1\1\1/s//7\1/g
g/\([a-zA-Z]\)\1\1\1\1\1/s//6\1/g
g/\([a-zA-Z]\)\1\1\1\1/s//5\1/g
g/\([a-zA-Z]\)\1\1\1/s//4\1/g
g/\([a-zA-Z]\)\1\1/s//3\1/g
g/\([a-zA-Z]\)\1/s//2\1/g
,p
g/9\([a-zA-Z]\)/s//\1\1\1\1\1\1\1\1\1/g
g/8\([a-zA-Z]\)/s//\1\1\1\1\1\1\1\1/g
g/7\([a-zA-Z]\)/s//\1\1\1\1\1\1\1/g
g/6\([a-zA-Z]\)/s//\1\1\1\1\1\1/g
g/5\([a-zA-Z]\)/s//\1\1\1\1\1/g
g/4\([a-zA-Z]\)/s//\1\1\1\1/g
g/3\([a-zA-Z]\)/s//\1\1\1/g
g/2\([a-zA-Z]\)/s//\1\1/g
,p
Q

View file

@ -0,0 +1,46 @@
;; Since newLISP has dynamic scope, use a namespace or context
;; to avoid variable capture.
(context 'monotonic-slices)
(define (monotonic-slices:monotonic-slices lst (key-func or) (cmp =))
(let (result '() tmp '() old-key 0 new-key 0)
(dolist (x lst)
(set 'new-key (key-func x))
(cond ((empty? tmp) (push x tmp))
((cmp new-key old-key) (push x tmp))
(true (push (reverse tmp) result) (set 'tmp (list x))))
(set 'old-key new-key))
(unless (empty? tmp) (push (reverse tmp) result))
(reverse result)))
(context MAIN)
(monotonic-slices '(0 0 2 3 3 3 4 5 5 5 5) )
((0 0) (2) (3 3 3) (4) (5 5 5 5))
(define (compress str)
(apply string (flat
(map
(fn (xs) (list (length xs) (first xs)))
(monotonic-slices (explode str))))))
(compress
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW")
"12W1B12W3B24W1B14W"
(define (decompress str)
(apply ;; Use for fold or reduce.
(fn (built a b) (push (dup (b 0) (int (join a))) built -1))
(cons ""
(monotonic-slices
(explode str)
(fn (c) (<= "0" c "9"))))
3))
(decompress "12W1B12W3B24W1B14W")
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"

View file

@ -1,10 +1,7 @@
# Run Length Encoding and Decoding
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
Split ← ⇌∧(:⊃(⊂□↙)↘)≡/-◫2⊂¯1⊙⊙{} # Use the indexes to cut the string.
Rle ← setinv(
/◇⊂⊜(□⊂⊃(°⋕⧻|⊢))+1⊛.
| ∧(⊂/⊂↯⋕◇⊃↘↙¯1):Split⊚≥@A.
)
/◇⊂⍚⊂°⋕°▽
| ▽⊃⊜⋕(♭⊜∘¬)⊸∈+@0⇡10)
"WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW"
&p⨬("oops"|"good")≍&p.°Rle&p.⊸Rle&p.