Last active
July 24, 2019 20:48
-
-
Save NolanDeveloper/94db092e07d1a8a1f7dea2e0c1afd3f0 to your computer and use it in GitHub Desktop.
Project euler utility functinos
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
-- Convert number to list of digits | |
tods n = if n < 10 then [n] else reverse $ unfoldr (\i -> if i == 0 then Nothing else Just (i `mod` 10, i `div` 10)) n | |
-- Convert list of digits to number | |
ton = foldl' (\a b -> a * 10 + b) 0 | |
-- Make list of numbers from digits | |
numbers ns = concat $ iterate (\xs -> concatMap (\n -> map (\xs' -> n : xs') xs) ns) (map (\c -> [c]) ns) | |
-- Primality test | |
isPrime n = 2 <= n && all (\k -> n `mod` k /= 0) [2..ceiling (sqrt (fromIntegral n))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment