Department numbers: Difference between revisions
Content added Content deleted
(Added Go) |
|||
Line 667: | Line 667: | ||
[13] 6 4 2 |
[13] 6 4 2 |
||
[14] 6 5 1 |
[14] 6 5 1 |
||
</pre> |
|||
=={{header|Go}}== |
|||
{{trans|Kotlin}} |
|||
<lang go>package main |
|||
import "fmt" |
|||
func main() { |
|||
fmt.Println("Police Sanitation Fire") |
|||
fmt.Println("------ ---------- ----") |
|||
count := 0 |
|||
for i := 2; i < 7; i += 2 { |
|||
for j := 1; j < 8; j++ { |
|||
if j == i { continue } |
|||
for k := 1; k < 8; k++ { |
|||
if k == i || k == j { continue } |
|||
if i + j + k != 12 { continue } |
|||
fmt.Printf(" %d %d %d\n", i, j, k) |
|||
count++ |
|||
} |
|||
} |
|||
} |
|||
fmt.Printf("\n%d valid combinations\n", count) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Police Sanitation Fire |
|||
------ ---------- ---- |
|||
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 |
|||
14 valid combinations |
|||
</pre> |
</pre> |
||