2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
|
|
@ -1,7 +1,14 @@
|
|||
function Get-DigitalSum ($n)
|
||||
function Get-DigitalSum ([string] $number, $base = 10)
|
||||
{
|
||||
if ($n -lt 10) {$n}
|
||||
else {
|
||||
($n % 10) + (Get-DigitalSum ([math]::Floor($n / 10)))
|
||||
if ($number.ToCharArray().Length -le 1) { [Convert]::ToInt32($number, $base) }
|
||||
else
|
||||
{
|
||||
$result = 0
|
||||
foreach ($character in $number.ToCharArray())
|
||||
{
|
||||
$digit = [Convert]::ToInt32(([string]$character), $base)
|
||||
$result += $digit
|
||||
}
|
||||
return $result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue