langs a-z
This commit is contained in:
parent
db842d013d
commit
d066446780
11389 changed files with 98361 additions and 1020 deletions
20
Task/Happy-numbers/PowerShell/happy-numbers-1.psh
Normal file
20
Task/Happy-numbers/PowerShell/happy-numbers-1.psh
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
function happy([int] $n) {
|
||||
$a=@()
|
||||
for($i=2;$a.count -lt $n;$i++) {
|
||||
$sum=$i
|
||||
$hist=@{}
|
||||
while( $hist[$sum] -eq $null ) {
|
||||
if($sum -eq 1) {
|
||||
$a+=$i
|
||||
$i
|
||||
}
|
||||
$hist[$sum]=$sum
|
||||
$sum2=0
|
||||
foreach($j in $sum.ToString().ToCharArray()) {
|
||||
$k=([int]$j)-0x30
|
||||
$sum2+=$k*$k
|
||||
}
|
||||
$sum=$sum2
|
||||
}
|
||||
}
|
||||
}
|
||||
18
Task/Happy-numbers/PowerShell/happy-numbers-2.psh
Normal file
18
Task/Happy-numbers/PowerShell/happy-numbers-2.psh
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
function happy([int] $n) {
|
||||
1..$n | ForEach-Object {
|
||||
$sum=$_
|
||||
$hist=@{}
|
||||
while( $hist[$sum] -eq $null ) {
|
||||
if($sum -eq 1) {
|
||||
$_
|
||||
}
|
||||
$hist[$sum]=$sum
|
||||
$sum2=0
|
||||
foreach($j in $sum.ToString().ToCharArray()) {
|
||||
$k=([int]$j)-0x30
|
||||
$sum2+=$k*$k
|
||||
}
|
||||
$sum=$sum2
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue