This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import division, print_function | |
from itertools import permutations, combinations_with_replacement, product | |
def guarded_exponentiation(a,b): | |
""" | |
Raise a to the power of b, but only if the result won't be silly large, as | |
silly largeness slows us way down. | |
""" | |
if (a > 1 or a < -1) and b > 1000: | |
raise OverflowError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Simulation of the 'Can you cross the river' riddler problem: | |
# https://fivethirtyeight.com/features/night-falls-a-storm-rolls-in-can-you-cross-the-river/ | |
# | |
# n | |
# / | \ | |
# a - b - c | |
# | | | | |
# d - e - f | |
# \ | / |
OlderNewer