Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.