Created
February 18, 2015 12:00
-
-
Save shigemk2/b18e7d8a3074646346fe to your computer and use it in GitHub Desktop.
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
import Data.Char | |
import Data.List | |
digitSum :: Int -> Int | |
digitSum = sum . map digitToInt . show | |
-- find :: (a -> Bool) -> [a] -> Maybe a | |
firstTo40 :: Maybe Int | |
firstTo40 = find (\x -> digitSum x == 40) [1..] | |
firstTo :: Int -> Maybe Int | |
firstTo n = find (\x -> digitSum x == n) [1..] | |
main = do | |
print $ digitToInt '2' | |
print $ digitToInt 'F' | |
print $ digitSum 4444 | |
print $ firstTo40 -- 49999 | |
print $ firstTo 40 -- 49999 | |
print $ firstTo 27 -- 49999 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment