Hacker News new | past | comments | ask | show | jobs | submit login

Garrett, thank you.

* * *

My inspiration for writing this came from watching 3Blue1Brown's YouTube video, "Simulating an epidemic":

https://www.youtube.com/watch?v=gxAaO2rsdIs

His simulations cover several scenarios:

- Simulating social distancing.

- Having people travel to a central location (e.g. a grocery store).

- What if the government is able to identify and isolate cases?

- Simulating multiple communities with travel, that put quarantine measures in place.

- What happens when people get tired of social distancing.

* * *

Thanks for sharing your code.

I see that you are using gnuplot to visualize the output of the script. Have you considered using the csv module (https://docs.python.org/3/library/csv.html) to output the data, instead of using the print() function? That way, you wouldn't have to manually add in spaces around the data and stringify the numeric data.

  >>> import csv, sys
  >>> writer = csv.writer(sys.stdout, delimiter=" ")
  >>> writer.writerow(["#", "T", "S", "I", "R"])
  # T S I R
In the script, usage would look something like this:

  import csv
  import sys
  
  ...
  
  writer = csv.writer(sys.stdout, delimiter=" ")
  
  writer.writerow(["#", "T", "S", "I", "R"])
  writer.writerow([T, S, I, R])
  while I > 1000:
  
      ...
  
      writer.writerow([T, S, I, R])



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: