How to resolve the algorithm Department numbers step by step in the Raku programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Department numbers step by step in the Raku 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 Raku programming language
Source code in the raku programming language
for (1..7).combinations(3).grep(*.sum == 12) {
for .permutations\ .grep(*.[0] %% 2) {
say Z=> .list;
}
}
You may also check:How to resolve the algorithm Pig the dice game/Player step by step in the Wren programming language
You may also check:How to resolve the algorithm HTTPS step by step in the Julia programming language
You may also check:How to resolve the algorithm Sorting algorithms/Pancake sort step by step in the Lua programming language
You may also check:How to resolve the algorithm Thue-Morse step by step in the Arturo programming language
You may also check:How to resolve the algorithm Forward difference step by step in the Racket programming language