Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
15
Task/Factorions/Haskell/factorions.hs
Normal file
15
Task/Factorions/Haskell/factorions.hs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
import Text.Printf (printf)
|
||||
import Data.List (unfoldr)
|
||||
import Control.Monad (guard)
|
||||
|
||||
factorion :: Int -> Int -> Bool
|
||||
factorion b n = f b n == n
|
||||
where
|
||||
f b = sum . map (product . enumFromTo 1) . unfoldr (\x -> guard (x > 0) >> pure (x `mod` b, x `div` b))
|
||||
|
||||
main :: IO ()
|
||||
main = mapM_ (uncurry (printf "Factorions for base %2d: %s\n") . (\(a, b) -> (b, result a b)))
|
||||
[(3,9), (4,10), (5,11), (2,12)]
|
||||
where
|
||||
factorions b = filter (factorion b) [1..]
|
||||
result n = show . take n . factorions
|
||||
Loading…
Add table
Add a link
Reference in a new issue