joeyh

joeyh at

Charles Stanhope likes this.

Show all 5 replies
helloworld :: String
helloworld = brainfuck $
        forM_ "hello, world!" $
                flip withChar output

Generates a page of brainfuck.. which does print out the greeting when run.

joeyh at 2014-12-12T06:29:02Z

 -- | Optimized to use less space.
 helloworld' :: String
 helloworld' = brainfuck $ go 0 $ map Char.ord "hello, world!"
   where
         go n [] = return ()
         go n (c:cs) = do
                 let delta = c - n
                 multi (if delta > 0 then incr else decr) (abs delta)
                 output
                 go c cs

I think this generates the shortest possible brainfuck hello world program. And I wrote it in ... 15 minutes?

joeyh at 2014-12-12T06:45:41Z

oh hell, I've taken all the fun out of brainfuck, haven't I?

joeyh at 2014-12-12T06:59:50Z

So yeah, I have a function that can optimize brainfuck code. For example, converts ">[-]>[-]+[<>[-],.<>]<<" to "+[[-],.]"

joeyh at 2014-12-12T20:48:59Z

Christopher Allan Webber likes this.