Skip to main content
2 of 2
added 143 characters in body
vnp
  • 57.3k
  • 4
  • 51
  • 140

As far as I know Project Euler problems, a brute force approach just doesn't work. So, we shouldn't code code, but rather an algorithm review.

An immediate thing coming to mind is that you test too many knowingly impossible combinations of a and b. They together must be composed of different digits, which you may test prior to multiplication.

My suggestion would be to create an iterator supplying numbers composed by different digits (from a given set - for b the digit set doesn't include digits used in a), and test the product being composed by what's left.

That may give you a significant speedup. May be, more math insight is required.

PS: once digits for a are selected, you may limit the range in which a product may fall, which in turn limits the possible range for b.

vnp
  • 57.3k
  • 4
  • 51
  • 140