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

Challenge

Name: Anonymous 2009-06-15 14:23

Write a C program which outputs binary values of all possible bytes(0-255) as e.g. '00001011\n' in the least space.

Name: Anonymous 2009-06-15 14:25

Do your own homework.

Name: Anonymous 2009-06-15 15:11

for (uint8_t byte = 0;; ++byte) {
    for (int i = 0; i < 8; ++i) putchar(byte & (0x80 >> i) ? '1' : '0');
    putchar('\n');
    if (byte == 0xFF) goto end;
} end:;

Name: Anonymous 2009-06-15 15:24

mapM_ putStrLn $ sequence $ replicate 8 ['0','1']

Name: Anonymous 2009-06-15 15:27

for (uint8_t byte = 0;; ++byte) {
    if (byte == 0xFF) goto end;
Am I missing something here?

Name: Anonymous 2009-06-15 15:40

for(char i=0;i<256;i++){for(char j=0;i<8;j++){printf("%i",i&1);i>>1}printf("\n");}

Name: Anonymous 2009-06-15 15:41

>>6
for(char i=0;i<256;i++){for(char j=0;i<8;j++){printf("%i",i&1);i>>=1}printf("\n");}
Forgot an =.

Name: Anonymous 2009-06-15 15:46

int i,b=256;while(b--){i=8;while(i--)putchar(b&(1<<i)?'1':'0');puts("");}

Name: Anonymous 2009-06-15 16:08

>>8
Nice!
but shouldn't that be i=7? I mean 1<<1 doesn't result in 1. Also use 48 and 49 instead of 0 and 1 for further shortening.

Name: Anonymous 2009-06-15 16:32

>>3
goto
!!!!

Name: Anonymous 2009-06-15 16:34

>>9
Ah yes. Also I'm not feeling the putchar and puts calls. Does anyone know any other (space-optimised) ways of doing that?

Name: Anonymous 2009-06-15 16:41

char i = 0;
while( i++ < 255 ) printf( "%b\n", i );
return 0;

Name: Anonymous 2009-06-15 17:45

256.times{|i|puts Array.new(8){|n|i[n]}.reverse.join}

Name: Anonymous 2009-06-15 18:02

(dotimes (i 256) (format t "~B~%" i))

Name: Anonymous 2009-06-15 18:10

srsly u guys

char i;main(){do putchar(i);while(++i);}

Name: REPLICATEM FAN 2009-06-15 18:17

>>4
sequence $ replicate
Use replicateM!

putStrLn . unlines $ replicateM 8 "01"

Name: Anonymous 2009-06-15 19:04

say unpack"B*",chr for 0..255

Name: Anonymous 2009-06-15 19:11

: bits 256 0 do i 7 for dup i rshift 1 and '0 + emit next cr loop ;

Name: Anonymous 2009-06-15 19:27

>>16
I still don't know a lot :/
why not mapM_ putStrLn $ replicateM 8 "01" then?

Name: Anonymous 2009-06-15 19:32

>>16
You can do that too, but some prefer to do as much as possible in purely functional code.

Name: Anonymous 2009-06-15 19:33

def s(n,j):
 if j+1:print n>>j&1,;s(n,j-1)
for i in range(256):s(i,7);print


Where's your FORCED now‽

Name: >>18 2009-06-15 21:28

Corrected:
: bits 256 0 do 7 for j i rshift 1 and '0 + emit next cr loop ;

Name: Anonymous 2009-06-15 21:32

>>20
PROTIP: replicateM is purely functional.

Name: Anonymous 2009-06-16 0:19

Isn't there a non-alphabet operator replacement for sequence?

Name: Anonymous 2009-06-16 18:04

>>18,22
What language is that? Factor, Forth?

Name: Expert Haskell Programmer 2009-06-16 19:49

>>24
--There is now
($&%@#) = sequence

Name: Expert Haskell Programmer 2009-06-16 21:45

y = sin x lol guys im so much better than lisp

Name: Anonymous 2009-06-17 17:14

char i = 1;
while( i++ ) printf( "%b\n", i );
return 0;

Name: Anonymous 2009-06-17 17:28

>>28
missing 0, also there is no %b.

Name: Anonymous 2009-06-17 17:45

>>29
o rly?

Name: Anonymous 2009-06-18 19:01

>>25
That language is, indeed, Forth.

Name: Anonymous 2009-06-18 19:57

(echo obase=2; tr '\0' '\n' < /dev/zero | head -n 256 | nl -v 0 -b a) | bc
or, if you have seq:
(echo obase=2; seq 0 255) | bc

Name: Anonymous 2009-06-18 20:17

[a:b:c:d:e:f:g:[h] | a <- i, b <- i, c <- i, d <- i, e <- i, f <- i, g <- i, h <- i]
where i = "01"

Name: Anonymous 2009-06-18 20:45

You guys are forgetting to make the fon't smaller.  That will take up even less space.

Name: Anonymous 2009-06-18 20:56

>>34
echo -e "main = let i = \"01\" in putStrLn $ \"<span style='font-size:0.1px'>\" ++ unlines [a:b:c:d:e:f:g:[h] | a <- i, b <- i, c <- i, d <- i, e <- i, f <- i, g <- i, h <- i] ++ \"</span>\"" | runghc | w3m

Name: Anonymous 2009-06-19 6:40

>>33
lolwat

Name: Anonymous 2009-06-19 9:30

>>33
PROTIP: [a,b,c,d,e,f,g,h]

Name: Anonymous 2009-06-19 12:34

print '00001011\n'

Name: Anonymous 2009-06-19 13:12

>>33
You do know that's exactly what replicateM 8 "01" does?

Name: Anonymous 2009-06-19 19:32

>>39
I thought I understood monads and suddenly you made this post.

And I feel kind of bad about it :(

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