[REBOL] Re: Algorithm challenge: compacting integers
From: vpavlu::gmail at: 21-Jan-2007 17:47
I don't follow the Altme conversation but would like to know where I
range in with my de/compact:
compact: func [blk /local result fst a b runl][
if empty? blk [return blk]
result: make list! length? blk
runl: 1
fst: a: first blk
foreach b next blk [
either = + 1 a b [
if runl = 1 [fst: a]
runl: runl + 1
][
insert result either runl = 1 [a][as-pair fst runl]
runl: 1
]
a: b
]
insert result either runl = 1 [a][as-pair fst runl]
to-block head result
]
decompact: func [blk /local result item][
result: make list! 2 * length? blk
foreach item blk [
either pair? item [
i: item/1 - 1
loop item/2 [insert result i: i + 1]
][
insert result item
]
]
to-block head result
]
regards,
Viktor