Skip to content

Instantly share code, notes, and snippets.

@meikj
Created January 9, 2014 20:32
Show Gist options
  • Save meikj/8341478 to your computer and use it in GitHub Desktop.
Save meikj/8341478 to your computer and use it in GitHub Desktop.
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