working version for small, too slow for large
more efficient version working for small
with memoization
fixing small bug
working for first large set (kinda slow tho)
adding some comments