Skip to content

Instantly share code, notes, and snippets.

@jarmar
Created Apr 3, 2012
Embed
What would you like to do?
Opera april fools p2 (Haskell)
import Data.Word
import Data.ByteString (pack, ByteString, writeFile)
import qualified Data.ByteString as ByteString
import Data.Char (digitToInt)
str = "010000100101101001101000001110010011000101000001010110010010011001010011010110011101110001011111011110101000111000000000000000000001100101011111100000000000000000010000011010001000010101111000000000000010101001000000000001001000000000111111111001111101111111100000001000000000000010001001000100010100111111010100001000011000010000011001000000110100001101000000011010000110100000110101010100111111000100011010000001001001100100011010001100100000001101101010011000001111010100100101000011111100011101011001010101110011101001001010001100110100011010010011011010110000001100010001100101000011101000011101001000011000111001001111011011011111001111101101100101001110100100111111001101001011010001101000000010100000001101100000010110100011011101100100110011111010111011000100010010000011011100100101111010011110011000101011101100111111101110001011101110000101101000001111011111001000100111010011100110011111001110110000010000000111110100101010000001000011011001110001110111010100011111000100100100100100000011001100111001001000111101010111001000010100010101110011101011101001111110100000110101010011100001001000111110000110101101101101111110001101100000001001110101011110101110000000001000100111010110011000111000101000101111001000001010000010011001111010101011010101101011101001001110110100010010011100011101000000100010010101010001110110011011101011010101111110001011101110010010001010011100001010000100100001101110001011111011110101000111000000"
fromBin :: String -> Word8
fromBin = foldl (\x y -> x * 2 + (fromIntegral . digitToInt $ y)) 0
splitEvery _ [] = []
splitEvery n xs = first : (splitEvery n rest)
where (first, rest) = splitAt n xs
-- take 1110001... and make it into a binary string
toBinary :: String -> ByteString
toBinary s = pack $ map fromBin (splitEvery 8 s)
main =
do ByteString.writeFile "foo.bz2" (toBinary str)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment