## Programming Praxis – House Of Representatives

In today’s Programming Praxis exercise, our goal is to calculate the amount of seats each state gets in the United States House of Representatives. Let’s get started, shall we?

Some imports:

```import Control.Arrow
import qualified Data.List.Key as K
import qualified Data.Map as M```

To calculate the seat distribution we need the population data for each state.

```popData :: M.Map String Integer
("Arizona",6392017), ("Arkansas",2915918), ("California",37253956),
("Florida",18801310), ("Georgia",9687653), ("Hawaii",1360301),
("Idaho",1567582), ("Illinois",12830632), ("Indiana",6483802),
("Iowa",3046355), ("Kansas",2853118), ("Kentucky",4339367),
("Louisiana",4533372), ("Maine",1328361), ("Maryland",5773552),
("Massachusetts",6547629), ("Michigan",9883640), ("Minnesota",5303925),
("Mississippi",2967297), ("Missouri",5988927), ("Montana",989415),
("New Jersey",8791894), ("New Mexico",2059179), ("New York",19378102),
("North Carolina",9535483), ("North Dakota",672591), ("Ohio",11536504),
("Oklahoma",3751351), ("Oregon",3831074), ("Pennsylvania",12702379),
("Rhode Island",1052567), ("South Carolina",4625364), ("South Dakota",814180),
("Tennessee",6346105), ("Texas",25145561), ("Utah",2763885),
("Vermont",625741), ("Virginia",8001024), ("Washington",6724540),
("West Virginia",1852994), ("Wisconsin",5686986), ("Wyoming",563626)]```

The algorithm itself is fairly simple. Start with one seat per state and then keep assigning one seat to the state with the highest geometric mean until the desired number of seats is reached.

```house :: Int -> M.Map String Integer
house seats = M.map fst \$ iterate add (M.map ((,) 1) popData) !! k where
```main :: IO ()