Private/Get-GreatestCommonDivisor.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using namespace System.Management.Automation

function Get-GreatestCommonDivisor {
    [CmdletBinding()]
    param(
        [Parameter()]
        [int]
        $Numerator,

        [Parameter()]
        [int]
        $Denominator
    )
    process {
        while ($Denominator -gt 0 -and $Numerator -ne $Denominator) {
            $Numerator, $Denominator = $Denominator, ($Numerator % $Denominator)
        }

        return $Numerator
    }
}