add 2010 census results
This commit is contained in:
parent
9ca60febac
commit
1d6ec55612
52
data/electoral-college-votes-2010-census.csv
Normal file
52
data/electoral-college-votes-2010-census.csv
Normal 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 +1,2 @@
|
||||||
https://www.archives.gov/electoral-college/allocation
|
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
16
main.go
|
@ -24,14 +24,14 @@ type VotesForEachParty struct {
|
||||||
// type src = *rand.Rand
|
// type src = *rand.Rand
|
||||||
|
|
||||||
/* Globals */
|
/* 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 */
|
/* Load data from csvs */
|
||||||
func readStates() ([]State, error) {
|
func readStates() ([]State, error) {
|
||||||
var states map[string]State = make(map[string]State)
|
var states map[string]State = make(map[string]State)
|
||||||
|
|
||||||
/* Electoral college votes for the 2024 election*/
|
/* 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 {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening the votes file: %v", err)
|
return nil, fmt.Errorf("error opening the votes file: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,6 @@ func readStates() ([]State, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error opening the results file for %s: %v", year, err)
|
return nil, fmt.Errorf("error opening the results file for %s: %v", year, err)
|
||||||
}
|
}
|
||||||
defer results_file.Close()
|
|
||||||
resultsReader := csv.NewReader(results_file)
|
resultsReader := csv.NewReader(results_file)
|
||||||
if _, err := resultsReader.Read(); err != nil { // Skip header
|
if _, err := resultsReader.Read(); err != nil { // Skip header
|
||||||
return nil, fmt.Errorf("error reading results header for %s: %v", year, err)
|
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
|
data.VictoriousPartyPerElection[year] = party
|
||||||
states[state] = data
|
states[state] = data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
results_file.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert statesData map to a slice for returning
|
// Convert statesData map to a slice for returning
|
||||||
|
@ -103,7 +104,7 @@ func sampleFromState(state State) VotesForEachParty {
|
||||||
// 2012: R
|
// 2012: R
|
||||||
// 2016: R
|
// 2016: R
|
||||||
// 2020: Split, 1 D, 4 R
|
// 2020: Split, 1 D, 4 R
|
||||||
p_split := float64(2 / 6)
|
p_split := 2.0 / 6.0
|
||||||
if r.Float64() < p_split {
|
if r.Float64() < p_split {
|
||||||
return VotesForEachParty{Democrats: 1, Republicans: 4}
|
return VotesForEachParty{Democrats: 1, Republicans: 4}
|
||||||
} else {
|
} else {
|
||||||
|
@ -116,7 +117,7 @@ func sampleFromState(state State) VotesForEachParty {
|
||||||
// 2012: D
|
// 2012: D
|
||||||
// 2016: Split: 3 D, 1 R
|
// 2016: Split: 3 D, 1 R
|
||||||
// 2020: 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 {
|
if r.Float64() < p_split {
|
||||||
return VotesForEachParty{Democrats: 3, Republicans: 1}
|
return VotesForEachParty{Democrats: 3, Republicans: 1}
|
||||||
} else {
|
} else {
|
||||||
|
@ -158,7 +159,8 @@ func simulateElection(states []State) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fmt.Printf("\nDemocrat seats: %d\n", republican_seats)
|
// fmt.Printf("\nDemocrat seats: %d\n", republican_seats)
|
||||||
if republican_seats > 270 {
|
fmt.Printf(" (%d) ", republican_seats)
|
||||||
|
if republican_seats >= 270 {
|
||||||
return 1
|
return 1
|
||||||
} else {
|
} else {
|
||||||
return 0
|
return 0
|
||||||
|
@ -176,7 +178,7 @@ func main() {
|
||||||
n_sims := 100_000
|
n_sims := 100_000
|
||||||
|
|
||||||
p_republicans := 0.0
|
p_republicans := 0.0
|
||||||
for _ = range n_sims {
|
for i := 0; i < n_sims; i++ {
|
||||||
result := simulateElection(states)
|
result := simulateElection(states)
|
||||||
fmt.Printf("Election result: %d\n", result)
|
fmt.Printf("Election result: %d\n", result)
|
||||||
if result == 1 {
|
if result == 1 {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user