How to resolve the algorithm Department numbers step by step in the Rust programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Department numbers step by step in the Rust programming language

Table of Contents

Problem Statement

There is a highly organized city that has decided to assign a number to each of their departments:

Each department can have a number between   1   and   7   (inclusive). The three department numbers are to be unique (different from each other) and must add up to   12. The Chief of the Police doesn't like odd numbers and wants to have an even number for his department.

Write a computer program which outputs all valid combinations.

Possible output   (for the 1st and 14th solutions):

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Department numbers step by step in the Rust programming language

Source code in the rust programming language

extern crate num_iter;
fn main() {
    println!("Police Sanitation Fire");
    println!("----------------------");

    for police in num_iter::range_step(2, 7, 2) {
        for sanitation in 1..8 {
            for fire in 1..8 {
                if police != sanitation
                    && sanitation != fire
                    && fire != police
                    && police + fire + sanitation == 12
                {
                    println!("{:6}{:11}{:4}", police, sanitation, fire);
                }
            }
        }
    }
}


  

You may also check:How to resolve the algorithm Dinesman's multiple-dwelling problem step by step in the Sidef programming language
You may also check:How to resolve the algorithm Power set step by step in the Java programming language
You may also check:How to resolve the algorithm Happy numbers step by step in the REXX programming language
You may also check:How to resolve the algorithm Text processing/2 step by step in the Factor programming language
You may also check:How to resolve the algorithm Greatest element of a list step by step in the Erlang programming language