29 lines
504 B
Text
29 lines
504 B
Text
function halveInt( [int] $rhs )
|
|
{
|
|
[math]::floor( $rhs / 2 )
|
|
}
|
|
|
|
function doubleInt( [int] $rhs )
|
|
{
|
|
$rhs*2
|
|
}
|
|
|
|
function isEven( [int] $rhs )
|
|
{
|
|
-not ( $_ % 2 )
|
|
}
|
|
|
|
function Ethiopian( [int] $lhs , [int] $rhs )
|
|
{
|
|
$scratch = @{}
|
|
1..[math]::floor( [math]::log( $lhs , 2 ) + 1 ) |
|
|
ForEach-Object {
|
|
$scratch[$lhs] = $rhs
|
|
$lhs
|
|
$lhs = halveInt( $lhs )
|
|
$rhs = doubleInt( $rhs ) } |
|
|
Where-Object { -not ( isEven $_ ) } |
|
|
ForEach-Object { $sum = 0 } { $sum += $scratch[$_] } { $sum }
|
|
}
|
|
|
|
Ethiopian 17 34
|