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

post you are run length encoding in lisp

Name: Anonymous 2014-10-05 3:18

critique mine pl0x:

(defun rle (str) ;run length encoding
(let ((i 0) c count out)
(while (< i (length str))
(if (eq c (elt str i))
(setq count (1+ count))
(when c
(setq out (append out (list (cons c count)))))
(setq c (elt str i))
(setq count 1))
(setq i (1+ i)))
(when c (setq out (append out (list (cons c count)))))
out))

Name: Anonymous 2014-10-09 7:43

rle:
#include <stdio.h>

int main(int argc, char **argv) {
int byte, count, temp;
begin:
byte = getchar();
count = 0;
if (byte == EOF) return 0;
is_same:
temp = getchar();
if (temp == EOF) {
putchar(count); putchar(byte);
return 0;
} else if (byte == temp) {
count++;
if (count == 255) {
putchar(count); putchar(byte);
goto begin;
} else goto is_same;
} else {
putchar(count); putchar(byte);
byte = temp; count = 0;
goto is_same;
}
}


unrle:
#include <stdio.h>

int main(int argc, char **argv) {
int count, byte;
for (;;) {
count = getchar();
byte = getchar();
if (count == EOF || byte == EOF) return 0;
for (int i = 0; i <= count; i++) putchar(byte);
}
}

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