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,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
|
||||
|
|
@ -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})
|
||||
|
|
@ -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])
|
||||
|
|
@ -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)]) ;
|
||||
|
|
@ -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) )]);
|
||||
|
|
@ -0,0 +1 @@
|
|||
def bead_sort: column_sums(max) | readout;
|
||||
|
|
@ -0,0 +1 @@
|
|||
[734,3,1,24,324,324,32,432,42,3,4,1,1] | bead_sort
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
$ jq -n -c -f bead_sort.jq
|
||||
[734,432,324,324,42,32,24,4,3,3,1,1,1]
|
||||
Loading…
Add table
Add a link
Reference in a new issue