Share via


PowerShell Diversion #4: Can You Count on PowerShell?

Here’s a problem that is more abstract and a bit trickier than the previous ‘diversions’.  It doesn’t require anything very sophisticated or obscure in terms of PowerShell, but might take a bit of extra thought on how to construct your solution.

Recently I say the following tweet from @standupmaths:

Multiple two two-digit numbers to get a four-digit answer. ab × cd = efgh Can you find one with all eight digits different?

As it happens there are quite a few solutions to this problem.  Can you use PowerShell to find them? 

Some things to work out:

  1. How many solutions are there if you allow EFGH to have leading zeros (e.g. ‘12 x 12 = 0144’) and consider ‘AB x CD’ to be distinct from ‘CD x AB’?
  2. How many solutions are there if you disallow leading zeros in EFGH?  Why are leading zeros for ‘AB’ and ‘CD’ not a consideration?
  3. How many solutions are there is you disallow leading zeros for EFGH and consider ‘AB x CD’ to be the same as ‘CD x AB’?
  4. What are the largest and smallest values of EFGH (with and without leading zeros)?

Hints, if you need them.