Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

EMU8086 help

Name: Dumbass 2007-06-17 19:43 ID:/qzsph9W

Modify the program so that it prints the decompressed data.

The compressed data is 1, 4, 3, 9, 5, 3, 2, 7, 0.  The program currently just prints all these values except the terminating zero.  When properly decompressed, the output should be:

 4 9 9 9 3 3 3 3 3 7 7

Modify the program to print out the decompressed data.  To do this you need to realize that the data comes in pairs like 5, 3.  This first value in the pair is the number of times the second value is to be repeated.  So set up a nested, inner loop to execute this number of times, and print the second value in the pair inside this inner loop.


The dumbfuck didn't give much of an explination on how to do it.

Name: Anonymous 2007-06-17 19:51 ID:SjJB4bwy

It would help if you posted the program you're supposed to modify.

Name: Anonymous 2007-06-17 19:58 ID:/qzsph9W

That's the problem. The guy didn't leave me the program to modify. Asshole! Anyways, I'll provide the picture by my photobucket:

http://i166.photobucket.com/albums/u84/roy9076/rle_soln.gif

Name: Anonymous 2007-06-17 20:16 ID:Heaven

>>3
That essentially contains the full solution. You only need to add code for the branches.

I see you like lolis.

Name: Anonymous 2007-06-17 20:18 ID:/qzsph9W

Anyone can help me about the coding?

Name: Anonymous 2007-06-17 22:40 ID:Heaven

>>5
/prog/ is not your personal army.

                       //`'''```,
             o        // LISP   `.,
       ,....OOo.   .c;.',,,.'``.,,.`

Name: Anonymous 2007-06-17 22:40 ID:5+x955Hl

>>3
I see you're a weeaboo faggot.

Name: Anonymous 2007-06-17 22:45 ID:aqgj2ROJ

Anyone can help me about the coding?
$ perl -le'print join" ",map{($,$v)=(shift,shift);map$v,1..$c}@ARGV' 1 4 3 9 5 3 2 7 0
4 9 9 9 3 3 3 3 3 7 7


( scratchpad ) [ { 1 4 3 9 5 3 2 7 0 } reverse [ ] each 4 [ [ dup # " " % ] times drop ] times drop ] " " make print
4 9 9 9 3 3 3 3 3 7 7


I see you like lolis.
who doesn't?

Name: Anonymous 2007-06-17 22:46 ID:Heaven

>>8
actually, i can do this instead, just because it looks nicer this way:
{ 1 4 3 9 5 3 2 7 0 } [ reverse [ ] each 4 [ [ dup # " " % ] times drop ] times drop ] " " make print

Name: Anonymous 2007-06-17 23:04 ID:Heaven

>>3
that implementation is made of bloated and fail.

'.rleloop'
'lodsw | xchg cx | jcxz .end | lodsw | rep | stosw'
'jmps .rleloop'
'.end'

Name: Anonymous 2007-06-18 4:33 ID:+qFbx5al

MOAR!
(wants to see an implementation of this in Lisp or Python).

Name: Anonymous 2007-06-18 4:37 ID:Heaven

this 'compression' sucks balls

Name: Anonymous 2007-06-18 4:53 ID:+qFbx5al

int compressed_data []={1, 4, 3, 9, 5, 3, 2, 7, 0};
for(int i=0; i<sizeof(compressed_data)/sizeof(int); i+=2)
  while(compressed_data[i]--) std::cout << compressed_data[i+1];

Name: Anonymous 2007-06-18 5:00 ID:Heaven

decompress [0]      = []
decompress (x:y:xs) = replicate x y ++ decompress xs

Name: Anonymous 2007-06-18 7:17 ID:aLashOsO

Python, using lists. The final 0 is useless, but I'll respect it. I'll return a list.

Iterative, traditional:

def uncompress(l):
    o = []
    for i in xrange(0, len(l) - 1, 2):
        o += l[i] * [l[i + 1]]
    return o


Iterative, Pythonic:

def uncompress(l):
    o = []
    for x, y in zip(l[:-1:2], l[1:-1:2]):
        o += x * [y]
    return o


Functional, tail recursive:

def uncompress(i, o=[]):
    if i == [0]: return o
    return uncompress2(i[2:], o + i[0] * [i[1]])


(LISP is pretty much the above code, just with a different syntax.)

Name: Anonymous 2007-06-18 7:30 ID:JE+333XP

>>8
who doesn't?
pizza in bizzaro world

Name: Anonymous 2007-06-18 8:01 ID:+qFbx5al

>>15 Thank-you Anonymous, I had not seen double :'s in a [ ] or the zip function, but then again I'm not a EXPERT PROGRAMMER.

Name: Anonymous 2007-06-18 8:48 ID:nVw2agAE

( scratchpad ) : decompress ( seq -- seq ) [ dup length 2/ [ reverse [ ] each ] swap slip [ [ dup , ] times drop ] times drop ] { } make ;
( scratchpad ) { 1 4 3 9 5 3 2 7 0 } decompress .
{ 4 9 9 9 3 3 3 3 3 7 7 }

Name: Anonymous 2007-06-18 14:01 ID:3OxbgaxP

>>18
ugly

Name: Anonymous 2007-06-19 2:49 ID:9duqMx72

J ftw.

x =: 1, 4, 3, 9, 5, 3, 2, 7, 0

_2 (< @: ({. # {:) @: >)\ x

BTW, does J have a concatMap function? I couldn't figure out how to join the boxes.

Name: Anonymous 2007-06-19 13:14 ID:Heaven

>>18
: decompress ( seq -- seq ) 1 head* 2 group [ reverse >vector dup pop 1- [ dup dup peek swap push ] times >array ] map concat ;

Name: Anonymous 2007-06-19 23:52 ID:9duqMx72


_2 ({. # {:)\ (|: _2 ]\ x)

I actually have no idea what \ does. yay me.

Name: Anonymous 2007-06-19 23:59 ID:IuTt0NDd

>>22
if you learned J you could understand it

Name: Anonymous 2007-06-20 14:05 ID:itsMZWlr

>>23
Well I am learning J. I understand what it does when you give it a vector but in >>22 I gave it a 2xn array and I have no idea how it gave the result.

Name: Anonymous 2007-06-24 20:13 ID:xKFMrow0

Superiar.

#/ |: _2 ]\ x

Name: Anonymous 2010-11-03 4:20

Name: Anonymous 2011-02-04 13:34


Don't change these.
Name: Email:
Entire Thread Thread List