Skip to content

Instantly share code, notes, and snippets.

View mdomke's full-sized avatar
💭
foobar

Martin Domke mdomke

💭
foobar
View GitHub Profile
@mdomke
mdomke / globimport.py
Last active April 4, 2018 15:25
Python glob import
import importlib
import pkgutil
def globimport(pattern):
base, found, rest = pattern.partition('*')
try:
module = importlib.import_module(base.rstrip('.'))
except ImportError:
pass
@mdomke
mdomke / equi.py
Last active May 19, 2017 19:16
equi function in python
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:
@mdomke
mdomke / equi.hs
Last active February 25, 2017 23:35
equi function in haskell
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