[ create a new paste ] login | about

Link: http://codepad.org/RuWBoviC    [ raw code | output | fork ]

Perl, pasted on Aug 10:
sub f{@a=@b=1..3;@a[$_,2]=($a[2],-$a[$_])for@_;"@a"eq"@b"}

# test cases
my @true = (
    [1,1,1,1],
    [],
    [0,0,0,0],
    [1,0,1,0,1,0],
    [1,1,0,0,1,1,0,0],
    [0,1,1,0,0,1,1,0],
    [1,1,1,0,0,0,0,1],
    [1,0,0,1,0,0],
    [1,1,1,1,0,0,0,0,1,0,0,1,0,0],
    [0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],
);
my @false = (
    [1],
    [1,1],
    [1,1,1],
    [0,1],
    [1,0,0,0,1],
    [1,0,0,1,1],
    [0,1,0,1],
    [1,1,1,1,0],
    [0,0,1,0,1,0,0,1],
    [1,0,1,1,1,1,0,0,0,1,1,0,0,0],
    [0,1,1,1],
);

print "true: ", join(" ", map 1*f(@$_), @true), "\n";
print "false: ", join(" ", map 1*f(@$_), @false), "\n";


Output:
1
2
true: 1 1 1 1 1 1 1 1 1 1
false: 0 0 0 0 0 0 0 0 0 0 0


Create a new paste based on this one


Comments: