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,59 @@
|
|||
' FB 1.05.0 Win64
|
||||
|
||||
Function findMax(array() As Integer) As Integer
|
||||
Dim length As Integer = UBound(array) - LBound(array) + 1
|
||||
If length = 0 Then Return 0 '' say
|
||||
If length = 1 Then Return array(LBound(array))
|
||||
Dim max As Integer = LBound(array)
|
||||
For i As Integer = LBound(array) + 1 To UBound(array)
|
||||
If array(i) > max Then max = array(i)
|
||||
Next
|
||||
Return max
|
||||
End Function
|
||||
|
||||
Function findMin(array() As Integer) As Integer
|
||||
Dim length As Integer = UBound(array) - LBound(array) + 1
|
||||
If length = 0 Then Return 0 '' say
|
||||
If length = 1 Then Return array(LBound(array))
|
||||
Dim min As Integer = LBound(array)
|
||||
For i As Integer = LBound(array) + 1 To UBound(array)
|
||||
If array(i) < min Then min = array(i)
|
||||
Next
|
||||
Return min
|
||||
End Function
|
||||
|
||||
Sub countingSort(array() As Integer, min As Integer, max As Integer)
|
||||
Dim count(0 To max - min) As Integer '' all zero by default
|
||||
Dim As Integer number, z
|
||||
For i As Integer = LBound(array) To UBound(array)
|
||||
number = array(i)
|
||||
count(number - min) += 1
|
||||
Next
|
||||
z = LBound(array)
|
||||
For i As Integer = min To max
|
||||
While count(i - min) > 0
|
||||
array(z) = i
|
||||
z += 1
|
||||
count(i - min) -= 1
|
||||
Wend
|
||||
Next
|
||||
End Sub
|
||||
|
||||
Sub printArray(array() As Integer)
|
||||
For i As Integer = LBound(array) To UBound(array)
|
||||
Print Using "####"; array(i);
|
||||
Next
|
||||
Print
|
||||
End Sub
|
||||
|
||||
Dim array(1 To 10) As Integer = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1} '' using BBC BASIC example array
|
||||
Print "Unsorted : ";
|
||||
printArray(array())
|
||||
Dim max As Integer = findMax(array())
|
||||
Dim min As Integer = findMin(array())
|
||||
countingSort array(), min, max
|
||||
Print "Sorted : ";
|
||||
printArray(array())
|
||||
Print
|
||||
Print "Press any key to quit"
|
||||
Sleep
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
proc countingSort[T](a: var openarray[T]; min, max: int) =
|
||||
let range = max - min + 1
|
||||
var count = newSeq[T](range)
|
||||
var z = 0
|
||||
|
||||
for i in 0 .. < a.len: inc count[a[i] - min]
|
||||
|
||||
for i in min .. max:
|
||||
for j in 0 .. <count[i - min]:
|
||||
a[z] = i
|
||||
inc z
|
||||
|
||||
var a = @[5, 3, 1, 7, 4, 1, 1, 20]
|
||||
countingSort(a, 1, 20)
|
||||
echo a
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
function countingSort(sequence array, integer mina, maxa)
|
||||
sequence count = repeat(0,maxa-mina+1)
|
||||
for i=1 to length(array) do
|
||||
count[array[i]-mina+1] += 1
|
||||
end for
|
||||
integer z = 1
|
||||
for i=mina to maxa do
|
||||
for j=1 to count[i-mina+1] do
|
||||
array[z] := i
|
||||
z += 1
|
||||
end for
|
||||
end for
|
||||
return array
|
||||
end function
|
||||
|
||||
sequence s = {5, 3, 1, 7, 4, 1, 1, 20}
|
||||
?countingSort(s,min(s),max(s))
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
aList = [4, 65, 2, 99, 83, 782, 1]
|
||||
see countingSort(aList, 1, 782)
|
||||
|
||||
func countingSort f, min, max
|
||||
count = list(max-min+1)
|
||||
for i = min to max
|
||||
count[i] = 0
|
||||
next
|
||||
|
||||
for i = 1 to len(f)
|
||||
count[ f[i] ] = count[ f[i] ] + 1
|
||||
next
|
||||
|
||||
z = 1
|
||||
for i = min to max
|
||||
while count[i] > 0
|
||||
f[z] = i
|
||||
z = z + 1
|
||||
count[i] = count[i] - 1
|
||||
end
|
||||
next
|
||||
return f
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
func counting_sort(a, min, max) {
|
||||
var cnt = ([0] * (max - min + 1));
|
||||
a.each { |i| cnt[i-min]++ };
|
||||
return cnt.map {|i| min++; [min-1] * i}.sum;
|
||||
}
|
||||
|
||||
var a = 100.of {100.rand.int};
|
||||
say counting_sort(a, 0, 100).dump;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
def countingSort(min; max):
|
||||
. as $in
|
||||
| reduce range(0;length) as $i
|
||||
( {};
|
||||
($in[$i]|tostring) as $s | .[$s] += 1 # courtesy of the fact that in jq, (null+1) is 1
|
||||
)
|
||||
| . as $hash
|
||||
# now construct the answer:
|
||||
| reduce range(min; max+1) as $i
|
||||
( [];
|
||||
($i|tostring) as $s
|
||||
| if $hash[$s] == null then .
|
||||
else reduce range(0; $hash[$s]) as $j (.; . + [$i])
|
||||
end
|
||||
);
|
||||
|
|
@ -0,0 +1 @@
|
|||
[1,2,1,4,0,10] | countingSort(0;10)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -M -c -n -f counting_sort.jq
|
||||
[0,1,1,2,4,10]
|
||||
Loading…
Add table
Add a link
Reference in a new issue