Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,30 @@
proc beadSort[T](a: var openarray[T]) =
var max = low(T)
var sum = 0
for x in a:
if x > max: max = x
var beads = newSeq[int](max * a.len)
for i in 0 .. < a.len:
for j in 0 .. < a[i]:
beads[i * max + j] = 1
for j in 0 .. < max:
sum = 0
for i in 0 .. < a.len:
sum += beads[i * max + j]
beads[i * max + j] = 0
for i in a.len - sum .. < a.len:
beads[i * max + j] = 1
for i in 0 .. < a.len:
var j = 0
while j < max and beads[i * max + j] > 0: inc j
a[i] = j
var a = @[5, 3, 1, 7, 4, 1, 1, 20]
beadSort a
echo a

View file

@ -0,0 +1,13 @@
function beadsort(sequence a)
sequence poles = repeat(0,max(a))
for i=1 to length(a) do
poles[1..a[i]] = sq_add(poles[1..a[i]],1)
end for
a[1..$] = 0
for i=1 to length(poles) do
a[1..poles[i]] = sq_add(a[1..poles[i]],1)
end for
return a
end function
?beadsort({5, 3, 1, 7, 4, 1, 1, 20})

View file

@ -0,0 +1,16 @@
func beadsort(arr) {
var rows = []
var columns = []
for datum in arr {
for column in ^datum {
++(columns[column] := 0)
++(rows[columns[column] - 1] := 0)
}
}
rows.reverse
}
say beadsort([5,3,1,7,4,1,1])

View file

@ -0,0 +1,7 @@
# ncols is the number of columns (i.e. vertical poles)
def column_sums(ncols):
. as $abacus
| reduce range(0; ncols) as $col
([];
. + [reduce $abacus[] as $row
(0; if $row > $col then .+1 else . end)]) ;

View file

@ -0,0 +1,8 @@
# Generic function to count the number of items in a stream:
def count(stream): reduce stream as $i (0; .+1);
def readout:
. as $sums
| .[0] as $n
| reduce range(0;$n) as $i
([]; . + [count( $sums[] | select( . > $i) )]);

View file

@ -0,0 +1 @@
def bead_sort: column_sums(max) | readout;

View file

@ -0,0 +1 @@
[734,3,1,24,324,324,32,432,42,3,4,1,1] | bead_sort

View file

@ -0,0 +1,2 @@
$ jq -n -c -f bead_sort.jq
[734,432,324,324,42,32,24,4,3,3,1,1,1]