#!/usr/local/bin/perl -w # dds.p - seeks double difference sets # see qecc/DDS $v=0; $I = 5 ; # the number of points to draw $S = 11 ; # the set size from which points are drawn 0..S-1 $D = 2 ; # the definition of "double". Change this to 1 to get regular # difference sets. # set S=0 to get program to calculate right value of S for a complete difference set $stop = 1 ; # whether to stop as soon as a set is found. $force1 = 0 ; # whether to force the first set members to be 0,1 eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; if($S<=0){ if($D==2) { $S = $I*($I-1)/2 + 1 ; } else { $S = $I*($I-1) + 1 ; } print "set S = $S\n" ; if($force1==0) {$force1 = 1 ; } } # initialize count of which differences exist in the set $count[0] = "counts" ; for ( $ii = 1 ; $ii <= $S-1 ; $ii++ ) { $count[$ii] = 0 ; } $s[0] = "D=$D I=$I S=$S:"; $s[1] = 0 ; &doit(2) ; sub doit { local ( $i ) = @_; if ( ($i==2) && $force1) { $max[$i] = 1 ; # print "invoking max=1\n" ; } else { $max[$i] = $S -1-$I+$i ; } for ( $s[$i] = $s[$i-1] + 1 ; $s[$i] <= $max[$i] ; $s[$i] ++ ) { # if($i==2) { print "max=$max[$i], s[$i]=$s[$i]\n" ; } for ( $ii = 1 ; $ii <= $i-1 ; $ii++ ) { $count[ $s[$i]-$s[$ii] ] ++ ; $count[ $S - ( $s[$i]-$s[$ii] ) ] ++ ; } $over=0; for ( $ii = 1 ; $ii <= $i-1 ; $ii++ ) { if( $count[ $s[$i]-$s[$ii] ] > $D ) { $over=1 ; } } if ($over==0) { # worth continuing. if ($i<$I) { &doit($i+1) ; } else { print join ( " ", @s ); print " (".join ( " ", @count ) if ($v) ; $ok = 1; $ones=0; # check all possible differneces for ( $ii = 1 ; $ii <= $S-1 ; $ii++ ) { if($count[$ii] != $D ) { $ok-- ; } if($count[$ii] == 1 ) { $ones++; } } if ($ok>0) {print " - OK!!"; } else { print " --- $ones ones XX"; print " (".join ( " ", @count ) ;} print "\n" ; if ($ok>0) { if($stop) { exit(0); } } } } # undo thecounts for ( $ii = 1 ; $ii <= $i-1 ; $ii++ ) { $count[ $s[$i]-$s[$ii] ]-- ; $count[ $S - ( $s[$i]-$s[$ii] ) ] -- ; } } }