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,52 @@
|
|||
function radixSortn(sequence s, integer n)
|
||||
sequence buckets = repeat({},10)
|
||||
sequence res = {}
|
||||
for i=1 to length(s) do
|
||||
integer digit = remainder(floor(s[i]/power(10,n-1)),10)+1
|
||||
buckets[digit] = append(buckets[digit],s[i])
|
||||
end for
|
||||
for i=1 to length(buckets) do
|
||||
integer len = length(buckets[i])
|
||||
if len!=0 then
|
||||
if len=1 or n=1 then
|
||||
res &= buckets[i]
|
||||
else
|
||||
res &= radixSortn(buckets[i],n-1)
|
||||
end if
|
||||
end if
|
||||
end for
|
||||
return res
|
||||
end function
|
||||
|
||||
function split_by_sign(sequence s)
|
||||
sequence buckets = {{},{}}
|
||||
for i=1 to length(s) do
|
||||
integer si = s[i]
|
||||
if si<0 then
|
||||
buckets[1] = append(buckets[1],-si)
|
||||
else
|
||||
buckets[2] = append(buckets[2],si)
|
||||
end if
|
||||
end for
|
||||
return buckets
|
||||
end function
|
||||
|
||||
function radixSort(sequence s)
|
||||
integer mins = min(s)
|
||||
integer passes = max(max(s),abs(mins))
|
||||
passes = floor(log10(passes))+1
|
||||
if mins<0 then
|
||||
sequence buckets = split_by_sign(s)
|
||||
buckets[1] = reverse(sq_uminus(radixSortn(buckets[1],passes)))
|
||||
buckets[2] = radixSortn(buckets[2],passes)
|
||||
s = buckets[1]&buckets[2]
|
||||
else
|
||||
s = radixSortn(s,passes)
|
||||
end if
|
||||
return s
|
||||
end function
|
||||
|
||||
?radixSort({1, 3, 8, 9, 0, 0, 8, 7, 1, 6})
|
||||
?radixSort({170, 45, 75, 90, 2, 24, 802, 66})
|
||||
?radixSort({170, 45, 75, 90, 2, 24, -802, -66})
|
||||
?radixSort({100000, -10000, 400, 23, 10000})
|
||||
Loading…
Add table
Add a link
Reference in a new issue