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

Pages: 1-

RLE

Name: Anonymous 2015-03-03 2:25

Here's my implementation of RLE in C.
http://en.wikipedia.org/wiki/Run-length_encoding
What is it in your lang?

#include <stdio.h>
int main(void) {
int i;
char s[] = "%*[_]%n";
for(i = 0; scanf("%c", &s[3]) == 1 && scanf(s, &i) != EOF);
printf("%d%c", ++i, s[3]));
return 0;
}

Name: Anonymous 2015-03-03 6:21

SOURCE FREE
IDENTIFICATION DIVISION.
PROGRAM-ID. run-length-encoding.

ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
REPOSITORY.
FUNCTION encode
FUNCTION decode
.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 input-str PIC A(100).
01 encoded PIC X(200).
01 decoded PIC X(200).

PROCEDURE DIVISION.
ACCEPT input-str
MOVE encode(FUNCTION TRIM(input-str)) TO encoded
DISPLAY "Encoded: " FUNCTION TRIM(encoded)
DISPLAY "Decoded: " FUNCTION TRIM(decode(encoded))
.
END PROGRAM run-length-encoding.


IDENTIFICATION DIVISION.
FUNCTION-ID. encode.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01 str-len PIC 9(3) COMP.

01 i PIC 9(3) COMP.

01 current-char PIC A.

01 num-chars PIC 9(3) COMP.
01 num-chars-disp PIC Z(3).

01 encoded-pos PIC 9(3) COMP VALUE 1.

LINKAGE SECTION.
01 str PIC X ANY LENGTH.

01 encoded PIC X(200).

PROCEDURE DIVISION USING str RETURNING encoded.
MOVE FUNCTION LENGTH(str) TO str-len
MOVE str (1:1) TO current-char
MOVE 1 TO num-chars
PERFORM VARYING i FROM 2 BY 1 UNTIL i > str-len
IF str (i:1) <> current-char
CALL "add-num-chars" USING encoded, encoded-pos,
CONTENT current-char, num-chars

MOVE str (i:1) TO current-char
MOVE 1 TO num-chars
ELSE
ADD 1 TO num-chars
END-IF
END-PERFORM

CALL "add-num-chars" USING encoded, encoded-pos, CONTENT current-char,
num-chars
.
END FUNCTION encode.

IDENTIFICATION DIVISION.
PROGRAM-ID. add-num-chars.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 num-chars-disp PIC Z(3).

LINKAGE SECTION.
01 str PIC X(200).

01 current-pos PIC 9(3) COMP.

01 char-to-encode PIC X.

01 num-chars PIC 9(3) COMP.

PROCEDURE DIVISION USING str, current-pos, char-to-encode, num-chars.
MOVE num-chars TO num-chars-disp
MOVE FUNCTION TRIM(num-chars-disp) TO str (current-pos:3)
ADD FUNCTION LENGTH(FUNCTION TRIM(num-chars-disp)) TO current-pos
MOVE char-to-encode TO str (current-pos:1)
ADD 1 TO current-pos
.
END PROGRAM add-num-chars.


IDENTIFICATION DIVISION.
FUNCTION-ID. decode.

DATA DIVISION.
LOCAL-STORAGE SECTION.
01 encoded-pos PIC 9(3) COMP VALUE 1.
01 decoded-pos PIC 9(3) COMP VALUE 1.

01 num-of-char PIC 9(3) COMP VALUE 0.

LINKAGE SECTION.
01 encoded PIC X(200).

01 decoded PIC X(100).

PROCEDURE DIVISION USING encoded RETURNING decoded.
PERFORM VARYING encoded-pos FROM 1 BY 1
UNTIL encoded (encoded-pos:2) = SPACES OR encoded-pos > 200
IF encoded (encoded-pos:1) IS NUMERIC
COMPUTE num-of-char = num-of-char * 10
+ FUNCTION NUMVAL(encoded (encoded-pos:1))
ELSE
PERFORM UNTIL num-of-char = 0
MOVE encoded (encoded-pos:1) TO decoded (decoded-pos:1)
ADD 1 TO decoded-pos
SUBTRACT 1 FROM num-of-char
END-PERFORM
END-IF
END-PERFORM
.
END FUNCTION decode.

Name: Anonymous 2015-03-03 6:23

fuck all y'all all y'all in y'all high horses

Name: Anonymous 2015-03-03 6:28

>>2
main.cobc:7: Error: syntax error, unexpected "Identifier", expecting ALL or Literal"
Help me Cobol dude.

Name: Anonymous 2015-03-03 6:37

Name: Anonymous 2015-03-03 13:14

Really lame encoding, go away baby

Name: Anonymous 2015-03-03 20:18

>>2
SOURCE FREE
Pathetic.

Name: Anonymous 2015-03-03 21:35

>>6
It may be lame but it's a good lil algorithm to show off. I really like my code in >>1

Name: Anonymous 2015-03-04 0:26

My cigar is burning unevenly but I care not.

Name: Anonymous 2015-03-04 0:40

>>2
Such elegance and grace

Name: george dubya bush 2015-03-04 1:56

Nice

Name: dubsmon 2015-03-04 18:13

check my dozen

Name: Anonymous 2015-03-04 20:30

Bitches brew

Name: Anonymous 2015-03-12 9:34

Bumping this with http://en.wikipedia.org/wiki/Kolakoski_sequence
Do you guys know about this sequence?

Name: Anonymous 2015-03-12 11:19

>>14
That's pretty neat.

Name: Anonymous 2015-03-13 15:01

>>15
Yeah, that's pretty cool.

Name: Anonymous 2015-03-13 16:59

>>16
Agreed, it is pretty nice.

Name: Anonymous 2015-03-13 17:25

>>17
Yup, that's pretty good.

Name: Anonymous 2015-03-13 18:56

>>15-18
Not as neat as dubs.

Name: Anonymous 2015-03-13 20:13

>>19
I see no dubs here, buddy!

Name: Anonymous 2015-03-13 23:43

>>1
It doesn't compile, but it's a very inspiring way to use scanf. One of the best programs I've seen on here.

Name: Anonymous 2015-03-13 23:44

>>21
It dpesn't compile
Disregard that.

Name: Anonymous 2015-03-14 17:16

>>22
Whom are you quoting? There is no word "dpesn't" in his post.

Name: Anonymous 2015-03-14 17:45

>>23
Parodying quote-kun doesn't make your shitposts any less shit.

Name: Anonymous 2015-03-14 17:53

>>24
I'm not parodying anyone, I'm genuinely interested why his quote contains a word the original post doesn't.

Name: Anonymous 2015-03-20 2:17

how do you pronounce rle?

Name: Anonymous 2015-03-20 3:36

Radical Left Encoding.

Name: Anonymous 2015-03-20 20:45

>>21
Thank you!
>>25
o and p are close in QWERTY

Note: "Who are you quoting" is a usenet thing, where old posters would shitpost on the newsgroup because some people used google groups and made usenet appear as a forum.

Name: Anonymous 2015-03-21 15:42

>>28
Close in QWERTY or not, it's strange that he chose to retype to quote them, as opposed to just copying and pasting them to save work and ensure precision.

Name: Anonymous 2015-03-22 5:52

>>29
Nice prime.

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