Skip to content

Instantly share code, notes, and snippets.

@svineet
Created April 11, 2020 17:55
Show Gist options
  • Save svineet/1c3e472c4abcbb048dcadd586edc8c8c to your computer and use it in GitHub Desktop.
Save svineet/1c3e472c4abcbb048dcadd586edc8c8c to your computer and use it in GitHub Desktop.
import math
DEBUG = False
def generate_input_sample(params):
population = COVIDPopulation(params["N"], params["K"])
return population
def covid_binary_search(population, start, end, costly):
if start > end: return
# Test this whole population segment
# Practically speaking, mix blood and do the COVID test
if DEBUG: print(f"Testing: {start} to {end}")
costly()
if not population.is_infected(start, end):
return
# No more splitting if start == end. We just tested an individual.
if start == end: return
# Split into two segments [start, mid] and [mid+1, end]
mid = math.floor((start+end)/2)
covid_binary_search(population, start, mid, costly)
covid_binary_search(population, mid+1, end, costly)
def covid_binary_search_wrapper(input_sample, costly):
population = input_sample
n = population.N
return covid_binary_search(population, 0, n-1, costly)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment