Department numbers: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 4: Line 4:
Police, Sanitation and Fire Department.
Police, Sanitation and Fire Department.


Each Department can have a number between 1 and 7.
Each Department can have a number between 1 and 7.<br>
The 3 numbers have to be different and have to add up to the number 12.
The 3 numbers have to be different and have to add up to the number 12.<br>
For some reason the Chief of the Police Department doesn't like odd numbers and wants to have an even number for his department.
For some reason the Chief of the Police Department doesn't like odd numbers and wants to have an even number for his department.


Line 11: Line 11:




Possible Output:
For example:

1 2 9


1 2 9 <br>
5 3 4
5 3 4


Line 37: Line 36:
foreach (@even_numbers)
foreach (@even_numbers)
{
{
my $police_n = $_;
my $police_number = $_;
for my $fire_n ( 1.. 12)
for my $fire_number ( 1.. 12)
{
{
for my $san_n (1..12)
for my $sanitation_number (1..12)
{
{
if ( $police_n + $fire_n + $san_n == 12 && $police_n != $fire_n && $fire_n != $san_n && $san_n != $police_n)
if ( $police_number + $fire_number + $sanitation_number == 12 &&
$police_number != $fire_number &&
$fire_number != $sanitation_number &&
$sanitation_number != $police_number)
{
{
print "$police_n\t$fire_n\t$san_n\n";
print "$police_number\t$fire_number\t$sanitation_number\n";
}
}
}
}