WeixiangYan/CodeTransOcean huggingface dataset:
Task: Bin given limits




Go: package main

import (
    "fmt"
    "sort"
)

func getBins(limits, data []int) []int {
    n := len(limits)
    bins := make([]int, n+1)
    for _, d := range data {
        index := sort.SearchInts(limits, d) 
        if index < len(limits) && d == limits[index] {
            index++
        }
        bins[index]++
    }
    return bins
}

func printBins(limits, bins []int) {
    n := len(limits)
    fmt.Printf("           < %3d = %2d\n", limits[0], bins[0])
    for i := 1; i < n; i++ {
        fmt.Printf(">= %3d and < %3d = %2d\n", limits[i-1], limits[i], bins[i])
    }
    fmt.Printf(">= %3d           = %2d\n", limits[n-1], bins[n])
    fmt.Println()
}

func main() {
    limitsList := [][]int{
        {23, 37, 43, 53, 67, 83},
        {14, 18, 249, 312, 389, 392, 513, 591, 634, 720},
    }

    dataList := [][]int{
        {
            95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47,
            16,  8,  9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55,
        },
        {
            445, 814, 519, 697, 700, 130, 255, 889, 481, 122, 932,  77, 323, 525, 570, 219, 367, 523, 442, 933,
            416, 589, 930, 373, 202, 253, 775,  47, 731, 685, 293, 126, 133, 450, 545, 100, 741, 583, 763, 306,
            655, 267, 248, 477, 549, 238,  62, 678,  98, 534, 622, 907, 406, 714, 184, 391, 913,  42, 560, 247,
            346, 860,  56, 138, 546,  38, 985, 948,  58, 213, 799, 319, 390, 634, 458, 945, 733, 507, 916, 123,
            345, 110, 720, 917, 313, 845, 426,   9, 457, 628, 410, 723, 354, 895, 881, 953, 677, 137, 397,  97,
            854, 740,  83, 216, 421,  94, 517, 479, 292, 963, 376, 981, 480,  39, 257, 272, 157,   5, 316, 395,
            787, 942, 456, 242, 759, 898, 576,  67, 298, 425, 894, 435, 831, 241, 989, 614, 987, 770, 384, 692,
            698, 765, 331, 487, 251, 600, 879, 342, 982, 527, 736, 795, 585,  40,  54, 901, 408, 359, 577, 237,
            605, 847, 353, 968, 832, 205, 838, 427, 876, 959, 686, 646, 835, 127, 621, 892, 443, 198, 988, 791,
            466,  23, 707, 467,  33, 670, 921, 180, 991, 396, 160, 436, 717, 918,   8, 374, 101, 684, 727, 749,
        },
    }

    for i := 0; i < len(limitsList); i++ {
        fmt.Println("Example", i+1, "\b\n")
        bins := getBins(limitsList[i], dataList[i])
        printBins(limitsList[i], bins)
    }
}








Ada: package binning is
   type Nums_Array is array (Natural range <>) of Integer;
   function Is_Sorted (Item : Nums_Array) return Boolean;
   subtype Limits_Array is Nums_Array with
        Dynamic_Predicate => Is_Sorted (Limits_Array);
   function Bins (Limits : Limits_Array; Data : Nums_Array) return Nums_Array;
   procedure Print (Limits : Limits_Array; Bin_Result : Nums_Array);
end binning;
Task: Bin given limits







Python: from bisect import bisect_right

def bin_it(limits: list, data: list) -> list:
    "Bin data according to (ascending) limits."
    bins = [0] * (len(limits) + 1)      
    for d in data:
        bins[bisect_right(limits, d)] += 1
    return bins

def bin_print(limits: list, bins: list) -> list:
    print(f"          < {limits[0]:3} := {bins[0]:3}")
    for lo, hi, count in zip(limits, limits[1:], bins[1:]):
        print(f">= {lo:3} .. < {hi:3} := {count:3}")
    print(f">= {limits[-1]:3}          := {bins[-1]:3}")


if __name__ == "__main__":
    print("RC FIRST EXAMPLE\n")
    limits  = [23, 37, 43, 53, 67, 83]
    data = [95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47,
            16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55]
    bins = bin_it(limits, data)
    bin_print(limits, bins)

    print("\nRC SECOND EXAMPLE\n")
    limits = [14, 18, 249, 312, 389, 392, 513, 591, 634, 720]
    data = [445,814,519,697,700,130,255,889,481,122,932, 77,323,525,570,219,367,523,442,933,
            416,589,930,373,202,253,775, 47,731,685,293,126,133,450,545,100,741,583,763,306,
            655,267,248,477,549,238, 62,678, 98,534,622,907,406,714,184,391,913, 42,560,247,
            346,860, 56,138,546, 38,985,948, 58,213,799,319,390,634,458,945,733,507,916,123,
            345,110,720,917,313,845,426,  9,457,628,410,723,354,895,881,953,677,137,397, 97,
            854,740, 83,216,421, 94,517,479,292,963,376,981,480, 39,257,272,157,  5,316,395,
            787,942,456,242,759,898,576, 67,298,425,894,435,831,241,989,614,987,770,384,692,
            698,765,331,487,251,600,879,342,982,527,736,795,585, 40, 54,901,408,359,577,237,
            605,847,353,968,832,205,838,427,876,959,686,646,835,127,621,892,443,198,988,791,
            466, 23,707,467, 33,670,921,180,991,396,160,436,717,918,  8,374,101,684,727,749]
    bins = bin_it(limits, data)
    bin_print(limits, bins)





Ada: package binning is
   type Nums_Array is array (Natural range <>) of Integer;
   function Is_Sorted (Item : Nums_Array) return Boolean;
   subtype Limits_Array is Nums_Array with
        Dynamic_Predicate => Is_Sorted (Limits_Array);
   function Bins (Limits : Limits_Array; Data : Nums_Array) return Nums_Array;
   procedure Print (Limits : Limits_Array; Bin_Result : Nums_Array);
end binning;
Task: Bin given limits



C#: using System;

public class Program
{
    static void Main()
    {
        PrintBins(new [] { 23, 37, 43, 53, 67, 83 },
            95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47,
            16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55
        );
        Console.WriteLine();

        PrintBins(new [] { 14, 18, 249, 312, 389, 392, 513, 591, 634, 720 },
            445,814,519,697,700,130,255,889,481,122,932, 77,323,525,570,219,367,523,442,933,416,589,930,373,202,
            253,775, 47,731,685,293,126,133,450,545,100,741,583,763,306,655,267,248,477,549,238, 62,678, 98,534,
            622,907,406,714,184,391,913, 42,560,247,346,860, 56,138,546, 38,985,948, 58,213,799,319,390,634,458,
            945,733,507,916,123,345,110,720,917,313,845,426,  9,457,628,410,723,354,895,881,953,677,137,397, 97,
            854,740, 83,216,421, 94,517,479,292,963,376,981,480, 39,257,272,157,  5,316,395,787,942,456,242,759,
            898,576, 67,298,425,894,435,831,241,989,614,987,770,384,692,698,765,331,487,251,600,879,342,982,527,
            736,795,585, 40, 54,901,408,359,577,237,605,847,353,968,832,205,838,427,876,959,686,646,835,127,621,
            892,443,198,988,791,466, 23,707,467, 33,670,921,180,991,396,160,436,717,918,  8,374,101,684,727,749);
    }

    static void PrintBins(int[] limits, params int[] data)
    {
        int[] bins = Bins(limits, data);
        Console.WriteLine($"-∞ .. {limits[0]} => {bins[0]}");
        for (int i = 0; i < limits.Length-1; i++) {
            Console.WriteLine($"{limits[i]} .. {limits[i+1]} => {bins[i+1]}");
        }
        Console.WriteLine($"{limits[^1]} .. ∞ => {bins[^1]}");
    }

    static int[] Bins(int[] limits, params int[] data)
    {
        Array.Sort(limits);
        int[] bins = new int[limits.Length + 1];
        foreach (int n in data) {
            int i = Array.BinarySearch(limits, n);
            i = i < 0 ? ~i : i+1;
            bins[i]++;
        }
        return bins;
    }
}
Task: Bin given limits


C++: #include <algorithm>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <vector>

std::vector<int> bins(const std::vector<int>& limits,
                      const std::vector<int>& data) {
    std::vector<int> result(limits.size() + 1, 0);
    for (int n : data) {
        auto i = std::upper_bound(limits.begin(), limits.end(), n);
        ++result[i - limits.begin()];
    }
    return result;
}

void print_bins(const std::vector<int>& limits, const std::vector<int>& bins) {
    size_t n = limits.size();
    if (n == 0)
        return;
    assert(n + 1 == bins.size());
    std::cout << "           < " << std::setw(3) << limits[0] << ": "
              << std::setw(2) << bins[0] << '\n';
    for (size_t i = 1; i < n; ++i)
        std::cout << ">= " << std::setw(3) << limits[i - 1] << " and < "
                  << std::setw(3) << limits[i] << ": " << std::setw(2)
                  << bins[i] << '\n';
    std::cout << ">= " << std::setw(3) << limits[n - 1] << "          : "
              << std::setw(2) << bins[n] << '\n';
}

int main() {
    const std::vector<int> limits1{23, 37, 43, 53, 67, 83};
    const std::vector<int> data1{
        95, 21, 94, 12, 99, 4,  70, 75, 83, 93, 52, 80, 57, 5,  53, 86, 65,
        17, 92, 83, 71, 61, 54, 58, 47, 16, 8,  9,  32, 84, 7,  87, 46, 19,
        30, 37, 96, 6,  98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55};

    std::cout << "Example 1:\n";
    print_bins(limits1, bins(limits1, data1));

    const std::vector<int> limits2{14,  18,  249, 312, 389,
                                   392, 513, 591, 634, 720};
    const std::vector<int> data2{
        445, 814, 519, 697, 700, 130, 255, 889, 481, 122, 932, 77,  323, 525,
        570, 219, 367, 523, 442, 933, 416, 589, 930, 373, 202, 253, 775, 47,
        731, 685, 293, 126, 133, 450, 545, 100, 741, 583, 763, 306, 655, 267,
        248, 477, 549, 238, 62,  678, 98,  534, 622, 907, 406, 714, 184, 391,
        913, 42,  560, 247, 346, 860, 56,  138, 546, 38,  985, 948, 58,  213,
        799, 319, 390, 634, 458, 945, 733, 507, 916, 123, 345, 110, 720, 917,
        313, 845, 426, 9,   457, 628, 410, 723, 354, 895, 881, 953, 677, 137,
        397, 97,  854, 740, 83,  216, 421, 94,  517, 479, 292, 963, 376, 981,
        480, 39,  257, 272, 157, 5,   316, 395, 787, 942, 456, 242, 759, 898,
        576, 67,  298, 425, 894, 435, 831, 241, 989, 614, 987, 770, 384, 692,
        698, 765, 331, 487, 251, 600, 879, 342, 982, 527, 736, 795, 585, 40,
        54,  901, 408, 359, 577, 237, 605, 847, 353, 968, 832, 205, 838, 427,
        876, 959, 686, 646, 835, 127, 621, 892, 443, 198, 988, 791, 466, 23,
        707, 467, 33,  670, 921, 180, 991, 396, 160, 436, 717, 918, 8,   374,
        101, 684, 727, 749};

    std::cout << "\nExample 2:\n";
    print_bins(limits2, bins(limits2, data2));
}
Task: Bin given limits





Java: import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Bins {
    public static <T extends Comparable<? super T>> int[] bins(
            List<? extends T> limits, Iterable<? extends T> data) {
        int[] result = new int[limits.size() + 1];
        for (T n : data) {
            int i = Collections.binarySearch(limits, n);
            if (i >= 0) {
                
                i = i+1;
            } else {
                
                i = ~i;
            }
            result[i]++;
        }
        return result;
    }

    public static void printBins(List<?> limits, int[] bins) {
        int n = limits.size();
        if (n == 0) {
            return;
        }
        assert n+1 == bins.length;
        System.out.printf("           < %3s: %2d\n", limits.get(0), bins[0]);
        for (int i = 1; i < n; i++) {
            System.out.printf(">= %3s and < %3s: %2d\n", limits.get(i-1), limits.get(i), bins[i]);
        }
        System.out.printf(">= %3s          : %2d\n", limits.get(n-1), bins[n]);
    }

    public static void main(String[] args) {
        List<Integer> limits = Arrays.asList(23, 37, 43, 53, 67, 83);
        List<Integer> data = Arrays.asList(
            95, 21, 94, 12, 99, 4,  70, 75, 83, 93, 52, 80, 57, 5,  53, 86, 65,
            17, 92, 83, 71, 61, 54, 58, 47, 16, 8,  9,  32, 84, 7,  87, 46, 19,
            30, 37, 96, 6,  98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55);

        System.out.println("Example 1:");
        printBins(limits, bins(limits, data));

        limits = Arrays.asList(14,  18,  249, 312, 389,
                               392, 513, 591, 634, 720);
        data = Arrays.asList(
            445, 814, 519, 697, 700, 130, 255, 889, 481, 122, 932, 77,  323, 525,
            570, 219, 367, 523, 442, 933, 416, 589, 930, 373, 202, 253, 775, 47,
            731, 685, 293, 126, 133, 450, 545, 100, 741, 583, 763, 306, 655, 267,
            248, 477, 549, 238, 62,  678, 98,  534, 622, 907, 406, 714, 184, 391,
            913, 42,  560, 247, 346, 860, 56,  138, 546, 38,  985, 948, 58,  213,
            799, 319, 390, 634, 458, 945, 733, 507, 916, 123, 345, 110, 720, 917,
            313, 845, 426, 9,   457, 628, 410, 723, 354, 895, 881, 953, 677, 137,
            397, 97,  854, 740, 83,  216, 421, 94,  517, 479, 292, 963, 376, 981,
            480, 39,  257, 272, 157, 5,   316, 395, 787, 942, 456, 242, 759, 898,
            576, 67,  298, 425, 894, 435, 831, 241, 989, 614, 987, 770, 384, 692,
            698, 765, 331, 487, 251, 600, 879, 342, 982, 527, 736, 795, 585, 40,
            54,  901, 408, 359, 577, 237, 605, 847, 353, 968, 832, 205, 838, 427,
            876, 959, 686, 646, 835, 127, 621, 892, 443, 198, 988, 791, 466, 23,
            707, 467, 33,  670, 921, 180, 991, 396, 160, 436, 717, 918, 8,   374,
            101, 684, 727, 749);

        System.out.println();
        System.out.println("Example 2:");
        printBins(limits, bins(limits, data));
    }
}
Task: Bin given limits







Python: from bisect import bisect_right

def bin_it(limits: list, data: list) -> list:
    "Bin data according to (ascending) limits."
    bins = [0] * (len(limits) + 1)      
    for d in data:
        bins[bisect_right(limits, d)] += 1
    return bins

def bin_print(limits: list, bins: list) -> list:
    print(f"          < {limits[0]:3} := {bins[0]:3}")
    for lo, hi, count in zip(limits, limits[1:], bins[1:]):
        print(f">= {lo:3} .. < {hi:3} := {count:3}")
    print(f">= {limits[-1]:3}          := {bins[-1]:3}")


if __name__ == "__main__":
    print("RC FIRST EXAMPLE\n")
    limits  = [23, 37, 43, 53, 67, 83]
    data = [95,21,94,12,99,4,70,75,83,93,52,80,57,5,53,86,65,17,92,83,71,61,54,58,47,
            16, 8, 9,32,84,7,87,46,19,30,37,96,6,98,40,79,97,45,64,60,29,49,36,43,55]
    bins = bin_it(limits, data)
    bin_print(limits, bins)

    print("\nRC SECOND EXAMPLE\n")
    limits = [14, 18, 249, 312, 389, 392, 513, 591, 634, 720]
    data = [445,814,519,697,700,130,255,889,481,122,932, 77,323,525,570,219,367,523,442,933,
            416,589,930,373,202,253,775, 47,731,685,293,126,133,450,545,100,741,583,763,306,
            655,267,248,477,549,238, 62,678, 98,534,622,907,406,714,184,391,913, 42,560,247,
            346,860, 56,138,546, 38,985,948, 58,213,799,319,390,634,458,945,733,507,916,123,
            345,110,720,917,313,845,426,  9,457,628,410,723,354,895,881,953,677,137,397, 97,
            854,740, 83,216,421, 94,517,479,292,963,376,981,480, 39,257,272,157,  5,316,395,
            787,942,456,242,759,898,576, 67,298,425,894,435,831,241,989,614,987,770,384,692,
            698,765,331,487,251,600,879,342,982,527,736,795,585, 40, 54,901,408,359,577,237,
            605,847,353,968,832,205,838,427,876,959,686,646,835,127,621,892,443,198,988,791,
            466, 23,707,467, 33,670,921,180,991,396,160,436,717,918,  8,374,101,684,727,749]
    bins = bin_it(limits, data)
    bin_print(limits, bins)
Task: Bin given limits




Go: package main

import (
    "fmt"
    "sort"
)

func getBins(limits, data []int) []int {
    n := len(limits)
    bins := make([]int, n+1)
    for _, d := range data {
        index := sort.SearchInts(limits, d) 
        if index < len(limits) && d == limits[index] {
            index++
        }
        bins[index]++
    }
    return bins
}

func printBins(limits, bins []int) {
    n := len(limits)
    fmt.Printf("           < %3d = %2d\n", limits[0], bins[0])
    for i := 1; i < n; i++ {
        fmt.Printf(">= %3d and < %3d = %2d\n", limits[i-1], limits[i], bins[i])
    }
    fmt.Printf(">= %3d           = %2d\n", limits[n-1], bins[n])
    fmt.Println()
}

func main() {
    limitsList := [][]int{
        {23, 37, 43, 53, 67, 83},
        {14, 18, 249, 312, 389, 392, 513, 591, 634, 720},
    }

    dataList := [][]int{
        {
            95, 21, 94, 12, 99, 4, 70, 75, 83, 93, 52, 80, 57, 5, 53, 86, 65, 17, 92, 83, 71, 61, 54, 58, 47,
            16,  8,  9, 32, 84, 7, 87, 46, 19, 30, 37, 96, 6, 98, 40, 79, 97, 45, 64, 60, 29, 49, 36, 43, 55,
        },
        {
            445, 814, 519, 697, 700, 130, 255, 889, 481, 122, 932,  77, 323, 525, 570, 219, 367, 523, 442, 933,
            416, 589, 930, 373, 202, 253, 775,  47, 731, 685, 293, 126, 133, 450, 545, 100, 741, 583, 763, 306,
            655, 267, 248, 477, 549, 238,  62, 678,  98, 534, 622, 907, 406, 714, 184, 391, 913,  42, 560, 247,
            346, 860,  56, 138, 546,  38, 985, 948,  58, 213, 799, 319, 390, 634, 458, 945, 733, 507, 916, 123,
            345, 110, 720, 917, 313, 845, 426,   9, 457, 628, 410, 723, 354, 895, 881, 953, 677, 137, 397,  97,
            854, 740,  83, 216, 421,  94, 517, 479, 292, 963, 376, 981, 480,  39, 257, 272, 157,   5, 316, 395,
            787, 942, 456, 242, 759, 898, 576,  67, 298, 425, 894, 435, 831, 241, 989, 614, 987, 770, 384, 692,
            698, 765, 331, 487, 251, 600, 879, 342, 982, 527, 736, 795, 585,  40,  54, 901, 408, 359, 577, 237,
            605, 847, 353, 968, 832, 205, 838, 427, 876, 959, 686, 646, 835, 127, 621, 892, 443, 198, 988, 791,
            466,  23, 707, 467,  33, 670, 921, 180, 991, 396, 160, 436, 717, 918,   8, 374, 101, 684, 727, 749,
        },
    }

    for i := 0; i < len(limitsList); i++ {
        fmt.Println("Example", i+1, "\b\n")
        bins := getBins(limitsList[i], dataList[i])
        printBins(limitsList[i], bins)
    }
}
Task: Department numbers



C#: using System;
public class Program
{
    public static void Main() {
        for (int p = 2; p <= 7; p+=2) {
            for (int s = 1; s <= 7; s++) {
                int f = 12 - p - s;
                if (s >= f) break;
                if (f > 7) continue;
                if (s == p || f == p) continue; 
                Console.WriteLine($"Police:{p}, Sanitation:{s}, Fire:{f}");
                Console.WriteLine($"Police:{p}, Sanitation:{f}, Fire:{s}");
            }
        }
    }
}









Ada: with Ada.Text_IO;

procedure Department_Numbers is
   use Ada.Text_IO;
begin
   Put_Line (" P S F");
   for Police in 2 .. 6 loop
      for Sanitation in 1 .. 7 loop
         for Fire in 1 .. 7 loop
            if
              Police mod 2 = 0                and
              Police + Sanitation + Fire = 12 and
              Sanitation /= Police            and
              Sanitation /= Fire              and
              Police     /= Fire
            then
               Put_Line (Police'Image & Sanitation'Image & Fire'Image);
            end if;
         end loop;
      end loop;
   end loop;
end Department_Numbers;
Task: Department numbers

C: #include<stdio.h>

int main()
{
	int police,sanitation,fire;
	
	printf("Police     Sanitation         Fire\n");
	printf("----------------------------------");
	
	for(police=2;police<=6;police+=2){
		for(sanitation=1;sanitation<=7;sanitation++){
			for(fire=1;fire<=7;fire++){
				if(police!=sanitation && sanitation!=fire && fire!=police && police+fire+sanitation==12){
					printf("\n%d\t\t%d\t\t%d",police,sanitation,fire);
				}
			}
		}
	}
	
	return 0;
}











Ada: with Ada.Text_IO;

procedure Department_Numbers is
   use Ada.Text_IO;
begin
   Put_Line (" P S F");
   for Police in 2 .. 6 loop
      for Sanitation in 1 .. 7 loop
         for Fire in 1 .. 7 loop
            if
              Police mod 2 = 0                and
              Police + Sanitation + Fire = 12 and
              Sanitation /= Police            and
              Sanitation /= Fire              and
              Police     /= Fire
            then
               Put_Line (Police'Image & Sanitation'Image & Fire'Image);
            end if;
         end loop;
      end loop;
   end loop;
end Department_Numbers;
Task: Department numbers


C++: #include <iostream>
#include <iomanip>

int main( int argc, char* argv[] ) {
    int sol = 1;
    std::cout << "\t\tFIRE\t\tPOLICE\t\tSANITATION\n";
    for( int f = 1; f < 8; f++ ) {
        for( int p = 1; p < 8; p++ ) {
            for( int s = 1; s < 8; s++ ) {
                if( f != p && f != s && p != s && !( p & 1 ) && ( f + s + p == 12 ) ) {
                std::cout << "SOLUTION #" << std::setw( 2 ) << sol++ << std::setw( 2 ) 
                << ":\t" << std::setw( 2 ) << f << "\t\t " << std::setw( 3 ) << p 
                << "\t\t" << std::setw( 6 ) << s << "\n";
                }
            }
        }
    }
    return 0;
}










Ada: with Ada.Text_IO;

procedure Department_Numbers is
   use Ada.Text_IO;
begin
   Put_Line (" P S F");
   for Police in 2 .. 6 loop
      for Sanitation in 1 .. 7 loop
         for Fire in 1 .. 7 loop
            if
              Police mod 2 = 0                and
              Police + Sanitation + Fire = 12 and
              Sanitation /= Police            and
              Sanitation /= Fire              and
              Police     /= Fire
            then
               Put_Line (Police'Image & Sanitation'Image & Fire'Image);
            end if;
         end loop;
      end loop;
   end loop;
end Department_Numbers;
Task: Department numbers




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)
}








Ada: with Ada.Text_IO;

procedure Department_Numbers is
   use Ada.Text_IO;
begin
   Put_Line (" P S F");
   for Police in 2 .. 6 loop
      for Sanitation in 1 .. 7 loop
         for Fire in 1 .. 7 loop
            if
              Police mod 2 = 0                and
              Police + Sanitation + Fire = 12 and
              Sanitation /= Police            and
              Sanitation /= Fire              and
              Police     /= Fire
            then
               Put_Line (Police'Image & Sanitation'Image & Fire'Image);
            end if;
         end loop;
      end loop;
   end loop;
end Department_Numbers;
Task: Department numbers





Java: public class DepartmentNumbers {
    public static void main(String[] args) {
        System.out.println("Police  Sanitation  Fire");
        System.out.println("------  ----------  ----");
        int count = 0;
        for (int i = 2; i <= 6; i += 2) {
            for (int j = 1; j <= 7; ++j) {
                if (j == i) continue;
                for (int k = 1; k <= 7; ++k) {
                    if (k == i || k == j) continue;
                    if (i + j + k != 12) continue;
                    System.out.printf("  %d         %d         %d\n", i, j, k);
                    count++;
                }
            }
        }
        System.out.printf("\n%d valid combinations", count);
    }
}







Ada: with Ada.Text_IO;

procedure Department_Numbers is
   use Ada.Text_IO;
begin
   Put_Line (" P S F");
   for Police in 2 .. 6 loop
      for Sanitation in 1 .. 7 loop
         for Fire in 1 .. 7 loop
            if
              Police mod 2 = 0                and
              Police + Sanitation + Fire = 12 and
              Sanitation /= Police            and
              Sanitation /= Fire              and
              Police     /= Fire
            then
               Put_Line (Police'Image & Sanitation'Image & Fire'Image);
            end if;
         end loop;
      end loop;
   end loop;
end Department_Numbers;