WeixiangYan/CodeTransOcean huggingface dataset:
Task: Hofstadter Figure-Figure sequences





Java: import java.util.*;

class Hofstadter
{
  private static List<Integer> getSequence(int rlistSize, int slistSize)
  {
    List<Integer> rlist = new ArrayList<Integer>();
    List<Integer> slist = new ArrayList<Integer>();
    Collections.addAll(rlist, 1, 3, 7);
    Collections.addAll(slist, 2, 4, 5, 6);
    List<Integer> list = (rlistSize > 0) ? rlist : slist;
    int targetSize = (rlistSize > 0) ? rlistSize : slistSize;
    while (list.size() > targetSize)
      list.remove(list.size() - 1);
    while (list.size() < targetSize)
    {
      int lastIndex = rlist.size() - 1;
      int lastr = rlist.get(lastIndex).intValue();
      int r = lastr + slist.get(lastIndex).intValue();
      rlist.add(Integer.valueOf(r));
      for (int s = lastr + 1; (s < r) && (list.size() < targetSize); s++)
        slist.add(Integer.valueOf(s));
    }
    return list;
  }
  
  public static int ffr(int n)
  {  return getSequence(n, 0).get(n - 1).intValue();  }
  
  public static int ffs(int n)
  {  return getSequence(0, n).get(n - 1).intValue();  }
  
  public static void main(String[] args)
  {
    System.out.print("R():");
    for (int n = 1; n <= 10; n++)
      System.out.print(" " + ffr(n));
    System.out.println();
    
    Set<Integer> first40R = new HashSet<Integer>();
    for (int n = 1; n <= 40; n++)
      first40R.add(Integer.valueOf(ffr(n)));
      
    Set<Integer> first960S = new HashSet<Integer>();
    for (int n = 1; n <= 960; n++)
      first960S.add(Integer.valueOf(ffs(n)));
    
    for (int i = 1; i <= 1000; i++)
    {
      Integer n = Integer.valueOf(i);
      if (first40R.contains(n) == first960S.contains(n))
        System.out.println("Integer " + i + " either in both or neither set");
    }
    System.out.println("Done");
  }
}







Ada: package Hofstadter_Figure_Figure is

   function FFR(P: Positive) return Positive;

   function FFS(P: Positive) return Positive;

end Hofstadter_Figure_Figure;
Task: Hofstadter Figure-Figure sequences







Python: def ffr(n):
    if n < 1 or type(n) != int: raise ValueError("n must be an int >= 1")
    try:
        return ffr.r[n]
    except IndexError:
        r, s = ffr.r, ffs.s
        ffr_n_1 = ffr(n-1)
        lastr = r[-1]
        
        s += list(range(s[-1] + 1, lastr))
        if s[-1] < lastr: s += [lastr + 1]
        
        len_s = len(s)
        ffs_n_1 = s[n-1] if len_s > n else (n - len_s) + s[-1]
        ans = ffr_n_1 + ffs_n_1
        r.append(ans)
        return ans
ffr.r = [None, 1]

def ffs(n):
    if n < 1 or type(n) != int: raise ValueError("n must be an int >= 1")
    try:
        return ffs.s[n]
    except IndexError:
        r, s = ffr.r, ffs.s
        for i in range(len(r), n+2):
            ffr(i)
            if len(s) > n:
                return s[n]
        raise Exception("Whoops!")
ffs.s = [None, 2]

if __name__ == '__main__':
    first10 = [ffr(i) for i in range(1,11)]
    assert first10 == [1, 3, 7, 12, 18, 26, 35, 45, 56, 69], "ffr() value error(s)"
    print("ffr(n) for n = [1..10] is", first10)
    
    bin = [None] + [0]*1000
    for i in range(40, 0, -1):
        bin[ffr(i)] += 1
    for i in range(960, 0, -1):
        bin[ffs(i)] += 1
    if all(b == 1 for b in bin[1:1000]):
        print("All Integers 1..1000 found OK")
    else:
        print("All Integers 1..1000 NOT found only once: ERROR")





Ada: package Hofstadter_Figure_Figure is

   function FFR(P: Positive) return Positive;

   function FFS(P: Positive) return Positive;

end Hofstadter_Figure_Figure;
Task: Hofstadter Figure-Figure sequences








VB: Private Function ffr(n As Long) As Long
    Dim R As New Collection
    Dim S As New Collection
    R.Add 1
    S.Add 2
    
    For i = 2 To n
        R.Add R(i - 1) + S(i - 1)
        For j = S(S.Count) + 1 To R(i) - 1
            S.Add j
        Next j
        For j = R(i) + 1 To R(i) + S(i - 1)
            S.Add j
        Next j
    Next i
    ffr = R(n)
    Set R = Nothing
    Set S = Nothing
End Function
Private Function ffs(n As Long) As Long
    Dim R As New Collection
    Dim S As New Collection
    R.Add 1
    S.Add 2
    
    For i = 2 To n
        R.Add R(i - 1) + S(i - 1)
        For j = S(S.Count) + 1 To R(i) - 1
            S.Add j
        Next j
        For j = R(i) + 1 To R(i) + S(i - 1)
            S.Add j
        Next j
        If S.Count >= n Then Exit For
    Next i
    ffs = S(n)
    Set R = Nothing
    Set S = Nothing
End Function
Public Sub main()
    Dim i As Long
    Debug.Print "The first ten values of R are:"
    For i = 1 To 10
        Debug.Print ffr(i);
    Next i
    Debug.Print
    Dim x As New Collection
    For i = 1 To 1000
        x.Add i, CStr(i)
    Next i
    For i = 1 To 40
        x.Remove CStr(ffr(i))
    Next i
    For i = 1 To 960
        x.Remove CStr(ffs(i))
    Next i
    Debug.Print "The first 40 values of ffr plus the first 960 values of ffs "
    Debug.Print "include all the integers from 1 to 1000 exactly once is "; Format(x.Count = 0)
End Sub




Ada: package Hofstadter_Figure_Figure is

   function FFR(P: Positive) return Positive;

   function FFS(P: Positive) return Positive;

end Hofstadter_Figure_Figure;
Task: Hofstadter Figure-Figure sequences

C: #include <stdio.h>
#include <stdlib.h>


typedef unsigned long long xint;

typedef struct {
	size_t len, alloc;
	xint *buf;
} xarray;

xarray rs, ss;

void setsize(xarray *a, size_t size)
{
	size_t n = a->alloc;
	if (!n) n = 1;

	while (n < size) n <<= 1;
	if (a->alloc < n) {
		a->buf = realloc(a->buf, sizeof(xint) * n);
		if (!a->buf) abort();
		a->alloc = n;
	}
}

void push(xarray *a, xint v)
{
	while (a->alloc <= a->len)
		setsize(a, a->alloc * 2);

	a->buf[a->len++] = v;
}



void RS_append(void);

xint R(int n)
{
	while (n > rs.len) RS_append();
	return rs.buf[n - 1];
}

xint S(int n)
{
	while (n > ss.len) RS_append();
	return ss.buf[n - 1];
}

void RS_append()
{
	int n = rs.len;
	xint r = R(n) + S(n);
	xint s = S(ss.len);

	push(&rs, r);
	while (++s < r) push(&ss, s);
	push(&ss, r + 1); 
}

int main(void)
{
	push(&rs, 1);
	push(&ss, 2);

	int i;
	printf("R(1 .. 10):");
	for (i = 1; i <= 10; i++)
		printf(" %llu", R(i));

	char seen[1001] = { 0 };
	for (i = 1; i <=  40; i++) seen[ R(i) ] = 1;
	for (i = 1; i <= 960; i++) seen[ S(i) ] = 1;
	for (i = 1; i <= 1000 && seen[i]; i++);

	if (i <= 1000) {
		fprintf(stderr, "%d not seen\n", i);
		abort();
	}

	puts("\nfirst 1000 ok");
	return 0;
}
Task: Hofstadter Figure-Figure sequences



C#: using System;
using System.Collections.Generic;
using System.Linq;

namespace HofstadterFigureFigure
{
	class HofstadterFigureFigure
	{
		readonly List<int> _r = new List<int>() {1};
		readonly List<int> _s = new List<int>();

		public IEnumerable<int> R()
		{
			int iR = 0;
			while (true)
			{
				if (iR >= _r.Count)
				{
					Advance();
				}
				yield return _r[iR++];
			}
		}

		public IEnumerable<int> S()
		{
			int iS = 0;
			while (true)
			{
				if (iS >= _s.Count)
				{
					Advance();
				}
				yield return _s[iS++];
			}
		}

		private void Advance()
		{
			int rCount = _r.Count;
			int oldR = _r[rCount - 1];
			int sVal;
			
			
			switch (rCount)
			{
				case 1:
					sVal = 2;
					break;
				case 2:
					sVal = 4;
					break;
				default:
					sVal = _s[rCount - 1];
					break;
			}
			_r.Add(_r[rCount - 1] + sVal);
			int newR = _r[rCount];
			for (int iS = oldR + 1; iS < newR; iS++)
			{
				_s.Add(iS);
			}
		}
	}

	class Program
	{
		static void Main()
		{
			var hff = new HofstadterFigureFigure();
			var rs = hff.R();
			var arr = rs.Take(40).ToList();

			foreach(var v in arr.Take(10))
			{
				Console.WriteLine("{0}", v);
			}

			var hs = new HashSet<int>(arr);
			hs.UnionWith(hff.S().Take(960));
			Console.WriteLine(hs.Count == 1000 ? "Verified" : "Oops!  Something's wrong!");
		}
	}
}
Task: Hofstadter Figure-Figure sequences


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

using namespace std;

unsigned hofstadter(unsigned rlistSize, unsigned slistSize)
{
    auto n = rlistSize > slistSize ? rlistSize : slistSize;
    auto rlist = new vector<unsigned> { 1, 3, 7 };
    auto slist = new vector<unsigned> { 2, 4, 5, 6 };
    auto list = rlistSize > 0 ? rlist : slist;
    auto target_size = rlistSize > 0 ? rlistSize : slistSize;

    while (list->size() > target_size) list->pop_back();

    while (list->size() < target_size)
    {
        auto lastIndex = rlist->size() - 1;
        auto lastr = (*rlist)[lastIndex];
        auto r = lastr + (*slist)[lastIndex];
        rlist->push_back(r);
        for (auto s = lastr + 1; s < r && list->size() < target_size;)
            slist->push_back(s++);
    }

    auto v = (*list)[n - 1];
    delete rlist;
    delete slist;
    return v;
}

ostream& operator<<(ostream& os, const set<unsigned>& s)
{
    cout << '(' << s.size() << "):";
    auto i = 0;
    for (auto c = s.begin(); c != s.end();)
    {
        if (i++ % 20 == 0) os << endl;
        os << setw(5) << *c++;
    }
    return os;
}

int main(int argc, const char* argv[])
{
    const auto v1 = atoi(argv[1]);
    const auto v2 = atoi(argv[2]);
    set<unsigned> r, s;
    for (auto n = 1; n <= v2; n++)
    {
        if (n <= v1)
            r.insert(hofstadter(n, 0));
        s.insert(hofstadter(0, n));
    }
    cout << "R" << r << endl;
    cout << "S" << s << endl;

    int m = max(*r.rbegin(), *s.rbegin());
    for (auto n = 1; n <= m; n++)
        if (r.count(n) == s.count(n))
            clog << "integer " << n << " either in both or neither set" << endl;

    return 0;
}
Task: Hofstadter Figure-Figure sequences





Java: import java.util.*;

class Hofstadter
{
  private static List<Integer> getSequence(int rlistSize, int slistSize)
  {
    List<Integer> rlist = new ArrayList<Integer>();
    List<Integer> slist = new ArrayList<Integer>();
    Collections.addAll(rlist, 1, 3, 7);
    Collections.addAll(slist, 2, 4, 5, 6);
    List<Integer> list = (rlistSize > 0) ? rlist : slist;
    int targetSize = (rlistSize > 0) ? rlistSize : slistSize;
    while (list.size() > targetSize)
      list.remove(list.size() - 1);
    while (list.size() < targetSize)
    {
      int lastIndex = rlist.size() - 1;
      int lastr = rlist.get(lastIndex).intValue();
      int r = lastr + slist.get(lastIndex).intValue();
      rlist.add(Integer.valueOf(r));
      for (int s = lastr + 1; (s < r) && (list.size() < targetSize); s++)
        slist.add(Integer.valueOf(s));
    }
    return list;
  }
  
  public static int ffr(int n)
  {  return getSequence(n, 0).get(n - 1).intValue();  }
  
  public static int ffs(int n)
  {  return getSequence(0, n).get(n - 1).intValue();  }
  
  public static void main(String[] args)
  {
    System.out.print("R():");
    for (int n = 1; n <= 10; n++)
      System.out.print(" " + ffr(n));
    System.out.println();
    
    Set<Integer> first40R = new HashSet<Integer>();
    for (int n = 1; n <= 40; n++)
      first40R.add(Integer.valueOf(ffr(n)));
      
    Set<Integer> first960S = new HashSet<Integer>();
    for (int n = 1; n <= 960; n++)
      first960S.add(Integer.valueOf(ffs(n)));
    
    for (int i = 1; i <= 1000; i++)
    {
      Integer n = Integer.valueOf(i);
      if (first40R.contains(n) == first960S.contains(n))
        System.out.println("Integer " + i + " either in both or neither set");
    }
    System.out.println("Done");
  }
}
Task: Hofstadter Figure-Figure sequences







Python: def ffr(n):
    if n < 1 or type(n) != int: raise ValueError("n must be an int >= 1")
    try:
        return ffr.r[n]
    except IndexError:
        r, s = ffr.r, ffs.s
        ffr_n_1 = ffr(n-1)
        lastr = r[-1]
        
        s += list(range(s[-1] + 1, lastr))
        if s[-1] < lastr: s += [lastr + 1]
        
        len_s = len(s)
        ffs_n_1 = s[n-1] if len_s > n else (n - len_s) + s[-1]
        ans = ffr_n_1 + ffs_n_1
        r.append(ans)
        return ans
ffr.r = [None, 1]

def ffs(n):
    if n < 1 or type(n) != int: raise ValueError("n must be an int >= 1")
    try:
        return ffs.s[n]
    except IndexError:
        r, s = ffr.r, ffs.s
        for i in range(len(r), n+2):
            ffr(i)
            if len(s) > n:
                return s[n]
        raise Exception("Whoops!")
ffs.s = [None, 2]

if __name__ == '__main__':
    first10 = [ffr(i) for i in range(1,11)]
    assert first10 == [1, 3, 7, 12, 18, 26, 35, 45, 56, 69], "ffr() value error(s)"
    print("ffr(n) for n = [1..10] is", first10)
    
    bin = [None] + [0]*1000
    for i in range(40, 0, -1):
        bin[ffr(i)] += 1
    for i in range(960, 0, -1):
        bin[ffs(i)] += 1
    if all(b == 1 for b in bin[1:1000]):
        print("All Integers 1..1000 found OK")
    else:
        print("All Integers 1..1000 NOT found only once: ERROR")
Task: Hofstadter Figure-Figure sequences








VB: Private Function ffr(n As Long) As Long
    Dim R As New Collection
    Dim S As New Collection
    R.Add 1
    S.Add 2
    
    For i = 2 To n
        R.Add R(i - 1) + S(i - 1)
        For j = S(S.Count) + 1 To R(i) - 1
            S.Add j
        Next j
        For j = R(i) + 1 To R(i) + S(i - 1)
            S.Add j
        Next j
    Next i
    ffr = R(n)
    Set R = Nothing
    Set S = Nothing
End Function
Private Function ffs(n As Long) As Long
    Dim R As New Collection
    Dim S As New Collection
    R.Add 1
    S.Add 2
    
    For i = 2 To n
        R.Add R(i - 1) + S(i - 1)
        For j = S(S.Count) + 1 To R(i) - 1
            S.Add j
        Next j
        For j = R(i) + 1 To R(i) + S(i - 1)
            S.Add j
        Next j
        If S.Count >= n Then Exit For
    Next i
    ffs = S(n)
    Set R = Nothing
    Set S = Nothing
End Function
Public Sub main()
    Dim i As Long
    Debug.Print "The first ten values of R are:"
    For i = 1 To 10
        Debug.Print ffr(i);
    Next i
    Debug.Print
    Dim x As New Collection
    For i = 1 To 1000
        x.Add i, CStr(i)
    Next i
    For i = 1 To 40
        x.Remove CStr(ffr(i))
    Next i
    For i = 1 To 960
        x.Remove CStr(ffs(i))
    Next i
    Debug.Print "The first 40 values of ffr plus the first 960 values of ffs "
    Debug.Print "include all the integers from 1 to 1000 exactly once is "; Format(x.Count = 0)
End Sub
Task: Hofstadter Figure-Figure sequences




Go: package main

import "fmt"

var ffr, ffs func(int) int




func init() {
    
    r := []int{0, 1}
    s := []int{0, 2}

    ffr = func(n int) int {
        for len(r) <= n {
            nrk := len(r) - 1       
            rNxt := r[nrk] + s[nrk] 
            r = append(r, rNxt)     
            for sn := r[nrk] + 2; sn < rNxt; sn++ {
                s = append(s, sn)   
            }
            s = append(s, rNxt+1)   
        }
        return r[n]
    }

    ffs = func(n int) int {
        for len(s) <= n {
            ffr(len(r))
        }
        return s[n]
    }
}

func main() {
    
    for n := 1; n <= 10; n++ {
        fmt.Printf("r(%d): %d\n", n, ffr(n))
    }
    
    var found [1001]int
    for n := 1; n <= 40; n++ {
        found[ffr(n)]++
    }
    for n := 1; n <= 960; n++ {
        found[ffs(n)]++
    }
    for i := 1; i <= 1000; i++ {
        if found[i] != 1 {
            fmt.Println("task 4: FAIL")
            return
        }
    }
    fmt.Println("task 4: PASS")
}
Task: Triplet of three numbers



C#: using System; using System.Collections.Generic; using System.Linq;
using T3 = System.Tuple<int, int, int>; using static System.Console;
class Program { static void Main() {
   WriteLine(" \"N\":  Prime Triplet    Adjacent (to previous)\n" +
             " ---- ----------------- -----------------------");
   foreach(var lmt in new double[]{6e3, 1e5, 1e6, 1e7, 1e8}) {
    var pr = PG.Primes((int)lmt); int l = 0, c = 0; bool a;
    foreach (var t in pr) { c += (a = l == t.Item1) ? 1 : 0;
      if (lmt < 1e5) WriteLine("{0,4}: {1,-18} {2}",
        t.Item1 + 1, t, a ? " *" : ""); l = t.Item3; }
    Console.WriteLine ("Up to {0:n0} there are {1:n0} prime triples, " +
      "of which {2:n0} were found to be adjacent.", lmt, pr.Count(), c); } } }

class PG { static bool[] f; static bool isPrT(int x, int y, int z) {
  if (x < 7) return false; return !f[x] && !f[y] && !f[z]; }
  public static IEnumerable<T3> Primes(int l) { f = new bool[l += 6];
  int j, lj, llj, lllj; j = lj = llj = lllj = 3;
  for (int d = 8, s = 9; s < l; lllj = llj, llj = lj, lj = j, j += 2, s += d += 8)
    if (!f[j]) { if (isPrT(lllj, lj, j)) yield return new T3(lllj, lj, j);
      for (int k = s, i = j << 1; k < l; k += i) f[k] = true; }
  for (; j < l; lllj = llj, llj = lj, lj = j, j += 2)
   if (isPrT(lllj, lj, j)) yield return new T3(lllj, lj, j); } }









Ada: with Ada.Text_Io;

procedure Triplets is

   Limit : constant := 5999;
   Prime : array (1 .. Limit + 5) of Boolean := (others => True);

   procedure Fill_Primes is
   begin
      Prime (1) := False;
      for N in 2 .. Limit loop
         if Prime (N) then
            for I in 2 .. Positive'Last loop
               exit when I * N not in Prime'Range;
               Prime (I * N) := False;
            end loop;
         end if;
      end loop;
   end Fill_Primes;

   function Is_Triplet (N : Natural) return Boolean is
   begin
      return
        Prime (N - 1) and then
        Prime (N + 3) and then
        Prime (N + 5);
   end Is_Triplet;

   package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
   use Ada.Text_Io, Natural_IO;
begin
   Natural_Io.Default_Width := 5;
   Fill_Primes;

   for N in 2 .. Limit loop
      if Is_Triplet (N) then
         Put (N, Width => 4);
         Put (":");
         Put (N - 1);
         Put (N + 3);
         Put (N + 5);
         New_Line;
      end if;
   end loop;
end Triplets;
Task: Triplet of three numbers

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define LIMIT 6000

char *primes(unsigned int limit) {
    char *p = malloc(limit + 1);
    int i, j, sqr = sqrt(limit);
    
    p[0] = p[1] = 0;
    memset(p+2, 1, limit-1);
    for (i=2; i<=sqr; i++)
        if (p[i])
            for (j=i*2; j<=limit; j+=i)
                p[j] = 0;
            
    return p;
}

int triplet(const char *p, unsigned int n) {
    return n >= 2 && p[n-1] && p[n+3] && p[n+5];
}

int main() {
    char *p = primes(LIMIT+5);
    int i;
    
    for (i=2; i<LIMIT; i++)
        if (triplet(p, i))
            printf("%4d: %4d, %4d, %4d\n", i, i-1, i+3, i+5);
    
    free(p);
    return 0;
}











Ada: with Ada.Text_Io;

procedure Triplets is

   Limit : constant := 5999;
   Prime : array (1 .. Limit + 5) of Boolean := (others => True);

   procedure Fill_Primes is
   begin
      Prime (1) := False;
      for N in 2 .. Limit loop
         if Prime (N) then
            for I in 2 .. Positive'Last loop
               exit when I * N not in Prime'Range;
               Prime (I * N) := False;
            end loop;
         end if;
      end loop;
   end Fill_Primes;

   function Is_Triplet (N : Natural) return Boolean is
   begin
      return
        Prime (N - 1) and then
        Prime (N + 3) and then
        Prime (N + 5);
   end Is_Triplet;

   package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
   use Ada.Text_Io, Natural_IO;
begin
   Natural_Io.Default_Width := 5;
   Fill_Primes;

   for N in 2 .. Limit loop
      if Is_Triplet (N) then
         Put (N, Width => 4);
         Put (":");
         Put (N - 1);
         Put (N + 3);
         Put (N + 5);
         New_Line;
      end if;
   end loop;
end Triplets;
Task: Triplet of three numbers


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

constexpr unsigned int LIMIT = 6000;

std::vector<bool> primes(unsigned int limit) {
    std::vector<bool> p(limit + 1, true);
    unsigned int root = std::sqrt(limit);

    p[0] = false;
    p[1] = false;

    for (size_t i = 2; i <= root; i++) {
        if (p[i]) {
            for (size_t j = 2 * i; j <= limit; j += i) {
                p[j] = false;
            }
        }
    }

    return p;
}

bool triplet(const std::vector<bool> &p, unsigned int n) {
    return n >= 2 && p[n - 1] && p[n + 3] && p[n + 5];
}

int main() {
    std::vector<bool> p = primes(LIMIT);

    for (size_t i = 2; i < LIMIT; i++) {
        if (triplet(p, i)) {
            printf("%4d: %4d, %4d, %4d\n", i, i - 1, i + 3, i + 5);
        }
    }

    return 0;
}










Ada: with Ada.Text_Io;

procedure Triplets is

   Limit : constant := 5999;
   Prime : array (1 .. Limit + 5) of Boolean := (others => True);

   procedure Fill_Primes is
   begin
      Prime (1) := False;
      for N in 2 .. Limit loop
         if Prime (N) then
            for I in 2 .. Positive'Last loop
               exit when I * N not in Prime'Range;
               Prime (I * N) := False;
            end loop;
         end if;
      end loop;
   end Fill_Primes;

   function Is_Triplet (N : Natural) return Boolean is
   begin
      return
        Prime (N - 1) and then
        Prime (N + 3) and then
        Prime (N + 5);
   end Is_Triplet;

   package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
   use Ada.Text_Io, Natural_IO;
begin
   Natural_Io.Default_Width := 5;
   Fill_Primes;

   for N in 2 .. Limit loop
      if Is_Triplet (N) then
         Put (N, Width => 4);
         Put (":");
         Put (N - 1);
         Put (N + 3);
         Put (N + 5);
         New_Line;
      end if;
   end loop;
end Triplets;
Task: Triplet of three numbers




Go: package main

import (
    "fmt"
    "rcu"
)

func main() {
    c := rcu.PrimeSieve(6003, false)
    var numbers []int
    fmt.Println("Numbers n < 6000 where: n - 1, n + 3, n + 5 are all primes:")
    for n := 4; n < 6000; n += 2 {
        if !c[n-1] && !c[n+3] && !c[n+5] {
            numbers = append(numbers, n)
        }
    }
    for _, n := range numbers {
        fmt.Printf("%6s  => ", rcu.Commatize(n))
        for _, p := range []int{n - 1, n + 3, n + 5} {
            fmt.Printf("%6s ", rcu.Commatize(p))
        }
        fmt.Println()
    }
    fmt.Printf("\n%d such numbers found.\n", len(numbers))
}








Ada: with Ada.Text_Io;

procedure Triplets is

   Limit : constant := 5999;
   Prime : array (1 .. Limit + 5) of Boolean := (others => True);

   procedure Fill_Primes is
   begin
      Prime (1) := False;
      for N in 2 .. Limit loop
         if Prime (N) then
            for I in 2 .. Positive'Last loop
               exit when I * N not in Prime'Range;
               Prime (I * N) := False;
            end loop;
         end if;
      end loop;
   end Fill_Primes;

   function Is_Triplet (N : Natural) return Boolean is
   begin
      return
        Prime (N - 1) and then
        Prime (N + 3) and then
        Prime (N + 5);
   end Is_Triplet;

   package Natural_Io is new Ada.Text_Io.Integer_Io (Natural);
   use Ada.Text_Io, Natural_IO;
begin
   Natural_Io.Default_Width := 5;
   Fill_Primes;

   for N in 2 .. Limit loop
      if Is_Triplet (N) then
         Put (N, Width => 4);
         Put (":");
         Put (N - 1);
         Put (N + 3);
         Put (N + 5);
         New_Line;
      end if;
   end loop;
end Triplets;