#Combo finder by Dale Swanson 04-07-07
#!/usr/bin/perl
use strict;
use warnings;
my $x; #general varibles
my $y;
my $z;
my $third; #third number
my $second; #second number
my $rem; #remainder of the third number
my @first; #the possible first numbers
my @second; #the possible second number, note $second is the user entered second number
my $diff; #the difference between the user entered second number, and the first possible second number in the list
while ($third < 40)
{ #the whole program will go in here
print "\nEnter third number, enter a number greater than 39 to exit ";
$third = ; #gets the third number
chomp($third);
last if ($third > 39); #exits program if the user enters a number > 39
$rem = $third % 4; #the remainder of the third number will decide what group the other two numbers belong to.
for ($x = 0; $x < 10; $x++)
{ #will set all the possible first and second numbers
$second[$x] = (($x * 4) + (($rem + 2) % 4)) % 40; #sets each of the possible second numbers, $x * 4 is the base, then we add the remainder, but off set by 2 (but still needs to be mod 4), then we make sure the whole thing is still mod 40
$first[$x] = (($x * 4) + $rem) % 40; #sets each of the possible first numbers, we don't need to offset the remainder, but we still make sure teh result is mod 40
}
print "\nThe second number must be one of these:\n@second\nEnter the second number (if it isn't known just pick the number you'd like the list to start with) ";
$second = ; #the user enters what he thinks the second number is (or where he want's to start the list)
$second = ($second - (($second - $rem + 2) % 4)) % 40; #converts the user entered second number to one of the 10 possible second numbers
$diff = $second - $second[0]; #finds how far each possible second number will need to be adjuested in the list
for ($x = 0; $x < 10; $x++)
{ #will reorder the list of second numbers to start with the second number enter by user.
$second[$x] = ($second[$x] + $diff) % 40; #adds the difference between the user enter second number to each possible second number, and makes sure they are still mod 40
}
foreach $x (@second)
{ #goes through each possible second number
foreach $y (@first)
{ #goes through each possible first number
if ($x == ($third + 2) % 40 || $x == ($third - 2) % 40 || $y == ($x + 2) % 40 || $y == ($x + 6) % 40)
{ #if the second number is 2 higher or lower then the third, or the first number is 2 or 6 higher than the second that combo isn't possible, print XX-XX-XX to show that.
#print "XX-XX-XX";
print " - - ";
#print "..-..-..";
}
else
{ #otherwise it's a vaild combo, so print it out
printf "%02d-%02d-%02d", $y, $x, $third;
}
print " ";
}
print "\n";
}
}