Challenge #352 [Easy] Making Imgur-style Links
function Base62 {
param(
[ValidateRange(0, [int]::MaxValue)]
[int]
$NumberInput
)
process {
[string]$Symbols = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
[int]$Radix = $Symbols.Length
[string]$Output = ""
Do {
$Output = '{0}{1}' -f $Output, $Symbols[($NumberInput % $Radix)]
$NumberInput = [Math]::Floor([decimal]($NumberInput /= $Radix))
}
While ($NumberInput -gt 0)
$Output
}
}
Base62 187621 # => 9OM
Base62 237860461 # => 3n26g
Base62 2187521 # => B4b9
Base62 18752 # => sS4
Comments