RosettaCodeData/Task/Ethiopian-multiplication/PowerShell/ethiopian-multiplication-1.ps1
2026-04-30 12:34:36 -04:00

35 lines
572 B
PowerShell

function isEven {
param ([int]$value)
return [bool]($value % 2 -eq 0)
}
function doubleValue {
param ([int]$value)
return [int]($value * 2)
}
function halveValue {
param ([int]$value)
return [int]($value / 2)
}
function multiplyValues {
param (
[int]$plier,
[int]$plicand,
[int]$temp = 0
)
while ($plier -ge 1)
{
if (!(isEven $plier)) {
$temp += $plicand
}
$plier = halveValue $plier
$plicand = doubleValue $plicand
}
return $temp
}
multiplyValues 17 34