Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
1
Task/Nth/Julia/nth-1.julia
Normal file
1
Task/Nth/Julia/nth-1.julia
Normal file
|
|
@ -0,0 +1 @@
|
|||
using Printf
|
||||
12
Task/Nth/Julia/nth-2.julia
Normal file
12
Task/Nth/Julia/nth-2.julia
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function ordinal(n::Integer)
|
||||
n < 0 && throw(DomainError())
|
||||
suffixes = ("st", "nd", "rd")
|
||||
u = n % 10
|
||||
t = n ÷ 10 % 10
|
||||
if u > 3 || u == 0 || t == 1
|
||||
suf = "th"
|
||||
else
|
||||
suf = suffixes[u]
|
||||
end
|
||||
return string(n, suf)
|
||||
end
|
||||
17
Task/Nth/Julia/nth-3.julia
Normal file
17
Task/Nth/Julia/nth-3.julia
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
println("Tests of ordinal formatting of integers.")
|
||||
for (i, n) in enumerate(0:25)
|
||||
(i - 1) % 10 == 0 && println()
|
||||
@printf("%7s", ordinal(n))
|
||||
end
|
||||
|
||||
println()
|
||||
for (i, n) in enumerate(250:265)
|
||||
(i - 1) % 10 == 0 && println()
|
||||
@printf("%7s", ordinal(n))
|
||||
end
|
||||
|
||||
println()
|
||||
for (i, n) in enumerate(1000:1025)
|
||||
(i - 1) % 10 == 0 && println()
|
||||
@printf("%7s", ordinal(n))
|
||||
end
|
||||
3
Task/Nth/Julia/nth-4.julia
Normal file
3
Task/Nth/Julia/nth-4.julia
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
Nth(x::Integer) = if x % 100 ∈ [11, 12, 13] "th" else ["th", "st", "nd", "rd", "th"][min(x % 10 + 1, 5)] end
|
||||
NthA(x::Integer) = "$(x)'$(Nth(x)) "
|
||||
[0:25..., 250:265..., 1000:1025...] .|> NthA .|> print;
|
||||
Loading…
Add table
Add a link
Reference in a new issue