small refactor

This commit is contained in:
NunoSempere 2024-04-14 15:12:49 -04:00
parent 1c1c32a83d
commit 0405e3815c

19
main.go
View File

@ -380,16 +380,7 @@ func simulateElection(states []State) int {
election_sample := sampleFromState(state) election_sample := sampleFromState(state)
republican_seats += election_sample.Republicans republican_seats += election_sample.Republicans
} }
return republican_seats
if dev {
fmt.Printf("\n\n(%d) ", republican_seats)
}
if republican_seats >= 270 {
return 1
} else {
return 0
}
} }
func main() { func main() {
@ -405,13 +396,11 @@ func main() {
p_republicans := 0.0 p_republicans := 0.0
for i := 0; i < n_sims; i++ { for i := 0; i < n_sims; i++ {
result := simulateElection(states) republican_seats := simulateElection(states)
if dev { if republican_seats >= 270 {
fmt.Printf("Election result: %d", result)
}
if result == 1 {
p_republicans++ p_republicans++
} }
fmt.Printf("%d - %t\n", republican_seats, republican_seats >= 270)
} }
p_republicans = p_republicans / float64(n_sims) p_republicans = p_republicans / float64(n_sims)
fmt.Printf("\n\n\n%% republicans: %f\n", p_republicans) fmt.Printf("\n\n\n%% republicans: %f\n", p_republicans)