WeixiangYan/CodeTransOcean huggingface dataset:
Task: Closest-pair problem



C#: class Segment
{
    public Segment(PointF p1, PointF p2)
    {
        P1 = p1;
        P2 = p2;
    }

    public readonly PointF P1;
    public readonly PointF P2;

    public float Length()
    {
        return (float)Math.Sqrt(LengthSquared());
    }

    public float LengthSquared()
    {
        return (P1.X - P2.X) * (P1.X - P2.X)
            + (P1.Y - P2.Y) * (P1.Y - P2.Y);
    }
}


Go: package main

import (
    "fmt"
    "math"
    "math/rand"
    "time"
)

type xy struct {
    x, y float64
}

const n = 1000
const scale = 100.

func d(p1, p2 xy) float64 {
    return math.Hypot(p2.x-p1.x, p2.y-p1.y)
}

func main() {
    rand.Seed(time.Now().Unix())
    points := make([]xy, n)
    for i := range points {
        points[i] = xy{rand.Float64() * scale, rand.Float64() * scale}
    }
    p1, p2 := closestPair(points)
    fmt.Println(p1, p2)
    fmt.Println("distance:", d(p1, p2))
}

func closestPair(points []xy) (p1, p2 xy) {
    if len(points) < 2 {
        panic("at least two points expected")
    }
    min := 2 * scale
    for i, q1 := range points[:len(points)-1] {
        for _, q2 := range points[i+1:] {
            if dq := d(q1, q2); dq < min {
                p1, p2 = q1, q2
                min = dq
            }
        }
    }
    return
}
Task: Address of a variable



C#: int i = 5;
int* p = &i;


Go: package main

import (
	"fmt"
	"unsafe"
)

func main() {
	myVar := 3.14
	myPointer := &myVar
	fmt.Println("Address:", myPointer, &myVar)
	fmt.Printf("Address: %p %p\n", myPointer, &myVar)

	var addr64 int64
	var addr32 int32
	ptr := unsafe.Pointer(myPointer)
	if unsafe.Sizeof(ptr) <= unsafe.Sizeof(addr64) {
		addr64 = int64(uintptr(ptr))
		fmt.Printf("Pointer stored in   int64: %#016x\n", addr64)
	}
	if unsafe.Sizeof(ptr) <= unsafe.Sizeof(addr32) {
		
		addr32 = int32(uintptr(ptr))
		fmt.Printf("Pointer stored in   int32: %#08x\n", addr32)
	}
	addr := uintptr(ptr)
	fmt.Printf("Pointer stored in uintptr: %#08x\n", addr)

	fmt.Println("value as float:", myVar)
	i := (*int32)(unsafe.Pointer(&myVar))
	fmt.Printf("value as int32: %#08x\n", *i)
}
Task: Inheritance_Single



C#: class Animal
{ 
   
  
}

class Dog : Animal
{ 
   
  
}

class Lab : Dog
{ 
   
  
}

class Collie : Dog
{ 
  
  
}

class Cat : Animal
{ 
  
  
}


Go: package main

type animal struct {
    alive bool
}

type dog struct {
    animal
    obedienceTrained bool
}

type cat struct {
    animal
    litterBoxTrained bool
}

type lab struct {
    dog
    color string
}

type collie struct {
    dog
    catchesFrisbee bool
}

func main() {
    var pet lab
    pet.alive = true
    pet.obedienceTrained = false
    pet.color = "yellow"
}
Task: Associative array_Creation



C#: System.Collections.HashTable map = new System.Collections.HashTable();
map["key1"] = "foo";


Go: 
var x map[string]int


x = make(map[string]int)


x = make(map[string]int, 42)


x["foo"] = 3


y1 := x["bar"]     
y2, ok := x["bar"] 


delete(x, "foo")


x = map[string]int{
	"foo": 2, "bar": 42, "baz": -1,
}
Task: Polymorphism



C#: using System;
class Point
{
  protected int x, y;
  public Point() : this(0) {}
  public Point(int x) : this(x,0) {}
  public Point(int x, int y) { this.x = x; this.y = y; }
  public int X { get { return x; } set { x = value; } }
  public int Y { get { return y; } set { y = value; } }
  public virtual void print() { System.Console.WriteLine("Point"); }
}

public class Circle : Point
{
  private int r;
  public Circle(Point p) : this(p,0) { }
  public Circle(Point p, int r) : base(p) { this.r = r; }
  public Circle() : this(0) { }
  public Circle(int x) : this(x,0) { }
  public Circle(int x, int y) : this(x,y,0) { }
  public Circle(int x, int y, int r) : base(x,y) { this.r = r; }
  public int R { get { return r; } set { r = value; } }
  public override void print() { System.Console.WriteLine("Circle"); }
 
  public static void main(String args[])
  {
    Point p = new Point();
    Point c = new Circle();
    p.print();
    c.print();
  }
}


Go: package main

import "fmt"

type point struct {
    x, y float64
}

type circle struct {
    x, y, r float64
}

type printer interface {
    print()
}

func (p *point) print() {
    fmt.Println(p.x, p.y)
}

func (c *circle) print() {
    fmt.Println(c.x, c.y, c.r)
}

func main() {
    var i printer            
    i = newPoint(3, 4)       
    i.print()                
    i = newCircle(5, 12, 13) 
    i.print()                
}












func (p *point) getX() float64  { return p.x }
func (p *point) getY() float64  { return p.y }
func (p *point) setX(v float64) { p.x = v }
func (p *point) setY(v float64) { p.y = v }

func (c *circle) getX() float64  { return c.x }
func (c *circle) getY() float64  { return c.y }
func (c *circle) getR() float64  { return c.r }
func (c *circle) setX(v float64) { c.x = v }
func (c *circle) setY(v float64) { c.y = v }
func (c *circle) setR(v float64) { c.r = v }



func (p *point) clone() *point   { r := *p; return &r }
func (c *circle) clone() *circle { r := *c; return &r }


func (p *point) set(q *point)   { *p = *q }
func (c *circle) set(d *circle) { *c = *d }










func newPoint(x, y float64) *point {
    return &point{x, y}
}
func newCircle(x, y, r float64) *circle {
    return &circle{x, y, r}
}
Task: Square root by hand



C#: using System;
using static System.Math;
using static System.Console;
using BI = System.Numerics.BigInteger;

class Program {

    static void Main(string[] args) {
        BI i, j, k, d; i = 2; int n = -1; int n0 = -1;
        j = (BI)Floor(Sqrt((double)i)); k = j; d = j;
        DateTime st = DateTime.Now;
        if (args.Length > 0) int.TryParse(args[0], out n);
        if (n > 0) n0 = n; else n = 1;
        do {
            Write(d); i = (i - k * d) * 100; k = 20 * j;
            for (d = 1; d <= 10; d++)
                if ((k + d) * d > i) { d -= 1; break; }
            j = j * 10 + d; k += d; if (n0 > 0) n--;
        } while (n > 0);
        if (n0 > 0) WriteLine("\nTime taken for {0} digits: {1}", n0, DateTime.Now - st); }

}


Go: package main

import (
    "fmt"
    "math/big"
)

var one = big.NewInt(1)
var ten = big.NewInt(10)
var twenty = big.NewInt(20)
var hundred = big.NewInt(100)

func sqrt(n float64, limit int) {
    if n < 0 {
        log.Fatal("Number cannot be negative")
    }
    count := 0
    for n != math.Trunc(n) {
        n *= 100
        count--
    }
    i := big.NewInt(int64(n))
    j := new(big.Int).Sqrt(i)
    count += len(j.String())
    k := new(big.Int).Set(j)
    d := new(big.Int).Set(j)
    t := new(big.Int)
    digits := 0
    var sb strings.Builder
    for digits < limit {
        sb.WriteString(d.String())
        t.Mul(k, d)
        i.Sub(i, t)
        i.Mul(i, hundred)
        k.Mul(j, twenty)
        d.Set(one)
        for d.Cmp(ten) <= 0 {
            t.Add(k, d)
            t.Mul(t, d)
            if t.Cmp(i) > 0 {
                d.Sub(d, one)
                break
            }
            d.Add(d, one)
        }
        j.Mul(j, ten)
        j.Add(j, d)
        k.Add(k, d)
        digits = digits + 1
    }
    root := strings.TrimRight(sb.String(), "0")
    if len(root) == 0 {
        root = "0"
    }
    if count > 0 {
        root = root[0:count] + "." + root[count:]
    } else if count == 0 {
        root = "0." + root
    } else {
        root = "0." + strings.Repeat("0", -count) + root
    }
    root = strings.TrimSuffix(root, ".")
    fmt.Println(root)
}

func main() {
    numbers := []float64{2, 0.2, 10.89, 625, 0.0001}
    digits := []int{500, 80, 8, 8, 8}
    for i, n := range numbers {
        fmt.Printf("First %d significant digits (at most) of the square root of %g:\n", digits[i], n)
        sqrt(n, digits[i])
        fmt.Println()
    }
}
Task: Pandigital prime



C#: using System;
 
class Program {
  
 
  
  
 
  static void fun(char sp) {
    var sw = System.Diagnostics.Stopwatch.StartNew();
    
    
    
 
    for (int x = sp == '1' ? 7654321 : 76543201; ; x -= 18) {
 
      
      
      
      var s = x.ToString();
      for (var ch = sp; ch < '8'; ch++) if (s.IndexOf(ch) < 0) goto nxt;
 
      
      
      if (x % 3 == 0) continue;
      for (int i = 1; i * i < x; ) {
        if (x % (i += 4) == 0) goto nxt;
        if (x % (i += 2) == 0) goto nxt;
      }
      sw.Stop(); Console.WriteLine("{0}..7: {1,10:n0} {2} μs", sp, x, sw.Elapsed.TotalMilliseconds * 1000); break;
      nxt: ;
    }
  }

static void Main(string[] args) {
    fun('1');
    fun('0');
  }
}


Go: package main

import (
    "fmt"
    "rcu"
)


func factorial(n int) int {
    fact := 1
    for i := 2; i <= n; i++ {
        fact *= i
    }
    return fact
}


func permutations(input []int) [][]int {
    perms := [][]int{input}
    a := make([]int, len(input))
    copy(a, input)
    var n = len(input) - 1
    for c := 1; c < factorial(n+1); c++ {
        i := n - 1
        j := n
        for a[i] > a[i+1] {
            i--
        }
        for a[j] < a[i] {
            j--
        }
        a[i], a[j] = a[j], a[i]
        j = n
        i += 1
        for i < j {
            a[i], a[j] = a[j], a[i]
            i++
            j--
        }
        b := make([]int, len(input))
        copy(b, a)
        perms = append(perms, b)
    }
    return perms
}

func main() {
outer:
    for _, start := range []int{1, 0} {
        fmt.Printf("The largest pandigital decimal prime which uses all the digits %d..n once is:\n", start)
        for _, n := range []int{7, 4} {
            m := n + 1 - start
            list := make([]int, m)
            for i := 0; i < m; i++ {
                list[i] = i + start
            }
            perms := permutations(list)
            for i := len(perms) - 1; i >= 0; i-- {
                le := len(perms[i])
                if perms[i][le-1]%2 == 0 || perms[i][le-1] == 5 || (start == 0 && perms[i][0] == 0) {
                    continue
                }
                p := 0
                pow := 1
                for j := le - 1; j >= 0; j-- {
                    p += perms[i][j] * pow
                    pow *= 10
                }
                if rcu.IsPrime(p) {
                    fmt.Println(rcu.Commatize(p) + "\n")
                    continue outer
                }
            }
        }
    }
}
Task: Primes with digits in nondecreasing order



C#: using System.Linq; using System.Collections.Generic; using static System.Console; using static System.Math;
 
class Program {

  static int ba; static string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

  
  static string from10(int b) { string res = ""; int re; while (b > 0) {
    b = DivRem(b, ba, out re); res = chars[(byte)re] + res; } return res; }

  
  static int to10(string s) { int res = 0; foreach (char i in s)
    res = res * ba + chars.IndexOf(i); return res; }

  
  static bool nd(string s) { if (s.Length < 2) return true;
    char l = s[0]; for (int i = 1; i < s.Length; i++)
      if (chars.IndexOf(l) > chars.IndexOf(s[i]))
        return false; else l = s[i] ; return true; }

  static void Main(string[] args) { int c, lim = 1000; string s;
    foreach (var b in new List<int>{ 2, 3, 4, 5, 6, 7, 8, 9, 10, 16, 17, 27, 31, 62 }) {
      ba = b; c = 0; foreach (var a in PG.Primes(lim))
        if (nd(s = from10(a))) Write("{0,4} {1}", s, ++c % 20 == 0 ? "\n" : "");
    WriteLine("\nBase {0}: found {1} non-decreasing primes under {2:n0}\n", b, c, from10(lim)); } } } 
 
class PG { public static IEnumerable<int> Primes(int lim) {
    var flags = new bool[lim + 1]; int j; yield return 2;
    for (j = 4; j <= lim; j += 2) flags[j] = true; j = 3;
    for (int d = 8, sq = 9; sq <= lim; j += 2, sq += d += 8)
      if (!flags[j]) { yield return j;
        for (int k = sq, i = j << 1; k <= lim; k += i) flags[k] = true; }
    for (; j <= lim; j += 2) if (!flags[j]) yield return j; } }


Go: package main

import (
    "fmt"
    "rcu"
)

func nonDescending(p int) bool {
    var digits []int
    for p > 0 {
        digits = append(digits, p%10)
        p = p / 10
    }
    for i := 0; i < len(digits)-1; i++ {
        if digits[i+1] > digits[i] {
            return false
        }
    }
    return true
}

func main() {
    primes := rcu.Primes(999)
    var nonDesc []int
    for _, p := range primes {
        if nonDescending(p) {
            nonDesc = append(nonDesc, p)
        }
    }
    fmt.Println("Primes below 1,000 with digits in non-decreasing order:")
    for i, n := range nonDesc {
        fmt.Printf("%3d ", n)
        if (i+1)%10 == 0 {
            fmt.Println()
        }
    }
    fmt.Printf("\n%d such primes found.\n", len(nonDesc))
}
Task: Numbers which are not the sum of distinct squares



C#: using System;
using System.Collections.Generic;
using System.Linq;
 
class Program {
 
  
  static bool soms(int n, IEnumerable<int> f) {
    if (n <= 0) return false;
    if (f.Contains(n)) return true;
    switch(n.CompareTo(f.Sum())) {
      case 1: return false;
      case 0: return true;
      case -1:
        var rf = f.Reverse().Skip(1).ToList();
        return soms(n - f.Last(), rf) || soms(n, rf);
    }
    return false;
  }

  static void Main() {
    var sw = System.Diagnostics.Stopwatch.StartNew();
    int c = 0, r, i, g; var s = new List<int>(); var a = new List<int>();
    var sf = "stopped checking after finding {0} sequential non-gaps after the final gap of {1}";
    for (i = 1, g = 1; g >= (i >> 1); i++) {
      if ((r = (int)Math.Sqrt(i)) * r == i) s.Add(i);
      if (!soms(i, s)) a.Add(g = i);
    }
    sw.Stop();
    Console.WriteLine("Numbers which are not the sum of distinct squares:");
    Console.WriteLine(string.Join(", ", a));
    Console.WriteLine(sf, i - g, g);
    Console.Write("found {0} total in {1} ms",
      a.Count, sw.Elapsed.TotalMilliseconds);
  }
}


Go: package main

import (
    "fmt"
    "math"
    "rcu"
)

func contains(a []int, n int) bool {
    for _, e := range a {
        if e == n {
            return true
        }
    }
    return false
}


func soms(n int, f []int) bool {
    if n <= 0 {
        return false
    }
    if contains(f, n) {
        return true
    }
    sum := rcu.SumInts(f)
    if n > sum {
        return false
    }
    if n == sum {
        return true
    }
    rf := make([]int, len(f))
    copy(rf, f)
    for i, j := 0, len(rf)-1; i < j; i, j = i+1, j-1 {
        rf[i], rf[j] = rf[j], rf[i]
    }
    rf = rf[1:]
    return soms(n-f[len(f)-1], rf) || soms(n, rf)
}

func main() {
    var s, a []int
    sf := "\nStopped checking after finding %d sequential non-gaps after the final gap of %d\n"
    i, g := 1, 1
    for g >= (i >> 1) {
        r := int(math.Sqrt(float64(i)))
        if r*r == i {
            s = append(s, i)
        }
        if !soms(i, s) {
            g = i
            a = append(a, g)
        }
        i++
    }
    fmt.Println("Numbers which are not the sum of distinct squares:")
    fmt.Println(a)
    fmt.Printf(sf, i-g, g)
    fmt.Printf("Found %d in total\n", len(a))
}

var r int
Task: Primes which contain only one odd digit



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

class Program
{
    
    
    static List<uint> sieve(uint max, bool ordinary = false)
    {
        uint k = ((max - 3) >> 1) + 1,
           lmt = ((uint)(Math.Sqrt(max++) - 3) >> 1) + 1;
        var pl = new List<uint> { };
        var ic = new bool[k];
        for (uint i = 0, p = 3; i < lmt; i++, p += 2) if (!ic[i])
                for (uint j = (p * p - 3) >> 1; j < k; j += p) ic[j] = true;
        if (ordinary)
        {
            pl.Add(2);
            for (uint i = 0, j = 3; i < k; i++, j += 2)
                if (!ic[i]) pl.Add(j);
        }
        else
            for (uint i = 0, j = 3, t = j; i < k; i++, t = j += 2)
                if (!ic[i])
                {
                    while ((t /= 10) > 0)
                        if (((t % 10) & 1) == 1) goto skip;
                    pl.Add(j);
                skip:;
                }
        return pl;
    }

    static void Main(string[] args)
    {
        var pl = sieve((uint)1e9);
        uint c = 0, l = 10, p = 1;
        Console.WriteLine("List of one-odd-digit primes < 1,000:");
        for (int i = 0; pl[i] < 1000; i++)
            Console.Write("{0,3}{1}", pl[i], i % 9 == 8 ? "\n" : "  ");
        string fmt = "\nFound {0:n0} one-odd-digit primes < 10^{1} ({2:n0})";
        foreach (var itm in pl)
            if (itm < l) c++;
            else Console.Write(fmt, c++, p++, l, l *= 10);
        Console.Write(fmt, c++, p++, l);
    }
}


Go: package main

import (
    "fmt"
    "rcu"
)

func allButOneEven(prime int) bool {
    digits := rcu.Digits(prime, 10)
    digits = digits[:len(digits)-1]
    allEven := true
    for _, d := range digits {
        if d&1 == 1 {
            allEven = false
            break
        }
    }
    return allEven
}

func main() {
    const (
        LIMIT      = 999
        LIMIT2     = 9999999999
        MAX_DIGITS = 3
    )
    primes := rcu.Primes(LIMIT)
    var results []int
    for _, prime := range primes[1:] {
        if allButOneEven(prime) {
            results = append(results, prime)
        }
    }
    fmt.Println("Primes under", rcu.Commatize(LIMIT+1), "which contain only one odd digit:")
    for i, p := range results {
        fmt.Printf("%*s ", MAX_DIGITS, rcu.Commatize(p))
        if (i+1)%9 == 0 {
            fmt.Println()
        }
    }
    fmt.Println("\nFound", len(results), "such primes.\n")

    primes = rcu.Primes(LIMIT2)
    count := 0
    pow := 10
    for _, prime := range primes[1:] {
        if allButOneEven(prime) {
            count++
        }
        if prime > pow {
            fmt.Printf("There are %7s such primes under %s\n", rcu.Commatize(count), rcu.Commatize(pow))
            pow *= 10
        }
    }
    fmt.Printf("There are %7s such primes under %s\n", rcu.Commatize(count), rcu.Commatize(pow))
}
Task: Reflection_List properties



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

public static class Reflection
{
    public static void Main() {
        var t = new TestClass();
        var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
        foreach (var prop in GetPropertyValues(t, flags)) {
            Console.WriteLine(prop);
        }
        foreach (var field in GetFieldValues(t, flags)) {
            Console.WriteLine(field);
        }
    }

    public static IEnumerable<(string name, object value)> GetPropertyValues<T>(T obj, BindingFlags flags) =>
        from p in typeof(T).GetProperties(flags)
        where p.GetIndexParameters().Length == 0 
        select (p.Name, p.GetValue(obj, null));
    
    public static IEnumerable<(string name, object value)> GetFieldValues<T>(T obj, BindingFlags flags) =>
        typeof(T).GetFields(flags).Select(f => (f.Name, f.GetValue(obj)));
    
    class TestClass
    {
        private int privateField = 7;
        public int PublicNumber { get; } = 4;
        private int PrivateNumber { get; } = 2;
    }

}


Go: package main

import (
	"fmt"
	"image"
	"reflect"
)


type t struct {
	X    int
	next *t
}

func main() {
	report(t{})
	report(image.Point{})
}

func report(x interface{}) {
	t := reflect.TypeOf(x)
	n := t.NumField()
	fmt.Printf("Type %v has %d fields:\n", t, n)
	fmt.Println("Name     Type     Exported")
	for i := 0; i < n; i++ {
		f := t.Field(i)
		fmt.Printf("%-8s %-8v %-8t\n",
			f.Name,
			f.Type,
			f.PkgPath == "",
		)
	}
	fmt.Println()
}
Task: URL parser



C#: using System;

namespace RosettaUrlParse
{
    class Program
    {
        static void ParseUrl(string url)
        {
            var u = new Uri(url);
            Console.WriteLine("URL:         {0}", u.AbsoluteUri);
            Console.WriteLine("Scheme:      {0}", u.Scheme);
            Console.WriteLine("Host:        {0}", u.DnsSafeHost);
            Console.WriteLine("Port:        {0}", u.Port);
            Console.WriteLine("Path:        {0}", u.LocalPath);
            Console.WriteLine("Query:       {0}", u.Query);
            Console.WriteLine("Fragment:    {0}", u.Fragment);
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            ParseUrl("foo:
            ParseUrl("urn:example:animal:ferret:nose");
            ParseUrl("jdbc:mysql:
            ParseUrl("ftp:
            ParseUrl("http:
            ParseUrl("ldap:
            ParseUrl("mailto:John.Doe@example.com");
            ParseUrl("news:comp.infosystems.www.servers.unix");
            ParseUrl("tel:+1-816-555-1212");
            ParseUrl("telnet:
            ParseUrl("urn:oasis:names:specification:docbook:dtd:xml:4.1.2");
        }
    }
}


Go: package main

import (
	"fmt"
	"log"
	"net"
	"net/url"
)

func main() {
	for _, in := range []string{
		"foo:
		"urn:example:animal:ferret:nose",
		"jdbc:mysql:
		"ftp:
		"http:
		"ldap:
		"mailto:John.Doe@example.com",
		"news:comp.infosystems.www.servers.unix",
		"tel:+1-816-555-1212",
		"telnet:
		"urn:oasis:names:specification:docbook:dtd:xml:4.1.2",

		"ssh:
		"https:
		"http:
	} {
		fmt.Println(in)
		u, err := url.Parse(in)
		if err != nil {
			log.Println(err)
			continue
		}
		if in != u.String() {
			fmt.Printf("Note: reassmebles as %q\n", u)
		}
		printURL(u)
	}
}

func printURL(u *url.URL) {
	fmt.Println("    Scheme:", u.Scheme)
	if u.Opaque != "" {
		fmt.Println("    Opaque:", u.Opaque)
	}
	if u.User != nil {
		fmt.Println("    Username:", u.User.Username())
		if pwd, ok := u.User.Password(); ok {
			fmt.Println("    Password:", pwd)
		}
	}
	if u.Host != "" {
		if host, port, err := net.SplitHostPort(u.Host); err == nil {
			fmt.Println("    Host:", host)
			fmt.Println("    Port:", port)
		} else {
			fmt.Println("    Host:", u.Host)
		}
	}
	if u.Path != "" {
		fmt.Println("    Path:", u.Path)
	}
	if u.RawQuery != "" {
		fmt.Println("    RawQuery:", u.RawQuery)
		m, err := url.ParseQuery(u.RawQuery)
		if err == nil {
			for k, v := range m {
				fmt.Printf("        Key: %q Values: %q\n", k, v)
			}
		}
	}
	if u.Fragment != "" {
		fmt.Println("    Fragment:", u.Fragment)
	}
}
Task: Idoneal numbers



C#: using System;

class Program {

  static void Main(string[] args) {
    var sw = System.Diagnostics.Stopwatch.StartNew();
    int a, b, c, i, n, s3, ab; var res = new int[65];
    for (n = 1, i = 0; n < 1850; n++) {
      bool found = true;
      for (a = 1; a < n; a++)
         for (b = a + 1, ab = a * b + a + b; b < n; b++, ab += a + 1) {
            if (ab > n) break;
            for (c = b + 1, s3 = ab + (b + a) * b; c < n; c++, s3 += b + a) {
                if (s3 == n) found = false;
                if (s3 >= n) break;
            }
         }
      if (found) res[i++] = n;
    }
    sw.Stop();
    Console.WriteLine("The 65 known Idoneal numbers:");
    for (i = 0; i < res.Length; i++)
      Console.Write("{0,5}{1}", res[i], i % 13 == 12 ? "\n" : "");
    Console.Write("Calculations took {0} ms", sw.Elapsed.TotalMilliseconds);
  }
}


Go: package main

import "rcu"

func isIdoneal(n int) bool {
    for a := 1; a < n; a++ {
        for b := a + 1; b < n; b++ {
            if a*b+a+b > n {
                break
            }
            for c := b + 1; c < n; c++ {
                sum := a*b + b*c + a*c
                if sum == n {
                    return false
                }
                if sum > n {
                    break
                }
            }
        }
    }
    return true
}

func main() {
    var idoneals []int
    for n := 1; n <= 1850; n++ {
        if isIdoneal(n) {
            idoneals = append(idoneals, n)
        }
    }
    rcu.PrintTable(idoneals, 13, 4, false)
}