All pastes #462665 Raw Edit

Untitled

public text v1 · immutable
#462665 ·published 2007-04-28 13:17 UTC
rendered paste body
#!/usr/bin/perl -w

use strict;

for my $test (1..12) {
    my $n = int(rand(10));
    for my $k (0..$n) {
        my $res = 0;
        my @a = map {int(rand(2));} 1..2**$n;
        open(TEST, ">test");
        print TEST "1\n$n $k @a\n";
        close(TEST);
        my $ans = `./solution < test`;

        for my $i (0..2**$n-1) {
            my $c = 0;
            $_ = sprintf("%b", $i);
            $c++ while s/1//;
            next if $c != $k;
    
            my $val = 0;
            for (0..2**$n-1) {
                $val ^= $a[$_] if (($_ & $i) == $_);
            }
    
            $res++ if $val;
        }
        print ($res == $ans ? "OK: n=$n, k=$k\n ".(join'',@a)." Erwartet: $res, Antwort=$ans\n" : "Fehlgeschlagen: n=$n k=$k ".(join'',@a)." Erwartet: $res, Antwort=$ans\n");
    }
}