Variable-length quantity: Difference between revisions
Content added Content deleted
(→{{header|Haskell}}: Added type signatures, slight tidying) |
|||
Line 670: | Line 670: | ||
Homemade Version: |
Homemade Version: |
||
<lang Haskell> |
<lang Haskell>import Data.List (intercalate) |
||
base :: Int |
|||
base = 8 |
|||
to :: Int -> [Int] |
|||
to 0 = [] |
to 0 = [] |
||
to i = to (div i base) ++ [mod i base] |
to i = to (div i base) ++ [mod i base] |
||
from |
from :: [Int] -> Int |
||
from = foldl1 (\x y -> x * base + y) |
|||
⚫ | |||
fancy 2097152 |
|||
fancy 2097151 |
|||
⚫ | |||
main :: IO () |
|||
⚫ | |||
mapM_ |
|||
(putStrLn . |
|||
intercalate " <-> " . |
|||
⚫ | |||
[2097152, 2097151] |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>10000000 <-> 2097152 |
<pre>10000000 <-> 2097152 |