Skip to content

Instantly share code, notes, and snippets.

@MatthewWilkes
Created September 17, 2019 09:10
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 MatthewWilkes/ff1e430015cbbc5f257f6639f2aec713 to your computer and use it in GitHub Desktop.
Save MatthewWilkes/ff1e430015cbbc5f257f6639f2aec713 to your computer and use it in GitHub Desktop.
import fractions
for num_pads in range(15):
options = {num_pads: fractions.Fraction(1)}
for pad in range(num_pads-1, 0, -1):
free_pads = [p for p in range(num_pads+1) if p > pad]
path_lengths = []
for free_pad in free_pads:
path_lengths.append(options[free_pad] + 1)
options[pad] = sum(path_lengths) / len(path_lengths)
print("{} pads: {} hops".format(num_pads, sum(options.values()) / len(options)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment