jagreygoose

Challenge #352 [Easy] Making Imgur-style Links

Jan 11th, 2019
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function Base62 {
  2.     param(
  3.     [ValidateRange(0, [int]::MaxValue)]
  4.         [int]
  5.         $NumberInput
  6.        
  7.     )
  8.  
  9.     process {
  10.  
  11.  
  12.         [string]$Symbols = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
  13.         [int]$Radix = $Symbols.Length
  14.         [string]$Output = ""
  15.  
  16.         Do {
  17.  
  18.             $Output = '{0}{1}' -f $Output, $Symbols[($NumberInput % $Radix)]
  19.             $NumberInput = [Math]::Floor([decimal]($NumberInput /= $Radix))
  20.  
  21.         }
  22.         While ($NumberInput -gt 0)
  23.         $Output
  24.        
  25.     }
  26. }
  27.  
  28.  
  29.  
  30. Base62 187621 # => 9OM
  31. Base62 237860461 # => 3n26g
  32. Base62 2187521 # => B4b9
  33. Base62 18752 # => sS4
Advertisement
Add Comment
Please, Sign In to add comment