slowest implementation of prob 43 in js ever.