this should do it
first draft, fails on repeated numbers