Another PowerShell Math Challenge

The Chairman is back with another set of math-related challenges. These types of challenges are a good way to get your brain looking at a problem from a different angle. This challenge includes 2 problems. One aimed more for intermediate level PowerShell scripters and one that might be a little more advanced.

Intermediate Level

Given a value like this:

$i = 2568

What is the total sum of all the individual integers? That is to say


Write a function that will accept a value and return the sum.

Bonus Elements

  • Limit the length of the number to 10 digits
  • Include Verbose output to show the operation
  • Write a variation on the function that writes an object to the pipeline that shows the original number, the number of individual elements and the sum.

Advanced Level

Given a value like this:

$a = 2,5,6

What are all the unique non-sums using all possible combinations. For example:

2+5 = 7
2+5+6 = 13
2+6 = 8
5+6 = 11

Write a PowerShell function or set of functions that will return a unique, and ordered list of sums based on the array. The array should have no more than 9 elements and use values 1-9 in the array.

Bonus Elements

  • Add parameter validation on the array length
  • Include Verbose output to show the operation

As usual, please submit links to your work and solutions and not the answer itself.

7 Replies to “Another PowerShell Math Challenge”

Comments are closed.