Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
104
Task/Number-names/Phix/number-names.phix
Normal file
104
Task/Number-names/Phix/number-names.phix
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
constant twenties = {"zero","one","two","three","four","five","six","seven","eight","nine","ten",
|
||||
"eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"}
|
||||
|
||||
function Twenty(integer N)
|
||||
return twenties[mod(N,20)+1]
|
||||
end function
|
||||
|
||||
constant decades = {"twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"}
|
||||
|
||||
function Decade(integer N)
|
||||
return decades[mod(N,10)-1]
|
||||
end function
|
||||
|
||||
function Hundred(integer N)
|
||||
if N<20 then
|
||||
return Twenty(N)
|
||||
elsif mod(N,10)=0 then
|
||||
return Decade(mod(floor(N/10),10))
|
||||
end if
|
||||
return Decade(floor(N/10)) & '-' & Twenty(mod(N,10))
|
||||
end function
|
||||
|
||||
function Thousand(integer N, string withand)
|
||||
if N<100 then
|
||||
return withand & Hundred (N);
|
||||
elsif mod(N,100)=0 then
|
||||
return withand & Twenty(floor(N/100))&" hundred"
|
||||
end if
|
||||
return Twenty(floor(N/100)) & " hundred and " & Hundred(mod(N,100))
|
||||
end function
|
||||
|
||||
constant orders = {{power(10,12),"trillion"},
|
||||
{power(10,9),"billion"},
|
||||
{power(10,6),"million"},
|
||||
{power(10,3),"thousand"}}
|
||||
|
||||
function Triplet(atom N)
|
||||
atom Order, High, Low
|
||||
string Name, res = ""
|
||||
integer n
|
||||
for i=1 to length(orders) do
|
||||
{Order,Name} = orders[i]
|
||||
High = floor(N/Order)
|
||||
Low = mod(N,Order)
|
||||
if High!=0 then
|
||||
res &= Thousand(High,"")&' '&Name
|
||||
end if
|
||||
N = Low
|
||||
if Low=0 then exit end if
|
||||
if length(res) and High!=0 then
|
||||
res &= ", "
|
||||
end if
|
||||
end for
|
||||
if N!=0 or res="" then
|
||||
res &= Thousand(floor(N),iff(res=""?"":"and "))
|
||||
N = abs(mod(N,1))
|
||||
if N>1e-6 then
|
||||
res &= " point"
|
||||
for i=1 to 10 do
|
||||
n = floor(N*10.0000001)
|
||||
res &= ' '&twenties[n+1]
|
||||
N = N*10-n
|
||||
if abs(N)<1e-6 then exit end if
|
||||
end for
|
||||
end if
|
||||
end if
|
||||
return res
|
||||
end function
|
||||
|
||||
function spell(atom N)
|
||||
string res = ""
|
||||
if N<0 then
|
||||
res = "minus "
|
||||
N = -N
|
||||
end if
|
||||
res &= Triplet(N)
|
||||
return res
|
||||
end function
|
||||
|
||||
constant Samples = {99, 300, 310, 417,1_501, 12_609, 200000000000100, 999999999999999,
|
||||
-123456787654321,102003000400005,1020030004,102003,102,1,0,-1,-99,
|
||||
-1501,1234,12.34,10000001.2,1E-3,-2.7182818}
|
||||
|
||||
function smartp(atom N)
|
||||
string res
|
||||
if N=floor(N) then return sprintf("%d",N) end if
|
||||
res = sprintf("%18.8f",N)
|
||||
if find('.',res) then
|
||||
res = trim_tail(res,"0")
|
||||
end if
|
||||
return res
|
||||
end function
|
||||
|
||||
atom si
|
||||
for i=1 to length(Samples) do
|
||||
si = Samples[i]
|
||||
printf(1,"%18s %s\n",{smartp(si),spell(si)})
|
||||
end for
|
||||
|
||||
si = 201021002001
|
||||
while si!=0 do
|
||||
printf(1,"%18s %s\n",{smartp(si),spell(si)})
|
||||
si = trunc(si/-10)
|
||||
end while
|
||||
Loading…
Add table
Add a link
Reference in a new issue