March 2014 update
This commit is contained in:
parent
09687c4926
commit
a25938f123
1846 changed files with 21876 additions and 5203 deletions
26
Task/Hailstone-sequence/PowerShell/hailstone-sequence.psh
Normal file
26
Task/Hailstone-sequence/PowerShell/hailstone-sequence.psh
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Author M. McNabb
|
||||
function Get-HailStoneBelowLimit {
|
||||
param($UpperLimit)
|
||||
begin {
|
||||
function Get-HailStone {
|
||||
param($n)
|
||||
switch($n) {
|
||||
1 {$n;return}
|
||||
{$n % 2 -eq 0} {$n; return Get-Hailstone ($n = $n / 2)}
|
||||
{$n % 2 -ne 0} {$n; return Get-Hailstone ($n = ($n * 3) +1)}
|
||||
}
|
||||
}
|
||||
$Counts = @()
|
||||
}
|
||||
|
||||
process {
|
||||
for ($i = 1; $i -lt $UpperLimit; $i++) {
|
||||
$Object = [pscustomobject]@{
|
||||
'Number' = $i
|
||||
'Count' = (Get-HailStone $i).count
|
||||
}
|
||||
$Counts += $Object
|
||||
}
|
||||
}
|
||||
end {$Counts}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue