Working solution for #12, way too slow