Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Algorithm challenge: compacting intege...

From: D::Weyand::gmx::de at: 28-Jan-2007 7:36

Here´s my code for the de/compacting integer challenge: compact: func [ blk [block!] /local rc b x val ][ rc: to list! blk loop length? rc [ either tail? b: next rc [ break ][ x: val: first rc all [while [(val: val + 1) = pick b 1] [b: remove b] change rc add 1x0 * x 0x1 * negate x - val] ] rc: next rc ] to block! head rc ] decompac: func [ blk [block!] /local i x val rc ][ loop length? blk [ blk: either pair? val: pick blk 1 [ x: add first val i: second val remove blk loop i [insert blk x: x - 1] skip blk i ][ next blk ] ] head blk ] Regards Dirk ---- www.TGD-Consulting.de/Download.html#list -- Attached file included as plaintext by Ecartis -- -- File: cd.r REBOL [] compact: func [ blk [block!] /local rc b x val ][ rc: to list! blk loop length? rc [ either tail? b: next rc [ break ][ x: val: first rc all [while [(val: val + 1) = pick b 1] [b: remove b] change rc add 1x0 * x 0x1 * negate x - val] ] rc: next rc ] to block! head rc ] decompact: func [ blk [block!] /local i x val rc ][ loop length? blk [ blk: either pair? val: pick blk 1 [ x: add first val i: second val remove blk loop i [insert blk x: x - 1] skip blk i ][ next blk ] ] head blk ] halt