first solution that seems plausible, if slow; not submitted yet