Re: [Haskell-beginners] Simplified Luhn Algorithm

I guess your issue is how to represent the card numbers of arbitrary
length, or? Wouldn't a list work?
Patrik
Den 31 dec 2017 05:03 skrev "trent shipley"
luhnDouble 3 6
luhnDouble 6 3
Using luhnDouble and the integer remainder function mod, define a function luhn :: Int -> Int -> Int -> Int -> Bool that decides if a four-digit bank card number is valid. For example:
luhn 1 7 8 4 True
luhn 4 7 8 3 False
In the exercises for chapter 7 we will consider a more general version of this function that accepts card numbers of any length. Hutton, Graham. Programming in Haskell (pp. 45-46). Cambridge University Press. Kindle Edition. -} luhnDouble :: Int -> Int luhnDouble x = if (2 * x) > 9 then (2 * x) - 9 else 2 * x luhn :: Int -> Int -> Int -> Int -> Bool luhn x1 x2 x3 x4 = if 0 == sum[luhnDouble x1, x2, luhnDouble x3, x4] `mod` 10 then True else False _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (1)
-
mrx