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

Prog challenge:

Name: Anonymous 2009-05-25 1:16

Write Ascii85 to binary converter in 10 lines of code.
Hard Mode: Using Python.
Hardcore Mode: in Esoteric language of your choice.

Name: Anonymous 2009-05-25 1:18

How long is a "line"?

Name: Anonymous 2009-05-25 1:24

First, what the hell is ASCII85? Second, what is binary? Define ``converter''. Also, when you say 10, do you mean 10 in decimal? Or 10 in base 1020?

Name: Anonymous 2009-05-25 1:26

Integer.toBinaryString(i);

Get bent faggot.

Name: Anonymous 2009-05-25 1:34

>>3
I admit my role!

Name: Anonymous 2009-05-25 1:37

>>5
What's that supposed to mean?

Name: Anonymous 2009-05-25 1:46

>>6
He accepts the submissive homosexual position for >>4

Name: Anonymous 2009-05-25 1:46

.286
cseg segment
assume cs:cseg, ds:cseg, es:cseg, ss:cseg
org 256
entrypoint:
    mov di, offset outbuffer
main_loop:
    xor bx, bx  ; low word of developing dord
    xor dx, dx  ; high word of developing dord
    mov bp, 5   ; how much development the dord has remaining
read_loop:
    call GetChar
cmp_start:
    inc ax
    jz do_eof
    cmp al, 21h
    jz read_loop
    cmp al, 0ah
    jz read_loop
    cmp al, 0eh
    jz read_loop
    cmp al, 0bh
    jz read_loop
    cmp al, 'z'+1
    jz do_z
    cmp al, '~'+1
    jz do_efd
    cmp al, '!'+1
    jb read_loop
    cmp al, 'u'+1
    ja read_loop
    sub al, '!'+1   ; develop the dord - turn into a digit 0 - 84
    xchg bx, ax     ; put it away for now
    call mul85      ; multiply existing dord
    add ax, bx      ; add this new one to it
    jnc nov
    inc dx          ; take high one too
nov:
    xchg ax, bx     ; put it back
    dec bp
    jnz read_loop   ; dord developed yet? no? otherwise just write it out
write_dord:
    xchg ax, dx
    xchg al, ah
    stosw
    xchg ax, bx
    xchg al, ah
    stosw
; check for overflow
    cmp di, offset outbuffer+28160
    jb main_loop
    push offset entrypoint
do_wr:
    mov dx, offset outbuffer
    mov cx, di
    sub cx, dx
    jz do_wr_n
    mov ah, 40h
    mov bx, 1
    int 21h
do_wr_n:
    ret
do_z:
    cmp bp, 5
    jnz read_loop
do_z_ok:    ; write a null dord
    xor bx, bx
    xor dx, dx
    jmp short write_dord
do_efd:
    call GetChar
    cmp al, '>'
    jnz cmp_start
do_eof:
    cmp bp, 5       ; no partial dord
    jz do_wr
    xchg ax, bx
    mov bx, bp
do_eof_dev:     ; develop the final dord to maturity
    call mul85
    dec bp
    jnz do_eof_dev
    neg bx
    add bx, 4
    jz do_wr
    mov cx, bx
;-- rounding fix --
    dec bx
    jnz rn2
    add dx, 128
    jmp short writebytesloop
rn2:
    dec bx
    jnz rn3
    add ah, 128
    jmp short rn35
rn3:
    add ax, 128
rn35:
    jnc writebytesloop
    inc dx
;------------------
writebytesloop:
    xchg dh, al
    xchg dh, dl
    xchg dl, ah
    stosb
    loop writebytesloop
    jmp short do_wr
mul85:  ; multiply DX:AX by 85 and leave the result in DX:AX
        ; no overflow check!
    push bx
    push cx
    mov bl, 85  ; bh already 0
    push dx
    mul bx
    pop cx
    push dx
    xchg ax, cx
    mul bx
    pop dx
    add ax, dx
    xchg ax, dx
    xchg ax, cx
    pop cx
    pop bx
    ret
GetChar:
    mov ax, inbufcnt
    or ax, ax
    jnz GetChar_NI
    push bx
    push cx
    push dx
    xchg ax, bx
    mov ah, 3fh
    mov cx, 35200
    mov dx, offset inbuffer
    int 21h
    mov si, dx
    pop dx
    pop cx
    pop bx
    mov inbufcnt, ax
    or ax, ax
    jnz GetChar_NI
    dec ax
    ret
GetChar_NI:
    xor ax, ax
    lodsb
    dec word ptr inbufcnt
    ret
inbufcnt dw 0
inbuffer db 35200 dup (?)
outbuffer db 28160 dup (?)
cseg ends
end entrypoint

Name: Anonymous 2009-05-25 1:51

>>8
BF 6D 8B 33-DB 33 D2 BD 05 00 E8 B3 00 40 74 63 3C 21 74 F6 3C 0A 74 F2 3C 0E 74 EE 3C 0B 74 EA
3C 7B 74 3D-3C 7F 74 44 3C 22 72 DE 3C 76 77 DA 2C 22 93 E8 76 00 03 C3 73 01 42 93 4D 75 CB 92
86 C4 AB 93 86 C4 AB 81 FF 6D F9 72 B6 68 00 01 BA 6D 8B 8B CF 2B CA 74 07 B4 40 BB 01 00 CD 21
C3 83 FD 05 75 A4 33 DB 33 D2 EB D3 E8 51 00 3C 3E 75 9A 83 FD 05 74 D8 93 8B DD E8 2E 00 4D 75
FA F7 DB 83 C3 04 74 C8 8B CB 4B 75 06 81 C2 80 00 EB 0E 4B 75 05 80 C4 80 EB 03 05 80 00 73 01
42 86 F0 86 F2 86 D4 AA E2 F7 EB A4 53 51 B3 55 52 F7 E3 59 52 91 F7 E3 5A 03 C2 92 91 59 5B C3
A1 EB 01 0B C0 75 1C 53 51 52 93 B4 3F B9 80 89 BA ED 01 CD 21 8B F2 5A 59 5B A3 EB 01 0B C0 75
02 48 C3 33 C0 AC FF 0E EB 01 C3 00 00


Challenge complete.

Name: Anonymous 2009-05-25 1:57

>>8
inbuffer
      ^

No one on /prog/ could have written this.  Your a phony!

Name: Anonymous 2009-05-25 2:00

>>10
You're a /prog/tard.

Name: Anonymous 2009-05-25 2:30

I admit my role, but what's an ASCII85? I bet I could do this in OIOC in one line! I admit my role!

Name: Anonymous 2009-05-25 5:39

Name: Anonymous 2009-05-25 5:41

>>12
What does you mean when you say "you admit your role"? Sorry, English is not my mother tongue.

Name: Anonymous 2009-05-25 5:56

>>14
Do you think a lot about your mother's tongue?
When did it start?
Does it disturb you?

Name: Anonymous 2009-05-25 6:01

>>14
I admit my role to taking your challenge.

Name: Anonymous 2009-05-25 9:48

Still doesn't work perfectly (outputs characters at the end which should be truncated). Does Haskell classify as an esoteric language?

import Data.Char (chr, ord, isSpace)

dec5, decode :: String -> String
dec5 xs = map (chr . fromInteger) $ reverse $ map (flip rem 256) $ take 4 $ iterate (flip div 256) n
    where n = sum $ zipWith (*) (map (85^) $ reverse [0..4]) (map (\c -> toInteger $ ord c - 33) xs)

decode [] = []
decode s | head s == 'z' = (replicate 4 '\0') ++ (decode $ tail s)
         | isSpace $ head s = decode $ tail s
         | otherwise = (dec5 $ take 5 (s ++ cycle ['u'])) ++ (decode $ drop 5 s)

Name: Anonymous 2009-05-25 9:52

>>17
Actually, (\c -> toInteger $ ord c - 33) could be ((-33+) . toInteger . ord), if somebody prefers those pointless things.

Name: GRUNNUR 2009-05-25 10:42

>>17

dec5, decode :: String -> String

removed this line because it's redundant

Name: Anonymous 2009-05-25 11:09

>>19
But it's one of the BEST ENTERPRISE PRACTICES!!

Name: Anonymous 2009-05-25 11:20

>>17
Also,
dec5 = (map (chr . fromInteger)) . reverse . (map (flip rem 256)) . (take 4) . (iterate (flip div 256)) . sum . (zipWith (*) (map (85^) $ reverse [0..4])) . (map ((-33+).toInteger.ord))

Name: Anonymous 2009-05-25 12:16

import struct

def decode(text):
    r = ''
    while text:
        b, t, text = 0, text[0:5], text[5:]
        while t: b, t = b*85 + ord(t[0]) - 33, t[1:]
        r += struct.pack('>I', b)
    return r


def encode(text):
    r = ''
    while text:
        b, t, text = '', struct.unpack('>I', text[0:4].ljust(4))[0], text[4:]
        while t:
            b, t = chr(t % 85 + 33) + b, t / 85
        r += b
    return r

Name: Anonymous 2009-05-25 22:47

>>11
BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA BUFFA

Name: Anonymous 2009-05-25 23:13

>>23
Did you mean ``Buffalo buffalo buffalo Buffalo buffalo buffalo Buffalo buffalo''?

Name: Anonymous 2009-05-27 0:03

bampu buffa

Name: Anonymous 2009-05-27 13:23

import Control.Arrow
import Char

ascii85ToAscii [] = []
ascii85ToAscii ascii85 =
   uncurry (++) $ reverse . take 4 . map (chr . (`mod` 256)) . iterate (`div` 256) .
      foldl ((+) . (*85)) 0 . map (subtract 33 . ord) *** ascii85ToAscii $ splitAt 5 ascii85

Name: Anonymous 2009-05-27 16:59

>>26
Can you please enlighten me as to what that piece of code does?
I'm mostly interested in the Control.Arrow and ***.

Name: Anonymous 2009-05-27 17:03

>>27
(***) :: a b c -> a b' c' -> a (b, b') (c, c')
I think this one is pretty clear.
Consider reading appropriate papers¹ for fuller explanation.
____
¹ http://www.haskell.org/haskellwiki/Research_papers/Monads_and_arrows#Arrows

Name: Anonymous 2009-05-27 17:08

>>28
Ah, does it take two functions which take one argument each and return one value and creates a function which takes a tuple of arguments and returns a tuple of values?
Don't beat me up, I never even tried understanding Arrows ;_;

Name: Anonymous 2009-05-27 17:12

>>28
Now that I realized that (***) needs (Arrow a) => a, the type signature finally became clear!
I have still a long way to go if I want to write code like >>26-dono. :(

Name: Anonymous 2009-05-27 17:23

>>29
Read Basic Category Theory for Computer Scientists.

Name: Anonymous 2009-05-27 17:29

>>31
How much do I have to know to understand it?

Name: Anonymous 2009-05-27 17:36

>>32
Not much, you just need some time, patience, and not to be a fucking idiot (not that I think you are).

Name: Anonymous 2009-05-27 21:33

import Control.Arrow

Name: Anonymous 2009-05-27 21:50

>>29
a b c is like b -> c, only more general (works for arrows, not only for functions).

Name: Anonymous 2009-05-28 14:50

>>35
I know. I wrote >>30 just after I posted >>29.
>>31
Thanks, I will (someday).

Name: Anonymous 2010-11-26 14:09

Name: Anonymous 2011-02-03 0:44

Name: Anonymous 2011-02-03 5:12

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