Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,15 @@
|
|||
import Numeric (readOct, showOct)
|
||||
import Data.List (intercalate)
|
||||
|
||||
to :: Int -> String
|
||||
to = flip showOct ""
|
||||
|
||||
from :: String -> Int
|
||||
from = fst . head . readOct
|
||||
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_
|
||||
(putStrLn .
|
||||
intercalate " <-> " . (pure (:) <*> to <*> (return . show . from . to)))
|
||||
[2097152, 2097151]
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import Data.List (intercalate)
|
||||
|
||||
to :: Int -> Int -> [Int]
|
||||
to _ 0 = []
|
||||
to base i = to base q <> [r]
|
||||
where
|
||||
(q, r) = quotRem i base
|
||||
|
||||
from :: Int -> [Int] -> Int
|
||||
from base = foldl1 ((+) . (base *))
|
||||
|
||||
|
||||
--------------------------- TEST ---------------------------
|
||||
main :: IO ()
|
||||
main =
|
||||
mapM_
|
||||
(putStrLn .
|
||||
intercalate " <-> " .
|
||||
(((:) . (=<<) show . toBase) <*> (return . show . fromBase . toBase)))
|
||||
[2097152, 2097151]
|
||||
where
|
||||
b = 8
|
||||
fromBase = from b
|
||||
toBase = to b
|
||||
Loading…
Add table
Add a link
Reference in a new issue