the algorith is there but not optimized
finished prob 24