Created
January 8, 2014 17:10
-
-
Save mtsmfm/8320393 to your computer and use it in GitHub Desktop.
基数変換
This file contains hidden or 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
| valList :: Int -> Int -> [Int] | |
| valList x n = map (n^) [numDigits, (numDigits-1)..0] | |
| where numDigits = floor $ logBase (fromIntegral n) (fromIntegral x) | |
| convert :: Int -> Int -> [Int] | |
| convert x n | |
| | x < n = [x] | |
| | otherwise = map (snd) $ tail $ scanl (\acc y -> let z = floor $ fromIntegral(fst acc) / fromIntegral(y) in ((fst acc) `mod` y, z)) (x, 0) xs | |
| where xs = valList x n |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
再帰にしようとしてうまくいかなくて convert にガード残ってた 😇