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,36 @@
var trees = [
# 0..2 are same
[ 'd', [ 'c', [ 'a', 'b', ], ], ],
[ [ 'd', 'c' ], [ 'a', 'b' ] ],
[ [ [ 'd', 'c', ], 'a', ], 'b', ],
# and this one's different!
[ [ [ [ [ [ 'a' ], 'b' ], 'c', ], 'd', ], 'e', ], 'f' ],
];
func get_tree_iterator(*rtrees) {
var tree;
func {
tree = rtrees.pop;
while (defined(tree) && tree.is_an(Array)) {
rtrees.append(tree[1]);
tree = tree[0];
}
return tree;
}
}
func cmp_fringe(a, b) {
var ti1 = get_tree_iterator(a);
var ti2 = get_tree_iterator(b);
loop {
var (L, R) = (ti1(), ti2());
defined(L) && defined(R) && (L == R) && next;
!defined(L) && !defined(R) && return "Same";
return "Different";
}
}
range(1, trees.end).each { |tree_idx|
say ("tree[#{tree_idx-1}] vs tree[#{tree_idx}]: ",
cmp_fringe(trees[tree_idx-1], trees[tree_idx]));
}

View file

@ -0,0 +1 @@
(t|flatten) == (s|flatten)

View file

@ -0,0 +1,33 @@
# "next" allows one to generate successive leaves, one at a time. This is accomplished
# by ensuring that the non-null output of a call to "next" can also serve as input.
#
# "next" returns null if there are no more leaves, otherwise it returns [leaf, nodes]
# where "leaf" is the next leaf, and nodes is an array of nodes still to be traversed.
# Input has the same form, but on input, "leaf" is ignored unless it is an array.
def next:
def _next:
.[0] as $node | .[1] as $nodes
| if ($node|type) == "array" then
if $node|length != 2 then
error("improper node: \($node) should have 2 items") else . end
| [ $node[0], [$node[1]] + $nodes]
elif $nodes|length > 0 then [$nodes[0], $nodes[1:]]
else null
end;
_next as $n
| if $n == null then null
elif ($n[0]|type) == "array" then $n|next
else $n
end;
# t and u must be binary trees
def same_fringe(t;u):
# x and y must be suitable for input to "next"
def eq(x;y):
if x == null then y == null
elif y == null then false
elif x[0] != y[0] then false
else eq( x|next; y|next)
end;
eq([t,[]]|next; [u,[]]|next) ;

View file

@ -0,0 +1,10 @@
[1,[2,[3,[4,[5,[6,7]]]]]] as $a
| [[[[[[1,2],3],4],5],6],7] as $b
| [[[1,2],3],[4,[5,[6,7]]]] as $c
| [[[1,2],2],4] as $d
| same_fringe($a;$a), same_fringe($b;$b), same_fringe($c;$c),
same_fringe($a;$b), same_fringe($a;$c), same_fringe($b;$c),
same_fringe($a;$d), same_fringe($d;$c), same_fringe($b;$d),
same_fringe( ["a",["b",["c",[["x","y"],"z"]]]];
[[["a","b"],"c"],["x",["y","z"]]] )

View file

@ -0,0 +1,11 @@
$ jq -n -f Same_Fringe.jq
true
true
true
true
true
true
false
false
false
true