Skip to content

Instantly share code, notes, and snippets.

@newjam
Last active December 20, 2015 00:48
Show Gist options
  • Save newjam/6044035 to your computer and use it in GitHub Desktop.
Save newjam/6044035 to your computer and use it in GitHub Desktop.
{-
Income quintiles in 2011. This represents the poorest fifth to the richest fifth
of income earners in america in 2001.
-}
income2011 = [15282.0, 37556.0, 61032.0, 93232.0, 197932.0]
{-
Find the average income of americans, by averaging the quintiles.
Useful functions:
* sum: takes a list of numbers and returns their sum.
* length: takes a list and returns its length, obviously.
-}
myAverage x = sum x / (realToFrac (length x))
{-
Find the ratio between the highest fifth and the lowest fifth of the income earners for 2011.
useful functions:
* head: get the first element of a list
* last: get the last element of a list
-}
disparity2011 = (last income2011) / (head income2011)
{-
Prelude> disparity2011
12.951969637482005
That is, the richest fifth made 13 times more than the poorest fifth in 2011.
Write a function that does that given any year
-}
richPoorRatio y = (last y) / (head y)
{-
find out how much ratio of incomes between the highest fifth and the lowest fifth has changed from 1966 to 2011.
-}
income1966 = [2345.0, 5206.0, 7449.0, 9972.0, 17019.0]
changeFrom1966to2012 = richPoorRatio income2011 / richPoorRatio income1966
{-
Prelude> changeFrom1966to2012
1.784615359298155
Income disparity has increase 78% in the last 44 years
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment