Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # .SYNOPSIS
- # Generate math worksheets randomly.
- #
- # .DESCRIPTION
- # Used to generate addition, subtraction, and multiplication worksheets. Can generate math problems that are
- # 1, 2, or 3 digits long. The Carry switch determines if 'number carrying' is used or not.
- #
- # .PARAMETER Digits
- # Specifies the number of digits to use for the math problems. Minimum value is 1. Maximum value is 3. Default is 1.
- #
- # .PARAMETER Operation
- # Specifies the operation for the generated math problems. Valid selections are: Addition, Subtraction, or Multiplication.
- # When Multiplication is selected, only 4 rows of problems are generated in order to provide extra space for problem solving.
- #
- # If parameter value is not specified, Addition problems are generated.
- #
- # .PARAMETER Carry
- # Specifies that 'number carrying' operations can be used.
- #
- # .NOTES
- # Author: Joshua Beckman
- # Editor: Anthony Franca
- # Version: 2019.09.20
- # Purpose: Educational
- #
- # .LINK
- # https://www.dowst.dev/homework-double-digit-addition-without-carrying/
- param(
- [parameter(Mandatory = $false)]
- [ValidateRange(1,3)][int]$Digits = 1,
- [parameter(Mandatory = $false)]
- [ValidateSet("Addition","Subtraction","Multiplication")][string]$Operation = "Addition",
- [parameter(Mandatory = $false)]
- [switch]$Carry
- )
- [System.Collections.Generic.List[PSObject]] $page = @()
- $j = 0
- $blank120 = "<td height=""120""> </td>`n" * 9
- $blank75 = "<td height=""75""> </td>`n" * 9
- $blank52 = "<td height=""52""> </td>`n" * 9
- $blank20 = "<td height=""20""><br></td>`n" * 9
- If($Operation -eq "Addition" -OR $Operation -eq "Subtraction"){$Count = 5}
- If($Operation -eq "Multiplication"){$Count = 4}
- while($j -lt $Count){
- [System.Collections.Generic.List[PSObject]] $rowA = @()
- [System.Collections.Generic.List[PSObject]] $rowB = @()
- $i=0
- while($i -lt 5){
- If($Digits -ge 1){
- $a = Get-Random -Minimum 1 -Maximum 10
- If($Operation -eq "Subtraction"){
- $b = Get-Random -Minimum 0 -Maximum $a
- }ElseIf($Operation -eq "Addition"){
- If($Carry -eq $true){
- $b = Get-Random -Minimum 0 -Maximum 10
- }Else{
- $b = Get-Random -Minimum 0 -Maximum (9-$a+1)
- }
- }ElseIf($Operation -eq "Multiplication"){
- $b = Get-Random -Minimum 1 -Maximum 10
- }
- }
- If($Digits -ge 2){
- $c = Get-Random -Minimum 1 -Maximum 10
- If($Operation -eq "Subtraction"){
- If($Carry -eq $true){
- $d = Get-Random -Minimum 0 -Maximum 10
- }Else{
- $d = Get-Random -Minimum 0 -Maximum $c
- }
- }ElseIf($Operation -eq "Addition"){
- If($Carry -eq $true){
- $d = Get-Random -Minimum 0 -Maximum 10
- }Else{
- $d = Get-Random -Minimum 0 -Maximum (9-$c+1)
- }
- }ElseIf($Operation -eq "Multiplication"){
- $d = Get-Random -Minimum 1 -Maximum 10
- }
- }
- If($Digits -ge 3){
- $e = Get-Random -Minimum 1 -Maximum 10
- If($Operation -eq "Subtraction"){
- If($Carry -eq $true){
- $f = Get-Random -Minimum 0 -Maximum 10
- }Else{
- $f = Get-Random -Minimum 0 -Maximum $e
- }
- }ElseIf($Operation -eq "Addition"){
- If($Carry -eq $true){
- $f = Get-Random -Minimum 0 -Maximum 10
- }Else{
- $f = Get-Random -Minimum 0 -Maximum (9-$e+1)
- }
- }ElseIf($Operation -eq "Multiplication"){
- $f = Get-Random -Minimum 1 -Maximum 10
- }
- }
- if(($b + $d) -gt 0){
- if($b -eq 0){$b=' '}
- $rowA.Add("<td class=""xl66"" height=""52"" width=""115"">$a$c$e</td>`n")
- If($Operation -eq "Addition"){
- $rowB.Add("<td class=""xl65"" height=""52"" width=""115"">+ $b$d$f</td>`n")
- }ElseIf($Operation -eq "Subtraction"){
- $rowB.Add("<td class=""xl65"" height=""52"" width=""115"">- $b$d$f</td>`n")
- }ElseIf($Operation -eq "Multiplication"){
- $rowB.Add("<td class=""xl65"" height=""52"" width=""115"">x $b$d$f</td>`n")
- }
- $i++
- }
- }
- $tableRows = New-Object System.Text.StringBuilder
- $tableRows.Append('<tr height="52">') | Out-Null
- $tableRows.Append($rowA -join('<td class="xl66" width="15"><br>')) | Out-Null
- $tableRows.Append('</tr><tr height="52">') | Out-Null
- $tableRows.Append($rowB -join('<td class="xl66" width="15"><br>')) | Out-Null
- If($Operation -eq "Multiplication"){
- $tableRows.Append("</tr><tr height=""52"">$blank120</tr>") | Out-Null
- }Else{
- $tableRows.Append("</tr><tr height=""52"">$blank75</tr>") | Out-Null
- }
- $page.Add($tableRows.ToString())
- $j++
- }
- If($Operation -eq "Addition"){
- $bodyTop = @'
- <html><head><title>Addition</title><style>.xl65{mso-style-parent:style0;font-size:36.0pt;mso-number-format:"\@";
- text-align:right;border-top:none;border-right:none;border-bottom:1.5pt solid blue;border-left:none;color:blue}
- .xl66{mso-style-parent:style0;font-size:36.0pt;mso-number-format:"\@";text-align:right;color:blue}</style></head><body>
- <table style="text-align: left; width: 635px; height: 60px;" border="0" cellpadding="0" cellspacing="0"><tbody>
- '@
- }ElseIf($Operation -eq "Subtraction"){
- $bodyTop = @'
- <html><head><title>Subtraction</title><style>.xl65{mso-style-parent:style0;font-size:36.0pt;mso-number-format:"\@";
- text-align:right;border-top:none;border-right:none;border-bottom:1.5pt solid blue;border-left:none;color:blue}
- .xl66{mso-style-parent:style0;font-size:36.0pt;mso-number-format:"\@";text-align:right;color:blue}</style></head><body>
- <table style="text-align: left; width: 635px; height: 60px;" border="0" cellpadding="0" cellspacing="0"><tbody>
- '@
- }ElseIf($Operation -eq "Multiplication"){
- $bodyTop = @'
- <html><head><title>Multiplication</title><style>.xl65{mso-style-parent:style0;font-size:36.0pt;mso-number-format:"\@";
- text-align:right;border-top:none;border-right:none;border-bottom:1.5pt solid blue;border-left:none;color:blue}
- .xl66{mso-style-parent:style0;font-size:36.0pt;mso-number-format:"\@";text-align:right;color:blue}</style></head><body>
- <table style="text-align: left; width: 635px; height: 60px;" border="0" cellpadding="0" cellspacing="0"><tbody>
- '@
- }
- $bodyBotton = @'
- </tbody></table><br><br></body></html>
- '@
- If($Operation -eq "Addition"){
- $bodyTop + $page -join("<tr height=""20"">$blank20</tr>") + $bodyBotton | out-file '.\addition.html'
- }ElseIf($Operation -eq "Subtraction"){
- $bodyTop + $page -join("<tr height=""20"">$blank20</tr>") + $bodyBotton | out-file '.\subtraction.html'
- }ElseIf($Operation -eq "Multiplication"){
- $bodyTop + $page -join("<tr height=""20"">$blank20</tr>") + $bodyBotton | out-file '.\multiplication.html'
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement