
31 May
2007
31 May
'07
9:08 p.m.
On Thursday 31 May 2007, Andrew Coppin wrote:
If you're bored... can you come up with a solution to this?
http://warp.povusers.org/ProgrammingChallenge.html
(Obviously a pretty silly challenge, but hey.)
With some help from int-e in irc:
{-# OPTIONS_GHC -fglasgow-exts #-}
import GHC.Base import GHC.Word import GHC.Exts import Numeric import Data.Char
doubleToBits (D# d) = W64# (unsafeCoerce# d)
main = interact $ unlines . map (pad . (\x -> showIntAtBase 2 intToDigit x "") . doubleToBits . read) . lines where pad l = replicate (64 - length l) '0' ++ l
I suspect that that doesn't respect the endianness of the machine like the C++ does, though. -- Dan