How to resolve the algorithm Department numbers step by step in the Wren programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Department numbers step by step in the Wren 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 Wren programming language
Source code in the wren programming language
System.print("Police Sanitation Fire")
System.print("------ ---------- ----")
var count = 0
for (h in 1..3) {
var i = h * 2
for (j in 1..7) {
if (j != i) {
for (k in 1..7) {
if ((k != i && k != j) && (i + j + k == 12) ) {
System.print(" %(i) %(j) %(k)")
count = count + 1
}
}
}
}
}
System.print("\n%(count) valid combinations")
You may also check:How to resolve the algorithm Show ASCII table step by step in the Forth programming language
You may also check:How to resolve the algorithm Ternary logic step by step in the Alternative version programming language
You may also check:How to resolve the algorithm Power set step by step in the Ursala programming language
You may also check:How to resolve the algorithm CSV data manipulation step by step in the AWK programming language
You may also check:How to resolve the algorithm Rename a file step by step in the Tcl programming language