Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created February 18, 2015 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shigemk2/b18e7d8a3074646346fe to your computer and use it in GitHub Desktop.
Save shigemk2/b18e7d8a3074646346fe to your computer and use it in GitHub Desktop.
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