Skip to content

Instantly share code, notes, and snippets.

@Jeremiah-England
Created February 5, 2024 02:40
Show Gist options
  • Save Jeremiah-England/581ef35b04a127ad027a5d60d194c61e to your computer and use it in GitHub Desktop.
Save Jeremiah-England/581ef35b04a127ad027a5d60d194c61e to your computer and use it in GitHub Desktop.
Feminist Fertility Cult Simulation
import math
ATTRITION_RATE = 0.4
ADULT_AGE = 22
END_FERTILE_AGE = 42
DEATH_AGE = 75
PER_YEAR_PER_COUPLE = 1
SIM_YEARS = 200
age_to_pop: dict[int, float] = {22: 5}
years = [age_to_pop]
print("year", "adults", "children", "total")
for year in range(SIM_YEARS):
new_age_to_pop: dict[int, float] = {0: 0}
for age, population in age_to_pop.items():
if age >= DEATH_AGE:
continue # die off.
if age >= END_FERTILE_AGE:
new_age_to_pop[age + 1] = population
continue
if age >= ADULT_AGE:
new_pop = (
population
if age != ADULT_AGE or year == 0
else population * (1 - ATTRITION_RATE) # + min(year * 0.002, 0.2))
)
new_age_to_pop[age + 1] = new_pop
new_age_to_pop[0] += new_pop * PER_YEAR_PER_COUPLE / 2
else:
new_age_to_pop[age + 1] = population
age_to_pop = new_age_to_pop
years.append(age_to_pop)
pop = sum(new_age_to_pop.values())
adult_pop = sum(p for a, p in new_age_to_pop.items() if a >= ADULT_AGE)
print(year + 23, adult_pop, pop - adult_pop, pop)
# Calculate population growth rate in doubling times from the last n years
n = 80
start_year = years[-n]
end_year = years[-1]
ratio = sum(end_year.values()) / sum(start_year.values())
print(f"Population growth rate: {n / math.log2(ratio):0.4f} years to double")
# OUTPUT:
#
# year adults children total
# 23 5 2.5 7.5
# 24 5 5.0 10.0
# 25 5 7.5 12.5
# 26 5 10.0 15.0
# 27 5 12.5 17.5
# 28 5 15.0 20.0
# 29 5 17.5 22.5
# 30 5 20.0 25.0
# 31 5 22.5 27.5
# 32 5 25.0 30.0
# 33 5 27.5 32.5
# 34 5 30.0 35.0
# 35 5 32.5 37.5
# 36 5 35.0 40.0
# 37 5 37.5 42.5
# 38 5 40.0 45.0
# 39 5 42.5 47.5
# 40 5 45.0 50.0
# 41 5 47.5 52.5
# 42 5 50.0 55.0
# 43 5 50.0 55.0
# 44 5 50.0 55.0
# 45 7.5 47.5 55.0
# 46 9.0 45.75 54.75
# 47 10.5 44.75 55.25
# 48 12.0 44.5 56.5
# 49 13.5 45.0 58.5
# 50 15.0 46.25 61.25
# 51 16.5 48.25 64.75
# 52 18.0 51.0 69.0
# 53 19.5 54.5 74.0
# 54 21.0 58.75 79.75
# 55 22.5 63.75 86.25
# 56 24.0 69.5 93.5
# 57 25.5 76.0 101.5
# 58 27.0 83.25 110.25
# 59 28.5 91.25 119.75
# 60 30.0 100.0 130.0
# 61 31.5 109.5 141.0
# 62 33.0 119.75 152.75
# 63 34.5 130.75 165.25
# 64 36.0 142.5 178.5
# 65 35.0 157.5 192.5
# 66 35.0 171.75 206.75
# 67 35.0 185.25 220.25
# 68 35.75 197.25 233.0
# 69 36.95 207.97499999999997 244.92499999999998
# 70 38.6 217.65 256.25
# 71 40.7 226.5 267.2
# 72 43.25 234.75 278.0
# 73 46.25 242.625 288.875
# 74 49.7 250.35000000000002 300.05
# 75 53.599999999999994 258.15 311.74999999999994
# 76 52.95 266.25 319.2
# 77 57.75 274.875 332.625
# 78 63.0 284.25 347.25
# 79 68.7 294.6 363.3
# 80 74.85 306.15 380.99999999999994
# 81 81.45 319.125 400.575
# 82 88.5 333.75 422.25
# 83 96.0 350.25 446.25
# 84 103.95 368.85 472.8
# 85 112.35 389.7750000000001 502.12500000000006
# 86 121.2 414.00000000000006 535.2
# 87 130.5 441.7500000000002 572.2500000000002
# 88 138.75 474.7500000000001 613.5000000000001
# 89 146.55 512.5500000000002 659.1000000000001
# 90 153.89999999999998 554.7 708.6
# 91 161.025 600.5250000000001 761.5500000000001
# 92 168.05999999999997 649.4175000000001 817.4775000000001
# 93 175.14 700.8375000000001 875.9775000000001
# 94 182.4 754.3125 936.7125
# 95 189.97499999999997 809.4375 999.4125
# 96 197.99999999999997 865.875 1063.875
# 97 206.60999999999999 923.3549999999999 1129.965
# 98 215.93999999999997 981.6749999999996 1197.6149999999996
# 99 224.62499999999997 1040.6999999999998 1265.3249999999998
# 100 234.29999999999998 1100.3624999999995 1334.6624999999995
# 101 245.1 1160.6624999999997 1405.7624999999996
# 102 257.15999999999997 1221.667499999999 1478.8274999999992
# 103 270.615 1283.5124999999994 1554.1274999999994
# 104 285.6 1346.3999999999996 1631.9999999999995
# 105 302.25 1410.5999999999997 1712.8499999999997
# 106 320.70000000000005 1476.4499999999996 1797.1499999999996
# 107 341.08500000000004 1544.3549999999996 1885.4399999999996
# 108 364.29 1614.0374999999997 1978.3274999999996
# 109 390.15000000000003 1686.7124999999996 2076.8624999999997
# 110 418.8 1763.6625000000001 2182.4625
# 111 449.7 1846.912500000001 2296.612500000001
# 112 482.58 1938.2850000000017 2420.8650000000016
# 113 517.17 2039.4000000000015 2556.5700000000015
# 114 553.2675 2151.6075000000014 2704.8750000000014
# 115 590.7104999999999 2276.0077500000016 2866.7182500000013
# 116 629.3774999999998 2413.4715000000015 3042.8490000000015
# 117 669.1874999999999 2564.6602500000013 3233.8477500000013
# 118 710.0999999999997 2730.0465000000013 3440.1465000000007
# 119 753.6149999999998 2909.9340000000007 3663.5490000000004
# 120 798.2729999999998 3104.478000000001 3902.7510000000007
# 121 844.1549999999997 3313.7055 4157.8605
# 122 890.9324999999998 3537.535499999998 4428.467999999998
# 123 938.7674999999997 3775.799249999998 4714.566749999998
# 124 987.8624999999997 4028.260499999998 5016.122999999998
# 125 1038.4604999999997 4294.635749999998 5333.096249999998
# 126 1090.8449999999998 4574.614499999998 5665.459499999997
# 127 1145.3399999999997 4867.879499999997 6013.219499999997
# 128 1202.3099999999997 5174.126999999998 6376.436999999997
# 129 1262.1599999999999 5492.861999999997 6755.021999999997
# 130 1325.3355 5823.643499999997 7148.9789999999975
# 131 1392.9975 6165.4297499999975 7558.427249999998
# 132 1466.0774999999999 6517.678499999998 7983.7559999999985
# 133 1545.5475 6880.367249999998 8425.914749999998
# 134 1632.1499999999999 7254.283499999998 8886.433499999997
# 135 1726.5059999999999 7640.9437499999985 9367.449749999998
# 136 1829.1150000000002 8042.512499999997 9871.627499999997
# 137 1940.3752499999998 8461.700999999994 10402.076249999993
# 138 2060.5959 8901.672074999995 10962.267974999995
# 139 2190.009150000001 9365.951024999995 11555.960174999997
# 140 2328.782400000001 9858.342599999996 12187.124999999998
# 141 2477.030400000001 10382.85405 12859.884450000001
# 142 2635.7274 10943.624250000003 13579.351650000002
# 143 2804.919300000001 11544.8589 14349.7782
# 144 2984.6358000000005 12190.7718 15175.4076
# 145 3174.767550000001 12885.5322 16060.29975
# 146 3375.2133000000003 13633.218224999993 17008.431524999993
# 147 3585.8920500000004 14437.776374999996 18023.668424999996
# 148 3806.7552000000005 15302.987099999988 19109.742299999987
# 149 4037.7987000000003 16232.436449999994 20270.235149999993
# 150 4279.075199999998 17229.493799999993 21508.568999999992
# 151 4530.481199999998 18297.52064999999 22828.00184999999
# 152 4792.084199999999 19439.3655 24231.449699999997
# 153 5064.044849999998 20657.359799999995 25721.404649999993
# 154 5347.034099999999 21952.914975 27299.949074999997
# 155 5642.083349999999 23326.733024999994 28968.816374999995
# 156 5950.596599999999 24779.023199999996 30729.619799999993
# 157 6274.261349999999 26309.825999999994 32584.087349999994
# 158 6614.999999999999 27919.306800000006 34534.306800000006
# 159 6974.921249999999 29608.019099999998 36582.94035
# 160 7356.277574999997 31377.131325000006 38733.4089
# 161 7761.426344999998 33228.61899750002 40990.04534250002
# 162 8192.344589999999 35165.42410500002 43357.76869500002
# 163 8651.497409999998 37191.58348500002 45843.080895000014
# 164 9141.360029999996 39312.328050000026 48453.68808000002
# 165 9664.798499999995 41534.15467500002 51198.95317500002
# 166 10224.644039999997 43864.87257000002 54089.51661000002
# 167 10823.676029999997 46313.62596000001 57137.30199000001
# 168 11464.568144999997 48890.894895000005 60355.46304
# 169 12149.878634999997 51608.4760125 63758.354647500004
# 170 12882.044249999997 54479.445075 67361.489325
# 171 13663.377809999996 57518.103104999966 71181.48091499996
# 172 14496.06942 60739.97543999998 75236.04485999998
# 173 15382.191329999998 64161.73053 79543.92186
# 174 16323.436439999996 67801.3578 84124.79423999999
# 175 17321.23845 71677.8639 88999.10235
# 176 18376.787654999996 75810.96166500002 94187.74932000002
# 177 19491.252884999998 80220.55110750002 99711.80399250002
# 178 20665.926089999997 84926.28789000002 105592.21398000001
# 179 21902.370569999992 89947.24110000004 111849.61167000003
# 180 23202.53639999999 95301.67860000001 118504.21500000001
# 181 24568.857629999995 101006.96901750003 125575.82664750003
# 182 26004.331259999995 107079.58944 133083.9207
# 183 27512.579812499996 113535.22605750001 141047.80587
# 184 29097.89859599999 120388.95554175004 149486.85413775002
# 185 30764.88375299999 127655.49549824996 158420.37925124995
# 186 32518.857185999987 135349.51287374998 167868.37005974996
# 187 34365.874455 143485.97974874993 177851.85420374994
# 188 36312.883740000005 152080.5664912499 188393.4502312499
# 189 38367.712962 161150.0627947499 199517.77575674988
# 190 40539.048156 170712.8176702499 211251.8658262499
# 191 42836.3920395 180789.19000874992 223625.58204824993
# 192 45270.01602 191402.0018774999 236672.0178974999
# 193 47850.906735000004 202576.9872599999 250427.8939949999
# 194 50590.77571800001 214343.16199649993 264933.93771449995
# 195 53501.971284000014 226733.3449784998 280235.31626249984
# 196 56597.41522800001 239784.65619749995 296382.0714255
# 197 59890.335930000016 253539.18904499995 313429.52497499995
# 198 63394.08246000001 268044.52830749995 331438.61076749995
# 199 67121.93977649999 283354.1098469999 350476.0496234999
# 200 71087.03723700001 299527.32737924997 370614.36461625
# 201 75302.315064 316629.4217062498 391931.73677024984
# 202 79780.54986 334731.1883062498 414511.7381662498
# 203 84534.4275075 353908.5524887498 438442.9799962498
# 204 89576.65689299999 374242.0574947498 463818.7143877498
# 205 94920.252894 395816.30709524977 490736.5599892498
# 206 100578.57761475 418719.3998669998 519297.97748174984
# 207 106565.53918455001 443042.38811452506 549607.9272990751
# 208 112895.56476045 468878.79036150017 581774.3551219502
# 209 119583.82870424999 496324.18245262484 615908.0111568748
# 210 126646.48823174999 525475.8885892499 652122.3768209999
# 211 134100.98291025002 556432.7900681249 690533.7729783749
# 212 141966.33320835 589295.2661027999 731261.5993111499
# 213 150263.43438014993 624165.277881375 774428.712261525
# 214 159015.33864899992 661146.6039525 820161.9426015
# 215 168247.52262899993 700345.2118837499 868592.7345127498
# 216 177988.13725049986 741869.78890275 919857.9261532499
# 217 188268.33903389992 785832.3301617001 974100.6691956001
# 218 199122.55888409988 832348.97448525 1031471.5333693499
# 219 210588.74715599985 881541.0828450007 1092129.8300010005
# 220 222708.4720694999 933536.6742262502 1156245.14629575
# 221 235526.91898049985 988472.1463514998 1223999.0653319997
# 222 249092.78974244988 1046494.2069755996 1295586.9967180495
# Population growth rate: 12.3144 years to double
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment