Skip to content

Instantly share code, notes, and snippets.

@alogic0
Last active June 12, 2018 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alogic0/39d8e8716bf656f9046d27818ea57987 to your computer and use it in GitHub Desktop.
Save alogic0/39d8e8716bf656f9046d27818ea57987 to your computer and use it in GitHub Desktop.
Funny Haskell. try to run `matrix 2 (7^12345)` in ghci
import Data.Char (digitToInt)
import Data.List (unfoldr)
import Data.Tuple (swap)
bin2dec :: String -> Integer
bin2dec = foldl (\d i -> d*2 + i) 0 . map (toInteger . digitToInt)
-- dec2bin = reverse . map intToDigit . unfoldr (test . swap . flip divMod 2) where test x = if x == (0,0) then Nothing else Just x
matrix b = unfoldr (test . swap . flip divMod b) where test x = if x == (0,0) then Nothing else Just x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment