add 2010 census results

This commit is contained in:
NunoSempere 2024-04-13 20:37:55 -04:00
parent 9ca60febac
commit 1d6ec55612
3 changed files with 62 additions and 7 deletions

View File

@ -0,0 +1,52 @@
State,Votes
Alabama,9
Alaska,3
Arizona,11
Arkansas,6
California,55
Colorado,9
Connecticut,7
Delaware,3
District of Columbia,3
Florida,29
Georgia,16
Hawaii,4
Idaho,4
Illinois,20
Indiana,11
Iowa,6
Kansas,6
Kentucky,8
Louisiana,8
Maine,4
Maryland,10
Massachusetts,11
Michigan,16
Minnesota,10
Mississippi,6
Missouri,10
Montana,3
Nebraska,5
Nevada,6
New Hampshire,4
New Jersey,14
New Mexico,5
New York,29
North Carolina,15
North Dakota,3
Ohio,18
Oklahoma,7
Oregon,7
Pennsylvania,20
Rhode Island,4
South Carolina,9
South Dakota,3
Tennessee,11
Texas,38
Utah,6
Vermont,3
Virginia,13
Washington,12
West Virginia,5
Wisconsin,10
Wyoming,3
1 State Votes
2 Alabama 9
3 Alaska 3
4 Arizona 11
5 Arkansas 6
6 California 55
7 Colorado 9
8 Connecticut 7
9 Delaware 3
10 District of Columbia 3
11 Florida 29
12 Georgia 16
13 Hawaii 4
14 Idaho 4
15 Illinois 20
16 Indiana 11
17 Iowa 6
18 Kansas 6
19 Kentucky 8
20 Louisiana 8
21 Maine 4
22 Maryland 10
23 Massachusetts 11
24 Michigan 16
25 Minnesota 10
26 Mississippi 6
27 Missouri 10
28 Montana 3
29 Nebraska 5
30 Nevada 6
31 New Hampshire 4
32 New Jersey 14
33 New Mexico 5
34 New York 29
35 North Carolina 15
36 North Dakota 3
37 Ohio 18
38 Oklahoma 7
39 Oregon 7
40 Pennsylvania 20
41 Rhode Island 4
42 South Carolina 9
43 South Dakota 3
44 Tennessee 11
45 Texas 38
46 Utah 6
47 Vermont 3
48 Virginia 13
49 Washington 12
50 West Virginia 5
51 Wisconsin 10
52 Wyoming 3

View File

@ -1 +1,2 @@
https://www.archives.gov/electoral-college/allocation
https://www.npr.org/2021/04/26/983082132/census-to-release-1st-results-that-shift-electoral-college-house-seats

16
main.go
View File

@ -24,14 +24,14 @@ type VotesForEachParty struct {
// type src = *rand.Rand
/* Globals */
var r = rand.New(rand.NewPCG(uint64(1), uint64(2)))
var r = rand.New(rand.NewPCG(uint64(100), uint64(2224)))
/* Load data from csvs */
func readStates() ([]State, error) {
var states map[string]State = make(map[string]State)
/* Electoral college votes for the 2024 election*/
votes_file, err := os.Open("data/electoral-college-votes.csv")
votes_file, err := os.Open("data/electoral-college-votes-2010-census.csv")
if err != nil {
return nil, fmt.Errorf("error opening the votes file: %v", err)
}
@ -64,7 +64,6 @@ func readStates() ([]State, error) {
if err != nil {
return nil, fmt.Errorf("error opening the results file for %s: %v", year, err)
}
defer results_file.Close()
resultsReader := csv.NewReader(results_file)
if _, err := resultsReader.Read(); err != nil { // Skip header
return nil, fmt.Errorf("error reading results header for %s: %v", year, err)
@ -83,6 +82,8 @@ func readStates() ([]State, error) {
data.VictoriousPartyPerElection[year] = party
states[state] = data
}
results_file.Close()
}
// Convert statesData map to a slice for returning
@ -103,7 +104,7 @@ func sampleFromState(state State) VotesForEachParty {
// 2012: R
// 2016: R
// 2020: Split, 1 D, 4 R
p_split := float64(2 / 6)
p_split := 2.0 / 6.0
if r.Float64() < p_split {
return VotesForEachParty{Democrats: 1, Republicans: 4}
} else {
@ -116,7 +117,7 @@ func sampleFromState(state State) VotesForEachParty {
// 2012: D
// 2016: Split: 3 D, 1 R
// 2020: Split, 3 D, 1 R
p_split := float64(2 / 6)
p_split := 2.0 / 6.0
if r.Float64() < p_split {
return VotesForEachParty{Democrats: 3, Republicans: 1}
} else {
@ -158,7 +159,8 @@ func simulateElection(states []State) int {
}
// fmt.Printf("\nDemocrat seats: %d\n", republican_seats)
if republican_seats > 270 {
fmt.Printf(" (%d) ", republican_seats)
if republican_seats >= 270 {
return 1
} else {
return 0
@ -176,7 +178,7 @@ func main() {
n_sims := 100_000
p_republicans := 0.0
for _ = range n_sims {
for i := 0; i < n_sims; i++ {
result := simulateElection(states)
fmt.Printf("Election result: %d\n", result)
if result == 1 {