Greatest common divisor: Difference between revisions
Content added Content deleted
m (→{{header|Oforth}}: Change of rem by mod) |
(→{{header|PowerShell}}: port short Python implementation) |
||
Line 2,453: | Line 2,453: | ||
return $b |
return $b |
||
}</lang> |
}</lang> |
||
or shorter (taken from Python implementation) |
|||
<lang powershell>function Get-GCD ($x, $y) { |
|||
if ($y -eq 0) { $x } else { Get-GCD $y ($x%$y) } |
|||
}</lang> |
|||
===Iterative Euclid Algorithm=== |
|||
based on Python implementation |
|||
<lang powershell> |
|||
Function Get-GCD( $x, $y ) { |
|||
while ($y -ne 0) { |
|||
$x, $y = $y, ($x % $y) |
|||
} |
|||
[Math]::abs($x) |
|||
} |
|||
</lang> |
|||
=={{header|Prolog}}== |
=={{header|Prolog}}== |