Skip to content

Instantly share code, notes, and snippets.

@mcsee
Last active February 29, 2024 03:35
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 mcsee/ec7035f1f818db309662460fc8a59d96 to your computer and use it in GitHub Desktop.
Save mcsee/ec7035f1f818db309662460fc8a59d96 to your computer and use it in GitHub Desktop.
<?
final class City {
public function interactionBetween($somePerson, $anotherPerson) {
if ($this->meetingProbability() < random()) {
return null; // no interaction
} else {
return new PersonToPersonInteraction($somePerson, $anotherPerson);
}
}
}
final class PersonToPersonInteraction {
public function propagate($aVirus) {
if ($this->somePerson->isInfectedWith($aVirus)
&& $aVirus->infectionProbability() > random()) {
$this->anotherPerson->getInfectedWith($aVirus);
}
}
}
$covid19 = new Virus();
$janeDoe = new Person();
$johnSmith = new Person();
$wuhan = new City();
$interaction = $wuhan->interactionBetween($johnSmith, $janeDoe);
if ($interaction != null) {
$interaction->propagate($covid19);
}
/* In this example we modeled the interaction
between an infected person and a healthy one.
Jane is healthy but might be infected
if Virus R0 applies to her. */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment