rewrite supply to use perm and binary search