Created
September 29, 2015 20:21
-
-
Save btipling/4742be1a794fec5c6a8c to your computer and use it in GitHub Desktop.
1st solution to csi 194 hw1 probl
This file contains hidden or 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
main = putStrLn "Hello, World!" | |
doubleSecondNum :: [Int] -> [Int] | |
doubleSecondNum numbers | |
| length numbers == 0 = numbers | |
| otherwise = reverse (map doubleEven (zip (reverse numbers) [0..])) | |
doubleEven :: (Int, Int) -> Int | |
doubleEven pair | |
| (succ (snd pair)) `mod` 2 == 0 = (fst pair) * 2 | |
| otherwise = fst pair | |
addListDigits :: [Int] -> Int | |
addListDigits ints | |
| length ints == 0 = 0 | |
| otherwise = sum (map combineDigits ints) | |
combineDigits :: Int -> Int | |
combineDigits 0 = 0 | |
combineDigits n | |
| n < 10 = n `mod` 10 | |
| otherwise = (n `mod` 10) + (combineDigits (n `quot` 10)) | |
doubleAndCombineInts :: [Int] -> Int | |
doubleAndCombineInts ints | |
| otherwise = addListDigits (doubleSecondNum ints) | |
isValidCCNum :: [Int] -> Bool | |
isValidCCNum ints | |
| otherwise = (doubleAndCombineInts ints) `mod` 10 == 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment