I think I came up with an alg that works, in docs