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

[REBOL] Re: Algorithm challenge: compacting integers

From: btiffin::rogers::com at: 21-Jan-2007 20:10

Hi list, newbie. Brian Tiffin, from Meaford, Ontario, Canada. Spent childhood as a commercial fisherman, summers living on an island population 5-20ish, schooldays in small town Meaford. Loved computers from the first moment I saw a TRS-80 Model I full-colour-glossy ad brochure. Bought one. Not knowing anything, I bought a casette tape called TBUG. My first ever program. Turns out that TBUG was the Model I's debugger. I was hooked. TBUG had to be re-written. I had a book on the Z-80, and with 8,192 bytes of storage, minus a few for the machine, good times were to be had. No disk drive, but the tape player had a foot-counter, what more do you want in file management. :) Then University...move to the capital city and after a stint with the government off to working for a phone company. Worked on the same project for over 15 years. Cubicles. I still get called in, but they will have to pay me more than money to go back to cubicles. Gave up the CS field in 99. Manual labour now. Feels better, and at a tenth of the pay, what more do you want in file management. :) Anyway, here's my compact code for Sunanda's compress to pairs challenge. Please note, from Altme, I'm a fan of a version from Chris. ; compress to SKIMP pairs compact: func ["Compact block of indexes to SKIMP pairs" data /local result start test count] [ all [tail? next data return data] result: make block! length? data ; preallocate result block start: test: first data ; start and test value test: 1 + test ; pre-increment test count: 1 ; the 'in sequence' count foreach element next data [ either test = element [ count: 1 + count test: 1 + test ][ insert tail result either 1 = count [start] [add 1x0 * start 0x1 * count] count: 1 start: test: element test: 1 + test ] ] insert tail result either 1 = count [start] [add start * 1x0 count * 0x1] result ] Have a nice day. btiffin