fork download
  1. nums = [ [2018 + j*10] + 4*[0] for j in range(11) ]
  2.  
  3. # 0 the numbers represent year
  4. # 1 out of fertile window people
  5. # 2 fertile population
  6. # 3 children
  7. # 4 newborns
  8.  
  9. for i, j in enumerate(nums):
  10. if i == 0:
  11. nums[0] = [2018, 0, 7, 0, 0]
  12. print(nums[i])
  13. continue
  14. # the if takes care of people going out of the fertility window
  15. if i > 2:
  16. # fertile people are previous + people who became fertile 30 years ago
  17. nums[i][1] = nums[i-1][1] + (nums[i-3][2] - nums[i-4][2])
  18. # the fertile people are previous - those who became fertile 30 years ago
  19. nums[i][2] = nums[i-1][2] - (nums[i-3][2] - nums[i-4][2])
  20. # fertile people are fertile + previous children
  21. nums[i][2] = nums[i-1][2] + nums[i-1][3]
  22. # children are previous newborns
  23. nums[i][3] = nums[i-1][4]
  24. # newborns are 140% of the fertile people
  25. nums[i][4] = round(nums[i-1][2] * 1.4)
  26. print(nums[i])
  27.  
Success #stdin #stdout 0.02s 6936KB
stdin
Standard input is empty
stdout
[2018, 0, 7, 0, 0]
[2028, 0, 7, 0, 10.0]
[2038, 0, 7, 10.0, 10.0]
[2048, 7, 17.0, 10.0, 10.0]
[2058, 7, 27.0, 10.0, 24.0]
[2068, 7, 37.0, 24.0, 38.0]
[2078, 17.0, 61.0, 38.0, 52.0]
[2088, 27.0, 99.0, 52.0, 85.0]
[2098, 37.0, 151.0, 85.0, 139.0]
[2108, 61.0, 236.0, 139.0, 211.0]
[2118, 99.0, 375.0, 211.0, 330.0]