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 @@
(lib 'list) ;; for list-delete
(define dataM
'((the cat sat on the mat)
(the cat sat on the mat)
(A B C A B C A B C)
(A B C A B D A B E)
(A B)
(A B)
(A B B A)))
(define orderM
'((mat cat)
(cat mat)
(C A C A)
(E A D A)
(B)
(B A)
(B A)))
(define (order-disjoint M N)
(define R (append N null)) ;; tmp copy of N : delete w when used
(for/list [(w M)]
(if
(not (member w R)) w ;; output as is
(begin0
(first N) ;; replacer
(set! N (rest N))
(set! R (list-delete R w))))))

View file

@ -0,0 +1,45 @@
function order_disjoint(sequence m, sequence n)
integer rlen = length(n)
sequence rdis = repeat(0,rlen)
for i=1 to rlen do
object e = n[i]
integer j = find(e,m)
while j!=0 and find(j,rdis) do
j = find(e,m,j+1)
end while
rdis[i] = j
end for
rdis = sort(rdis)
while rlen and rdis[1]=0 do
rdis = rdis[2..$]
rlen -= 1
end while
for i=1 to rlen do
m[rdis[i]]=n[i]
end for
return join(m)
end function
sequence tests = {{"the cat sat on the mat","mat cat"},
{"the cat sat on the mat","cat mat"},
{"A B C A B C A B C","C A C A"},
{"A B C A B D A B E","E A D A"},
{"A B","B"},
{"A B","B A"},
{"A B B A","B A"},
{"",""},
{"A","A"},
{"A B",""},
{"A B B A","A B"},
{"A B A B","A B"},
{"A B A B","B A B A"},
{"A B C C B A","A C A C"},
{"A B C C B A","C A C A"},
{"A X","Y A"},
{"A X","Y A X"},
{"A X","Y X A"}}
for i=1 to length(tests) do
string {m,n} = tests[i]
printf(1,"\"%s\",\"%s\" => \"%s\"\n",{m,n,order_disjoint(split(m),split(n))})
end for

View file

@ -0,0 +1,18 @@
func dsort(m, n) {
var h = Hash()
n.each {|item| h{item} := 0 ++ }
m.map {|item| h{item} := 0 -- > 0 ? n.shift : item}
}
<<'EOT'.lines.each { |line|
the cat sat on the mat | mat cat
the cat sat on the mat | cat mat
A B C A B C A B C | C A C A
A B C A B D A B E | E A D A
A B | B
A B | B A
A B B A | B A
EOT
var (a, b) = line.split('|').map{.words}...
say "#{a.to_s} | #{b.to_s} -> #{dsort(a.clone, b.clone).to_s}"
}

View file

@ -0,0 +1,15 @@
def disjoint_order(N):
# The helper function, indices, ensures that successive occurrences
# of a particular value in N are matched by successive occurrences
# in the input on the assumption that null is not initially in the input.
def indices:
. as $in
| reduce range(0; N|length) as $i
# state: [ array, indices ]
( [$in, []];
(.[0] | index(N[$i])) as $ix | .[0][$ix] = null | .[1] += [$ix])
| .[1];
. as $in
| (indices | sort) as $sorted
| reduce range(0; N|length) as $i ($in; .[$sorted[$i]] = N[$i] ) ;

View file

@ -0,0 +1,2 @@
["the", "cat", "sat", "on", "the", "mat"] | indices( ["mat", "cat"] )
#=> ["the","mat","sat","on","the","cat"]

View file

@ -0,0 +1,2 @@
["the", "cat", "sat", "on", "the", "mat"] | disjoint_order( ["cat", "mat"] )
#=> ["the","cat","sat","on","the","mat"]

View file

@ -0,0 +1,2 @@
["A", "B", "C", "A", "B", "C", "A", "B", "C"] | disjoint_order( ["C", "A", "C", "A"] )
#=> ["C","B","A","C","B","A","A","B","C"]

View file

@ -0,0 +1,2 @@
["A", "B", "C", "A", "B", "D", "A", "B", "E"] | disjoint_order( ["E", "A", "D", "A"] )
#=> ["E","B","C","A","B","D","A","B","A"]

View file

@ -0,0 +1,2 @@
["A", "B"] | disjoint_order( ["B"] )
#=> ["A","B"]

View file

@ -0,0 +1,2 @@
["A", "B"] | disjoint_order( ["B", "A"] )
#=> ["B","A"]

View file

@ -0,0 +1,2 @@
["A", "B", "B", "A"] | disjoint_order( ["B", "A"] )
#=> ["B","A","B","A"]

View file

@ -0,0 +1,2 @@
["X", "X", "Y"] | disjoint_order(["X"])
#=> [X, X, Y]