summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid A. Madore <david+git@madore.org>2020-06-04 15:50:53 +0200
committerDavid A. Madore <david+git@madore.org>2020-06-04 15:50:53 +0200
commit2e894e05cc886dbb15e2c4312343ac84fa4ceef1 (patch)
tree3170c69f1e939e7e807027b6c8d4839f5cf28a5d
parent28b43e0af19e0867f48d9b65aee823499da05edd (diff)
downloadinf105-2e894e05cc886dbb15e2c4312343ac84fa4ceef1.tar.gz
inf105-2e894e05cc886dbb15e2c4312343ac84fa4ceef1.tar.bz2
inf105-2e894e05cc886dbb15e2c4312343ac84fa4ceef1.zip
Test randomizer script: change uniformity rules.
-rwxr-xr-xmisc/randomize-test.pl60
1 files changed, 30 insertions, 30 deletions
diff --git a/misc/randomize-test.pl b/misc/randomize-test.pl
index 2db3998..e569adb 100755
--- a/misc/randomize-test.pl
+++ b/misc/randomize-test.pl
@@ -11,10 +11,15 @@ my %opts;
getopts("c:N:n:", \%opts);
-my @preamble = ();
-my @postamble = ();
-my @questions = ();
-my $nbvarid = 0;
+my @preamble = (); # Preamble lines
+my @postamble = (); # Postamble lines
+my @questions = (); # Array of question hashrefs
+# Each question hash has keys:
+# {question}: arrayref with question lines
+# {answers}: arrayref of arrayrefs with answer lines, correct answer first
+# {varid}: idnex in qvars array
+my @qvars = (); # Array of question variants
+# Each entry is an arrayref of indexes in the questions array
### READ INPUT FILE
@@ -45,23 +50,23 @@ while ($_ = <>) {
die "wrong placement" if $in_preamble || $in_postamble || $in_qvar || defined($curqn);
die "bad format" unless $_ eq "\\begin\{qvar\}\n";
$in_qvar = 1;
- $varid = ($nbvarid++);
+ push @qvars, [];
next LINELOOP;
} elsif ( $_ =~ m/\\end\{qvar\}/ ) {
die "wrong placement" if $in_preamble || $in_postamble || (!$in_qvar) || defined($curqn);
die "bad format" unless $_ eq "\\end\{qvar\}\n";
$in_qvar = 0;
- $varid = undef;
next LINELOOP;
} elsif ( $_ =~ m/\\begin\{question\}/ ) {
die "wrong placement" if $in_preamble || $in_postamble || defined($curqn);
die "bad format" unless $_ eq "\\begin\{question\}\n";
my %qn = ();
- $varid = ($nbvarid++) unless $in_qvar;
- $qn{varid} = $varid;
+ push @qvars, [] unless $in_qvar;
+ $qn{varid} = $#qvars;
$qn{question} = [];
$qn{answers} = [];
push @questions, \%qn;
+ push @{$qvars[$#qvars]}, $#questions;
$listref = $qn{question};
$curqn = \%qn;
next LINELOOP;
@@ -90,14 +95,12 @@ while ($_ = <>) {
}
-# printf STDERR "nbvarid=%d (total=%d)\n", $nbvarid, scalar(@questions);
-
### RANDOMIZE
my $commonseed = $opts{N} // "";
my $seed = $opts{n} // "";
-my $nbqn = $opts{c} // int(($nbvarid+1)/2);
+my $nbqn = $opts{c} // int((scalar(@qvars)+1)/2);
my @questab = ();
my @quesanstab = ();
@@ -106,24 +109,21 @@ if ( 1 ) { ## Keep following variables local
my @hashlist;
-for ( my $i=0 ; $i<scalar(@questions) ; $i++ ) {
- push @hashlist, sha256("${commonseed}\n${seed}\nQ\n${i}\n");
+for ( my $u=0 ; $u<scalar(@qvars) ; $u++ ) {
+ push @hashlist, sha256("${commonseed}\n${seed}\nQV\n${u}\n");
}
-my @prequestab = sort { $hashlist[$a] cmp $hashlist[$b] } (0..(scalar(@questions)-1));
-my %varid_punch;
-PREQUESLOOP:
-for ( my $k=0 ; $k<scalar(@prequestab) ; $k++ ) {
- last if scalar(@questab) > $nbqn;
- my $i = $prequestab[$k];
- my $qn = $questions[$i];
- my $varid = $qn->{varid};
- if ( defined($varid) ) {
- if ( defined($varid_punch{$varid}) ) {
- next PREQUESLOOP;
- } else {
- $varid_punch{$varid} = $i;
- }
+my @qvartab = sort { $hashlist[$a] cmp $hashlist[$b] } (0..(scalar(@qvars)-1));
+
+for ( my $k=0 ; $k<scalar(@qvartab) && $k<$nbqn ; $k++ ) {
+ my $u = $qvartab[$k];
+ @hashlist = ();
+ for ( my $kv=0 ; $kv<scalar(@{$qvars[$u]}) ; $kv++ ) {
+ my $i = $qvars[$u]->[$kv];
+ push @hashlist, sha256("${commonseed}\n${seed}\nQ\n${i}\n");
}
+ my $kv = (sort { $hashlist[$a] cmp $hashlist[$b] } (0..(scalar(@{$qvars[$u]})-1)))[0];
+ my $i = $qvars[$u]->[$kv];
+ die "this is impossible" unless $questions[$i]->{varid} == $u;
push @questab, $i;
}
@@ -158,13 +158,13 @@ for ( my $k=0 ; $k<scalar(@questab) ; $k++ ) {
foreach my $l ( @{$qn->{question}} ) {
print $l;
}
- for ( my $kk=0 ; $kk<scalar(@{$quesanstab[$i]}) ; $kk++ ) {
- my $j = $quesanstab[$i]->[$kk];
+ for ( my $kj=0 ; $kj<scalar(@{$quesanstab[$i]}) ; $kj++ ) {
+ my $j = $quesanstab[$i]->[$kj];
my $a = $qn->{answers}->[$j];
foreach my $l ( @{$a} ) {
print $l;
}
- push @correct, sprintf("%d%s", $k+1, chr(ord("A")+$kk)) if $j==0;
+ push @correct, sprintf("%d%s", $k+1, chr(ord("A")+$kj)) if $j==0;
}
print "\\end\{question\}\n\n";
}