How to resolve the algorithm Department numbers step by step in the Quackery programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Department numbers step by step in the Quackery 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 Quackery programming language
Source code in the quackery programming language
[ 2dup = iff
[ 2drop drop ] done
dip over swap over = iff
[ 2drop drop ] done
rot echo sp
swap echo sp
echo cr ] is fire ( pol san fir --> )
[ 2dup = iff 2drop done
12 over -
dip over swap -
dup 1 < iff
[ 2drop drop ] done
dup 7 > iff
[ 2drop drop ] done
fire ] is sanitation ( pol san --> )
[ 7 times
[ dup
i^ 1+ sanitation ]
drop ] is police ( pol --> )
[ cr ' [ 2 4 6 ]
witheach police ] is departments ( --> )
departments
You may also check:How to resolve the algorithm Averages/Root mean square step by step in the Forth programming language
You may also check:How to resolve the algorithm File size step by step in the Axe programming language
You may also check:How to resolve the algorithm Greyscale bars/Display step by step in the Component Pascal programming language
You may also check:How to resolve the algorithm Short-circuit evaluation step by step in the J programming language
You may also check:How to resolve the algorithm Motzkin numbers step by step in the Fermat programming language