Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
65
Task/Number-names/Julia/number-names-1.julia
Normal file
65
Task/Number-names/Julia/number-names-1.julia
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
const stext = ["one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
|
||||
const teentext = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
|
||||
"seventeen", "eighteen", "nineteen"]
|
||||
const tenstext = ["ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy",
|
||||
"eighty", "ninety"]
|
||||
const ordstext = ["million", "billion", "trillion", "quadrillion", "quintillion", "sextillion",
|
||||
"septillion", "octillion", "nonillion", "decillion", "undecillion", "duodecillion",
|
||||
"tredecillion", "quattuordecillion", "quindecillion", "sexdecillion", "septendecillion",
|
||||
"octodecillion", "novemdecillion", "vigintillion"]
|
||||
|
||||
function normalize_digits!(a::Array{T,1}) where T<:Integer
|
||||
while 0 < length(a) && a[end] == 0
|
||||
pop!(a)
|
||||
end
|
||||
length(a)
|
||||
end
|
||||
|
||||
function digits2text!(d::Array{T,1}, use_short_scale=true) where T<:Integer
|
||||
ndig = normalize_digits!(d)
|
||||
0 < ndig || return ""
|
||||
if ndig < 7
|
||||
s = ""
|
||||
if 3 < ndig
|
||||
t = digits2text!(d[1:3])
|
||||
s = digits2text!(d[4:end]) * " thousand"
|
||||
0 < length(t) || return s
|
||||
return occursin(t, "and") ? s * " " * t : s * " and " * t
|
||||
end
|
||||
if ndig == 3
|
||||
s *= stext[pop!(d)] * " hundred"
|
||||
ndig = normalize_digits!(d)
|
||||
0 < ndig || return s
|
||||
s *= " and "
|
||||
end
|
||||
1 < ndig || return s*stext[pop!(d)]
|
||||
j, i = d
|
||||
j ≠ 0 || return s*tenstext[i]
|
||||
i ≠ 1 || return s*teentext[j]
|
||||
return s*tenstext[i] * "-" * stext[j]
|
||||
end
|
||||
s = digits2text!(d[1:6])
|
||||
d = d[7:end]
|
||||
dgrp = use_short_scale ? 3 : 6
|
||||
ord = 0
|
||||
while dgrp < length(d)
|
||||
ord += 1
|
||||
t = digits2text!(d[1:dgrp])
|
||||
d = d[(dgrp+1):end]
|
||||
0 < length(t) || continue
|
||||
t = t * " " * ordstext[ord]
|
||||
s = length(s) == 0 ? t : t * " " * s
|
||||
end
|
||||
ord += 1
|
||||
t = digits2text!(d) * " " * ordstext[ord]
|
||||
0 < length(s) || return t
|
||||
t * " " * s
|
||||
end
|
||||
|
||||
function num2text(n::T, use_short_scale=true) where T<:Integer
|
||||
-1 < n || return "minus "*num2text(-n, use_short_scale)
|
||||
0 < n || return "zero"
|
||||
toobig = use_short_scale ? big(10)^66 : big(10)^126
|
||||
n < toobig || return "too big to say"
|
||||
digits2text!(digits(n, base=10), use_short_scale)
|
||||
end
|
||||
42
Task/Number-names/Julia/number-names-2.julia
Normal file
42
Task/Number-names/Julia/number-names-2.julia
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
using Printf
|
||||
|
||||
println("Some easy ones to start with\n")
|
||||
|
||||
for i in [-1:21..., 100, 101, 10000, 10001, 1000000, 1010101]
|
||||
@printf("%8d is %s\n", i, num2text(i))
|
||||
end
|
||||
|
||||
println("\nSome larger numbers\n")
|
||||
|
||||
println("The largest signed literal integer (short-scale)")
|
||||
i = typemax(1)
|
||||
println(" ", i, " is")
|
||||
println(num2text(i))
|
||||
println()
|
||||
|
||||
println("The largest signed literal integer (long-scale)")
|
||||
println(" ", i, " is")
|
||||
println(num2text(i, false))
|
||||
println()
|
||||
|
||||
println("The largest unsigned integer (short-scale)")
|
||||
i = typemax(UInt128)
|
||||
println(" ", i, " is")
|
||||
println(num2text(i))
|
||||
println()
|
||||
|
||||
println("50! (short-scale)")
|
||||
i = factorial(big(50))
|
||||
println(" ", i, " is")
|
||||
println(num2text(i))
|
||||
println()
|
||||
|
||||
println("51! (short-scale)")
|
||||
i = factorial(big(51))
|
||||
println(" ", i, " is")
|
||||
println(num2text(i))
|
||||
println()
|
||||
|
||||
println("51! (long-scale)")
|
||||
println(" ", i, " is")
|
||||
println(num2text(i, false))
|
||||
Loading…
Add table
Add a link
Reference in a new issue