Created
January 9, 2014 20:32
-
-
Save meikj/8341478 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.List | |
type NI = Int | |
type Age = Int | |
type Balance = Int | |
type Person = (NI, Age, Balance) | |
type Bank = [Person] | |
type Market = [Bank] | |
type Pop = [NI] | |
-- BEGIN TEST DATA -- | |
b1 :: Bank | |
b1 = [(1,21,100), (2,32,5000)] | |
b2 :: Bank | |
b2 = [(2,32,10000), (1,21,50)] | |
m :: Market | |
m = [b1, b2] | |
p :: Pop | |
p = [1,2,3,4,5] | |
-- END TEST DATA -- | |
retired :: Person -> Bool | |
retired (_,age,_) = age >= 65 | |
deposit :: Person -> Int -> Person | |
deposit (n,a,b) bal = (n,a,b + bal) | |
credit :: Bank -> [Person] | |
credit b = filter (\(_,_,bal) -> bal >= 0) b | |
equityAge :: Bank -> (Int, Int) -> Int | |
equityAge b (a1,a2) = sum [bal | (_,age,bal) <- b, (age >= a1) && (age <= a2)] | |
creditNI :: NI -> Market -> Int | |
creditNI n m = sum [bal | (ni,_,bal) <- concat m, ni == n] | |
bankFree :: Pop -> Market -> Pop | |
bankFree p m = p \\ [ni | (ni,_,_) <- concat m] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment