Skip to content

Instantly share code, notes, and snippets.

@jaw6
Created April 14, 2015 01:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaw6/b5fff9e0c65b2c9fb039 to your computer and use it in GitHub Desktop.
Save jaw6/b5fff9e0c65b2c9fb039 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'csv'
def flip; rand(2) == 1; end
headers = ['year', '# male pres', '# female pres']
rows = []
250.times do |j|
years = 2016
men, women = 44, 0
balanced = false
i = 0
while !balanced && years < 9_000_000 do
i += 1
if flip # is woman?
women += 1
else
men += 1
end
if flip # is two-term?
years += 8
else
years += 4
end
if women > men
balanced = true
end
end
rows << [years, men, women]
end
rows.sort! { |a,b| a.first <=> b.first }
csv = CSV.generate do |csv|
csv << headers
rows.each { |row| csv << row }
end
print csv
avg = rows.inject(0) { |total,row| total += row.first } / 50
puts "Average: #{avg}"
We can make this file beautiful and searchable if this error is corrected: It looks like row 252 should actually have 3 columns, instead of 1. in line 251.
year,# male pres,# female pres
3540,147,148
3760,167,168
3800,168,169
3820,174,175
4216,205,206
4732,244,245
4756,254,255
4832,251,252
5064,278,279
5108,280,281
5300,301,302
5492,322,323
5496,308,309
5500,312,313
5516,319,320
5616,330,331
5624,321,322
5668,323,324
5684,329,330
6028,353,354
6468,399,400
6536,398,399
6668,402,403
6740,411,412
6784,414,415
6812,422,423
7236,456,457
7320,468,469
7640,489,490
7880,508,509
8004,514,515
8084,526,527
8148,525,526
8292,534,535
8564,569,570
8572,570,571
8592,563,564
9212,622,623
9404,632,633
9472,645,646
9644,658,659
9776,660,661
9828,663,664
10020,685,686
10472,735,736
10552,736,737
10564,736,737
10704,743,744
11044,770,771
11300,808,809
11672,824,825
11816,843,844
11944,838,839
11980,863,864
11988,860,861
12560,896,897
12772,916,917
13216,952,953
13268,955,956
13416,956,957
13556,1003,1004
13596,983,984
13616,999,1000
13676,988,989
13772,996,997
13916,1011,1012
14000,1019,1020
14036,1015,1016
14140,1031,1032
14620,1073,1074
14916,1096,1097
15228,1128,1129
15344,1127,1128
15444,1137,1138
15832,1168,1169
15864,1173,1174
15964,1188,1189
16072,1198,1199
16440,1219,1220
16580,1243,1244
16988,1278,1279
17056,1258,1259
17132,1276,1277
17988,1349,1350
18140,1355,1356
18356,1386,1387
18412,1387,1388
18424,1381,1382
18428,1398,1399
19032,1455,1456
19212,1452,1453
20280,1554,1555
20592,1562,1563
20616,1563,1564
20680,1576,1577
20736,1578,1579
20860,1599,1600
21256,1618,1619
22008,1685,1686
22472,1733,1734
22572,1750,1751
23164,1786,1787
23664,1820,1821
24932,1912,1913
25652,1984,1985
25732,1991,1992
25960,2019,2020
25980,2002,2003
26764,2076,2077
27300,2125,2126
27560,2152,2153
27568,2141,2142
28020,2184,2185
28152,2193,2194
30308,2386,2387
30460,2398,2399
31968,2532,2533
32436,2550,2551
32812,2580,2581
33244,2644,2645
34000,2688,2689
34376,2702,2703
34644,2714,2715
35000,2748,2749
36368,2888,2889
37176,2956,2957
37676,3005,3006
38036,3026,3027
39376,3134,3135
40120,3193,3194
40272,3212,3213
41272,3302,3303
41548,3321,3322
42216,3358,3359
42688,3412,3413
43812,3501,3502
44024,3507,3508
44124,3549,3550
44296,3544,3545
44744,3594,3595
44940,3592,3593
45008,3596,3597
45496,3665,3666
45696,3661,3662
46436,3745,3746
46784,3780,3781
48324,3876,3877
49288,3951,3952
49384,3968,3969
50060,4054,4055
50572,4074,4075
53096,4285,4286
53912,4356,4357
54512,4395,4396
60172,4868,4869
64604,5232,5233
65776,5349,5350
65984,5372,5373
66008,5352,5353
66168,5346,5347
68788,5636,5637
74452,6072,6073
74508,6066,6067
75828,6182,6183
77412,6301,6302
77756,6332,6333
77952,6292,6293
79040,6447,6448
80272,6527,6528
88104,7221,7222
89016,7278,7279
89648,7307,7308
92396,7583,7584
95396,7791,7792
95708,7842,7843
102772,8417,8418
105612,8623,8624
112868,9295,9296
113856,9335,9336
115460,9439,9440
123592,10178,10179
128328,10595,10596
128512,10570,10571
133204,10953,10954
133700,10985,10986
137288,11316,11317
139628,11517,11518
146164,12010,12011
146316,12019,12020
148876,12243,12244
150020,12368,12369
151864,12492,12493
161392,13319,13320
165068,13625,13626
175900,14509,14510
179284,14817,14818
185052,15291,15292
199324,16428,16429
215148,17805,17806
230952,19087,19088
270808,22434,22435
278068,23035,23036
281252,23278,23279
286532,23726,23727
300628,24902,24903
305684,25355,25356
342332,28448,28449
353824,29404,29405
362232,30029,30030
365516,30280,30281
365920,30381,30382
372732,30894,30895
442516,36772,36773
632384,52553,52554
726968,60423,60424
736280,61201,61202
799152,66448,66449
834088,69333,69334
877204,72923,72924
942232,78338,78339
977456,81265,81266
980436,81616,81617
987544,82130,82131
1011144,84068,84069
1025832,85178,85179
1145036,95142,95143
1237284,102885,102886
1258096,104758,104759
1328784,110642,110643
1559228,129793,129794
1642552,136774,136775
2199252,182869,182870
2353976,196096,196097
2596172,216046,216047
2801600,233180,233181
2804804,233694,233695
3917612,326279,326280
4498396,374947,374948
5186900,432049,432050
8257052,687822,687823
9000000,749654,749261
9000000,750276,749158
9000000,750831,749622
9000000,750601,749905
9000000,750895,748859
9000000,750398,749206
9000000,750534,749350
9000004,750886,749160
9000004,750770,749376
9000004,750484,749228
Average: 3124080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment