PowerShell and Math Homework

Using PowerShell to check math homework and be an easy and rewarding task.

My 10 year daughter asked me to check her math homework tonight. Math was my best subject in school, but that was a long time ago. The assignment that she had was to find if several of numbers where divisible by 2, 3, 4, and 5. I started to look at it this and said that I could write a computer script to check the answers.

Flash forward, a few eye rolls and groans later, I’m now sitting in front of the family computer and punching way at the keyboard. It didn’t take long for me to have the script typed out in PowerShell and running it to show that her dad knows a thing or two.

$report = @()
$numbers = 34,68,50,258,275,432,637,726,945,1652,1974,1683,2759,5428,9472
$divided = 2,3,4,5

foreach ($number in $numbers){
    $line = "" | Select Number, "2", "3", "4", "5"
    $line.Number = $number
    $line."2" = (($number / 2) -is [int])
    $line."3" = (($number / 3) -is [int])
    $line."4" = (($number / 4) -is [int])
    $line."5" = (($number / 5) -is [int])
    $report += $line
$report | Ft

So after the script ran, not even a second later we were checking the homework. I could tell that she was amazed that I was able to finish the math work in seconds. It was even a better feeling as we both read the answers, me from the computer screen and her from her homework.

Number     2     3     4     5
------     -     -     -     -
    34  True False False False
    68  True False  True False
    50  True False False  True
   258  True  True False False
   275 False False False  True
   432  True  True  True False
   637 False False False False
   726  True  True False False
   945 False  True False  True
  1652  True False  True False
  1974  True  True False False
  1683 False  True False False
  2759 False False False False
  5428  True False  True False
  9472  True False  True False

She asked me how this worked, but as I started to explain how the script worked, I noticed her eyes glazed over and she started to walk away. Now that she knows I can do awesome things with the computer, maybe I can get her help her with other math issues.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.