Department numbers: Difference between revisions
Content added Content deleted
ReeceGoding (talk | contribs) (Added R.) |
(Add Mercury) |
||
Line 2,444: | Line 2,444: | ||
ReadChar; |
ReadChar; |
||
END DepartmentNumbers.</lang> |
END DepartmentNumbers.</lang> |
||
=={{header|Mercury}}== |
|||
<lang mercury>:- module department_numbers. |
|||
:- interface. |
|||
:- import_module io. |
|||
:- pred main(io::di, io::uo) is cc_multi. |
|||
:- implementation. |
|||
:- import_module int, list, solutions, string. |
|||
main(!IO) :- |
|||
io.print_line("P S F", !IO), |
|||
unsorted_aggregate(department_number, print_solution, !IO). |
|||
:- pred print_solution({int, int, int}::in, io::di, io::uo) is det. |
|||
print_solution({P, S, F}, !IO) :- |
|||
io.format("%d %d %d\n", [i(P), i(S), i(F)], !IO). |
|||
:- pred department_number({int, int, int}::out) is nondet. |
|||
department_number({Police, Sanitation, Fire}) :- |
|||
list.member(Police, [2, 4, 6]), |
|||
list.member(Sanitation, 1 .. 7), |
|||
list.member(Fire, 1 .. 7), |
|||
Police \= Sanitation, |
|||
Police \= Fire, |
|||
Sanitation \= Fire, |
|||
Police + Sanitation + Fire = 12.</lang> |
|||
{{out}} |
|||
<pre>P S F |
|||
2 3 7 |
|||
2 4 6 |
|||
2 6 4 |
|||
2 7 3 |
|||
4 1 7 |
|||
4 2 6 |
|||
4 3 5 |
|||
4 5 3 |
|||
4 6 2 |
|||
4 7 1 |
|||
6 1 5 |
|||
6 2 4 |
|||
6 4 2 |
|||
6 5 1</pre> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |