Last active
June 12, 2018 12:00
-
-
Save alogic0/39d8e8716bf656f9046d27818ea57987 to your computer and use it in GitHub Desktop.
Funny Haskell. try to run `matrix 2 (7^12345)` in ghci
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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