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
|
|
@ -0,0 +1,44 @@
|
|||
enum BASE, FRAC, DECIMAL
|
||||
constant DESC = {"Base","Fraction","Decimal"}
|
||||
|
||||
function vdc(integer n, atom base, integer flag)
|
||||
object res = ""
|
||||
atom num = 0, denom = 1, digit, g
|
||||
while n do
|
||||
denom *= base
|
||||
digit = remainder(n,base)
|
||||
n = floor(n/base)
|
||||
if flag=BASE then
|
||||
res &= digit+'0'
|
||||
else
|
||||
num = num*base+digit
|
||||
end if
|
||||
end while
|
||||
if flag=FRAC then
|
||||
g = gcd(num,denom)
|
||||
return {num/g,denom/g}
|
||||
elsif flag=DECIMAL then
|
||||
return num/denom
|
||||
end if
|
||||
return {iff(length(res)=0?"0":"0."&res)}
|
||||
end function
|
||||
|
||||
procedure show_vdc(integer flag, string fmt)
|
||||
object v
|
||||
for i=2 to 5 do
|
||||
printf(1,"%s %d: ",{DESC[flag],i})
|
||||
for j=0 to 9 do
|
||||
v = vdc(j,i,flag)
|
||||
if flag=FRAC and v[1]=0 then
|
||||
printf(1,"0 ")
|
||||
else
|
||||
printf(1,fmt,v)
|
||||
end if
|
||||
end for
|
||||
puts(1,"\n")
|
||||
end for
|
||||
end procedure
|
||||
|
||||
show_vdc(BASE,"%s ")
|
||||
show_vdc(FRAC,"%d/%d ")
|
||||
show_vdc(DECIMAL,"%g ")
|
||||
Loading…
Add table
Add a link
Reference in a new issue