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
import importlib | |
import pkgutil | |
def globimport(pattern): | |
base, found, rest = pattern.partition('*') | |
try: | |
module = importlib.import_module(base.rstrip('.')) | |
except ImportError: | |
pass |
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
def equi(l): | |
"""Finds the equilibirum point in a list `l`. | |
The equilibrium point is the index within the list where the sum of | |
elements to the left is equal to the sum of the elements to the right. | |
Args: | |
l (list): A list of integers. | |
Returns: |
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
import Data.List | |
-- | Find the index corresponding to the equilibrium point of a | |
-- list. This is where the sum of the values to the left of the | |
-- index equals the sum of the values to the right. | |
equi :: [Int] -> Maybe Int | |
equi xs = findIndex match $ scanl (+) 0 xs | |
where match x = x * 2 == sum xs |