tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -0,0 +1,25 @@
|
|||
fun toBase b v = let
|
||||
fun toBase' (a, 0) = a
|
||||
| toBase' (a, v) = toBase' (v mod b :: a, v div b)
|
||||
in
|
||||
toBase' ([], v)
|
||||
end
|
||||
|
||||
fun fromBase b ds =
|
||||
foldl (fn (k, n) => n * b + k) 0 ds
|
||||
|
||||
val toAlphaDigits = let
|
||||
fun convert n = if n < 10 then chr (n + ord #"0")
|
||||
else chr (n + ord #"a" - 10)
|
||||
in
|
||||
implode o map convert
|
||||
end
|
||||
|
||||
val fromAlphaDigits = let
|
||||
fun convert c = if Char.isDigit c then ord c - ord #"0"
|
||||
else if Char.isUpper c then ord c - ord #"A" + 10
|
||||
else if Char.isLower c then ord c - ord #"a" + 10
|
||||
else raise Match
|
||||
in
|
||||
map convert o explode
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue