My partly working non-efficient code for reducible.py