kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Mersenne primes
Go: package main

import (
	"fmt"
	"time"

	
	"math/big"
	
)

func main() {
	start := time.Now()
	one := big.NewInt(1)
	mp := big.NewInt(0)
	bp := big.NewInt(0)
	const max = 22
	for count, p := 0, uint(2); count < max; {
		mp.Lsh(one, p)
		mp.Sub(mp, one)
		if mp.ProbablyPrime(0) {
			elapsed := time.Since(start).Seconds()
			if elapsed >= 0.01 {
				fmt.Printf("2 ^ %-4d - 1 took %6.2f secs\n", p, elapsed)
			} else {
				fmt.Printf("2 ^ %-4d - 1\n", p)
			}
			count++
		}
		for {
			if p > 2 {
				p += 2
			} else {
				p = 3
			}
			bp.SetUint64(uint64(p))
			if bp.ProbablyPrime(0) {
				break
			}
		}
	}
}

PHP: <?php

function is_prime($n) {
    if ($n <= 3) {
        return $n > 1;
    } elseif (($n % 2 == 0) or ($n % 3 == 0)) {
        return false;
    }
    $i = 5;
    while ($i * $i <= $n) {
        if ($n % $i == 0) {
            return false;
        }
        $i += 2;
        if ($n % $i == 0) {
            return false;
        }
        $i += 4;
    }
    return true;
}

for ($i = 0 ; $i <= 63 ; $i++) {
    $pow = pow(2, $i) - 1;
    $mersenne = is_prime($pow);
    if ($mersenne) {
        echo '2 ^ ', $i, ' - 1', PHP_EOL;
    }
}
Task: Mersenne primes
Java: import java.math.BigInteger;

public class MersennePrimes {
    private static final int MAX = 20;

    private static final BigInteger ONE = BigInteger.ONE;
    private static final BigInteger TWO = BigInteger.valueOf(2);

    private static boolean isPrime(int n) {
        if (n < 2) return false;
        if (n % 2 == 0) return n == 2;
        if (n % 3 == 0) return n == 3;
        int d = 5;
        while (d * d <= n) {
            if (n % d == 0) return false;
            d += 2;
            if (n % d == 0) return false;
            d += 4;
        }
        return true;
    }

    public static void main(String[] args) {
        int count = 0;
        int p = 2;
        while (true) {
            BigInteger m = TWO.shiftLeft(p - 1).subtract(ONE);
            if (m.isProbablePrime(10)) {
                System.out.printf("2 ^ %d - 1\n", p);
                if (++count == MAX) break;
            }
            
            do {
                p = (p > 2) ? p + 2 : 3;
            } while (!isPrime(p));
        }
    }
}

PHP: <?php

function is_prime($n) {
    if ($n <= 3) {
        return $n > 1;
    } elseif (($n % 2 == 0) or ($n % 3 == 0)) {
        return false;
    }
    $i = 5;
    while ($i * $i <= $n) {
        if ($n % $i == 0) {
            return false;
        }
        $i += 2;
        if ($n % $i == 0) {
            return false;
        }
        $i += 4;
    }
    return true;
}

for ($i = 0 ; $i <= 63 ; $i++) {
    $pow = pow(2, $i) - 1;
    $mersenne = is_prime($pow);
    if ($mersenne) {
        echo '2 ^ ', $i, ' - 1', PHP_EOL;
    }
}
Task: Mersenne primes
Python: import random


def MillerRabinPrimalityTest(number):
    
    if number == 2:
        return True
    elif number == 1 or number % 2 == 0:
        return False
    
    
    
    
    oddPartOfNumber = number - 1
    
    
    timesTwoDividNumber = 0
    
    
    while oddPartOfNumber % 2 == 0:
        oddPartOfNumber = oddPartOfNumber / 2
        timesTwoDividNumber = timesTwoDividNumber + 1 
     
    
    for time in range(3):
        
        
        while True:
            
            randomNumber = random.randint(2, number)-1
            if randomNumber != 0 and randomNumber != 1:
                break
        
        
        randomNumberWithPower = pow(randomNumber, oddPartOfNumber, number)
        
        
        if (randomNumberWithPower != 1) and (randomNumberWithPower != number - 1):
            
            iterationNumber = 1
            
            
            while (iterationNumber <= timesTwoDividNumber - 1) and (randomNumberWithPower != number - 1):
                
                randomNumberWithPower = pow(randomNumberWithPower, 2, number)
                
                
                iterationNumber = iterationNumber + 1
            
            if (randomNumberWithPower != (number - 1)):
                return False
            
    
    return True


MAX = 20
p = 2
count = 0
while True:
    m = (2 << (p - 1)) - 1
    if MillerRabinPrimalityTest(m):
        print "2 ^ {} - 1".format(p)
        count = count + 1
        if count == MAX:
            break
    
    while True:
        p = p + 2 if (p > 2) else 3
        if MillerRabinPrimalityTest(p):
            break
print "done"

PHP: <?php

function is_prime($n) {
    if ($n <= 3) {
        return $n > 1;
    } elseif (($n % 2 == 0) or ($n % 3 == 0)) {
        return false;
    }
    $i = 5;
    while ($i * $i <= $n) {
        if ($n % $i == 0) {
            return false;
        }
        $i += 2;
        if ($n % $i == 0) {
            return false;
        }
        $i += 4;
    }
    return true;
}

for ($i = 0 ; $i <= 63 ; $i++) {
    $pow = pow(2, $i) - 1;
    $mersenne = is_prime($pow);
    if ($mersenne) {
        echo '2 ^ ', $i, ' - 1', PHP_EOL;
    }
}
Task: Mersenne primes
VB: Imports System.Numerics

Module Module1

    Function Sqrt(x As BigInteger) As BigInteger
        If x < 0 Then
            Throw New ArgumentException("Negative argument.")
        End If
        If x < 2 Then
            Return x
        End If
        Dim y = x / 2
        While y > (x / y)
            y = ((x / y) + y) / 2
        End While
        Return y
    End Function

    Function IsPrime(bi As BigInteger) As Boolean
        If bi < 2 Then
            Return False
        End If
        If bi Mod 2 = 0 Then
            Return bi = 2
        End If
        If bi Mod 3 = 0 Then
            Return bi = 3
        End If
        If bi Mod 5 = 0 Then
            Return bi = 5
        End If
        If bi Mod 7 = 0 Then
            Return bi = 7
        End If
        If bi Mod 11 = 0 Then
            Return bi = 11
        End If
        If bi Mod 13 = 0 Then
            Return bi = 13
        End If
        If bi Mod 17 = 0 Then
            Return bi = 17
        End If
        If bi Mod 19 = 0 Then
            Return bi = 19
        End If

        Dim limit = Sqrt(bi)
        Dim test As BigInteger = 23
        While test < limit
            If bi Mod test = 0 Then
                Return False
            End If
            test += 2
            If bi Mod test = 0 Then
                Return False
            End If
            test += 4
        End While

        Return True
    End Function

    Sub Main()
        Const MAX = 9

        Dim pow = 2
        Dim count = 0

        While True
            If IsPrime(pow) Then
                Dim p = BigInteger.Pow(2, pow) - 1
                If IsPrime(p) Then
                    Console.WriteLine("2 ^ {0} - 1", pow)
                    count += 1
                    If count >= MAX Then
                        Exit While
                    End If
                End If
            End If
            pow += 1
        End While
    End Sub

End Module

PHP: <?php

function is_prime($n) {
    if ($n <= 3) {
        return $n > 1;
    } elseif (($n % 2 == 0) or ($n % 3 == 0)) {
        return false;
    }
    $i = 5;
    while ($i * $i <= $n) {
        if ($n % $i == 0) {
            return false;
        }
        $i += 2;
        if ($n % $i == 0) {
            return false;
        }
        $i += 4;
    }
    return true;
}

for ($i = 0 ; $i <= 63 ; $i++) {
    $pow = pow(2, $i) - 1;
    $mersenne = is_prime($pow);
    if ($mersenne) {
        echo '2 ^ ', $i, ' - 1', PHP_EOL;
    }
}
Task: Nimber arithmetic
C: #include <stdio.h>
#include <stdint.h>


uint32_t hpo2(uint32_t n) {
    return n & -n;
}


uint32_t lhpo2(uint32_t n) {
    uint32_t q = 0, m = hpo2(n);
    for (; m % 2 == 0; m >>= 1, ++q) {}
    return q;
}


uint32_t nimsum(uint32_t x, uint32_t y) {
    return x ^ y;
}


uint32_t nimprod(uint32_t x, uint32_t y) {
    if (x < 2 || y < 2)
        return x * y;
    uint32_t h = hpo2(x);
    if (x > h)
        return nimprod(h, y) ^ nimprod(x ^ h, y);
    if (hpo2(y) < y)
        return nimprod(y, x);
    uint32_t xp = lhpo2(x), yp = lhpo2(y);
    uint32_t comp = xp & yp;
    if (comp == 0)
        return x * y;
    h = hpo2(comp);
    return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1));
}

void print_table(uint32_t n, char op, uint32_t(*func)(uint32_t, uint32_t)) {
    printf(" %c |", op);
    for (uint32_t a = 0; a <= n; ++a)
        printf("%3d", a);
    printf("\n--- -");
    for (uint32_t a = 0; a <= n; ++a)
        printf("---");
    printf("\n");
    for (uint32_t b = 0; b <= n; ++b) {
        printf("%2d |", b);
        for (uint32_t a = 0; a <= n; ++a)
            printf("%3d", func(a, b));
        printf("\n");
    }
}

int main() {
    print_table(15, '+', nimsum);
    printf("\n");
    print_table(15, '*', nimprod);
    const uint32_t a = 21508, b = 42689;
    printf("\n%d + %d = %d\n", a, b, nimsum(a, b));
    printf("%d * %d = %d\n", a, b, nimprod(a, b));
    return 0;
}

C#: #include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>


uint32_t hpo2(uint32_t n) {
    return n & -n;
}


uint32_t lhpo2(uint32_t n) {
    uint32_t q = 0, m = hpo2(n);
    for (; m % 2 == 0; m >>= 1, ++q) {}
    return q;
}


uint32_t nimsum(uint32_t x, uint32_t y) {
    return x ^ y;
}


uint32_t nimprod(uint32_t x, uint32_t y) {
    if (x < 2 || y < 2)
        return x * y;
    uint32_t h = hpo2(x);
    if (x > h)
        return nimprod(h, y) ^ nimprod(x ^ h, y);
    if (hpo2(y) < y)
        return nimprod(y, x);
    uint32_t xp = lhpo2(x), yp = lhpo2(y);
    uint32_t comp = xp & yp;
    if (comp == 0)
        return x * y;
    h = hpo2(comp);
    return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1));
}

void print_table(uint32_t n, char op, std::function<uint32_t(uint32_t, uint32_t)> func) {
    std::cout << ' ' << op << " |";
    for (uint32_t a = 0; a <= n; ++a)
        std::cout << std::setw(3) << a;
    std::cout << "\n--- -";
    for (uint32_t a = 0; a <= n; ++a)
        std::cout << "---";
    std::cout << '\n';
    for (uint32_t b = 0; b <= n; ++b) {
        std::cout << std::setw(2) << b << " |";
        for (uint32_t a = 0; a <= n; ++a)
            std::cout << std::setw(3) << func(a, b);
        std::cout << '\n';
    }
}

int main() {
    print_table(15, '+', nimsum);
    printf("\n");
    print_table(15, '*', nimprod);
    const uint32_t a = 21508, b = 42689;
    std::cout << '\n';
    std::cout << a << " + " << b << " = " << nimsum(a, b) << '\n';
    std::cout << a << " * " << b << " = " << nimprod(a, b) << '\n';
    return 0;
}
Task: Nimber arithmetic
C: #include <stdio.h>
#include <stdint.h>


uint32_t hpo2(uint32_t n) {
    return n & -n;
}


uint32_t lhpo2(uint32_t n) {
    uint32_t q = 0, m = hpo2(n);
    for (; m % 2 == 0; m >>= 1, ++q) {}
    return q;
}


uint32_t nimsum(uint32_t x, uint32_t y) {
    return x ^ y;
}


uint32_t nimprod(uint32_t x, uint32_t y) {
    if (x < 2 || y < 2)
        return x * y;
    uint32_t h = hpo2(x);
    if (x > h)
        return nimprod(h, y) ^ nimprod(x ^ h, y);
    if (hpo2(y) < y)
        return nimprod(y, x);
    uint32_t xp = lhpo2(x), yp = lhpo2(y);
    uint32_t comp = xp & yp;
    if (comp == 0)
        return x * y;
    h = hpo2(comp);
    return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1));
}

void print_table(uint32_t n, char op, uint32_t(*func)(uint32_t, uint32_t)) {
    printf(" %c |", op);
    for (uint32_t a = 0; a <= n; ++a)
        printf("%3d", a);
    printf("\n--- -");
    for (uint32_t a = 0; a <= n; ++a)
        printf("---");
    printf("\n");
    for (uint32_t b = 0; b <= n; ++b) {
        printf("%2d |", b);
        for (uint32_t a = 0; a <= n; ++a)
            printf("%3d", func(a, b));
        printf("\n");
    }
}

int main() {
    print_table(15, '+', nimsum);
    printf("\n");
    print_table(15, '*', nimprod);
    const uint32_t a = 21508, b = 42689;
    printf("\n%d + %d = %d\n", a, b, nimsum(a, b));
    printf("%d * %d = %d\n", a, b, nimprod(a, b));
    return 0;
}

Go: package main

import (
    "fmt"
    "strings"
)


func hpo2(n uint) uint { return n & (-n) }


func lhpo2(n uint) uint {
    q := uint(0)
    m := hpo2(n)
    for m%2 == 0 {
        m = m >> 1
        q++
    }
    return q
}


func nimsum(x, y uint) uint { return x ^ y }


func nimprod(x, y uint) uint {
    if x < 2 || y < 2 {
        return x * y
    }
    h := hpo2(x)
    if x > h {
        return nimprod(h, y) ^ nimprod(x^h, y) 
    }
    if hpo2(y) < y {
        return nimprod(y, x) 
    }
    xp, yp := lhpo2(x), lhpo2(y)
    comp := xp & yp
    if comp == 0 {
        return x * y 
    }
    h = hpo2(comp)
    
    return nimprod(nimprod(x>>h, y>>h), 3<<(h-1))
}

type fnop struct {
    fn func(x, y uint) uint
    op string
}

func main() {
    for _, f := range []fnop{{nimsum, "+"}, {nimprod, "*"}} {
        fmt.Printf(" %s |", f.op)
        for i := 0; i <= 15; i++ {
            fmt.Printf("%3d", i)
        }
        fmt.Println("\n--- " + strings.Repeat("-", 48))
        for i := uint(0); i <= 15; i++ {
            fmt.Printf("%2d |", i)
            for j := uint(0); j <= 15; j++ {
                fmt.Printf("%3d", f.fn(i, j))
            }
            fmt.Println()
        }
        fmt.Println()
    }

    a := uint(21508)
    b := uint(42689)
    fmt.Printf("%d + %d = %d\n", a, b, nimsum(a, b))
    fmt.Printf("%d * %d = %d\n", a, b, nimprod(a, b))
}
Task: Nimber arithmetic
C: #include <stdio.h>
#include <stdint.h>


uint32_t hpo2(uint32_t n) {
    return n & -n;
}


uint32_t lhpo2(uint32_t n) {
    uint32_t q = 0, m = hpo2(n);
    for (; m % 2 == 0; m >>= 1, ++q) {}
    return q;
}


uint32_t nimsum(uint32_t x, uint32_t y) {
    return x ^ y;
}


uint32_t nimprod(uint32_t x, uint32_t y) {
    if (x < 2 || y < 2)
        return x * y;
    uint32_t h = hpo2(x);
    if (x > h)
        return nimprod(h, y) ^ nimprod(x ^ h, y);
    if (hpo2(y) < y)
        return nimprod(y, x);
    uint32_t xp = lhpo2(x), yp = lhpo2(y);
    uint32_t comp = xp & yp;
    if (comp == 0)
        return x * y;
    h = hpo2(comp);
    return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1));
}

void print_table(uint32_t n, char op, uint32_t(*func)(uint32_t, uint32_t)) {
    printf(" %c |", op);
    for (uint32_t a = 0; a <= n; ++a)
        printf("%3d", a);
    printf("\n--- -");
    for (uint32_t a = 0; a <= n; ++a)
        printf("---");
    printf("\n");
    for (uint32_t b = 0; b <= n; ++b) {
        printf("%2d |", b);
        for (uint32_t a = 0; a <= n; ++a)
            printf("%3d", func(a, b));
        printf("\n");
    }
}

int main() {
    print_table(15, '+', nimsum);
    printf("\n");
    print_table(15, '*', nimprod);
    const uint32_t a = 21508, b = 42689;
    printf("\n%d + %d = %d\n", a, b, nimsum(a, b));
    printf("%d * %d = %d\n", a, b, nimprod(a, b));
    return 0;
}

Python: 
def hpo2(n): return n & (-n)


def lhpo2(n):
    q = 0
    m = hpo2(n)
    while m%2 == 0:
        m = m >> 1
        q += 1
    return q

def nimsum(x,y): return x ^ y

def nimprod(x,y):
    if x < 2 or y < 2:
        return x * y
    h = hpo2(x)
    if x > h:
        return nimprod(h, y) ^ nimprod(x^h, y) 
    if hpo2(y) < y:
        return nimprod(y, x) 
    xp, yp = lhpo2(x), lhpo2(y)
    comp = xp & yp
    if comp == 0:
        return x * y 
    h = hpo2(comp)
    
    return nimprod(nimprod(x>>h, y>>h), 3<<(h-1))

if __name__ == '__main__':
    for f, op in ((nimsum, '+'), (nimprod, '*')):
        print(f" {op} |", end='')
        for i in range(16):
            print(f"{i:3d}", end='')
        print("\n--- " + "-"*48)
        for i in range(16):
            print(f"{i:2d} |", end='')
            for j in range(16):
                print(f"{f(i,j):3d}", end='')
            print()
        print()

    a, b = 21508, 42689
    print(f"{a} + {b} = {nimsum(a,b)}")
    print(f"{a} * {b} = {nimprod(a,b)}")
Task: Nimber arithmetic
C++: #include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>


uint32_t hpo2(uint32_t n) {
    return n & -n;
}


uint32_t lhpo2(uint32_t n) {
    uint32_t q = 0, m = hpo2(n);
    for (; m % 2 == 0; m >>= 1, ++q) {}
    return q;
}


uint32_t nimsum(uint32_t x, uint32_t y) {
    return x ^ y;
}


uint32_t nimprod(uint32_t x, uint32_t y) {
    if (x < 2 || y < 2)
        return x * y;
    uint32_t h = hpo2(x);
    if (x > h)
        return nimprod(h, y) ^ nimprod(x ^ h, y);
    if (hpo2(y) < y)
        return nimprod(y, x);
    uint32_t xp = lhpo2(x), yp = lhpo2(y);
    uint32_t comp = xp & yp;
    if (comp == 0)
        return x * y;
    h = hpo2(comp);
    return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1));
}

void print_table(uint32_t n, char op, std::function<uint32_t(uint32_t, uint32_t)> func) {
    std::cout << ' ' << op << " |";
    for (uint32_t a = 0; a <= n; ++a)
        std::cout << std::setw(3) << a;
    std::cout << "\n--- -";
    for (uint32_t a = 0; a <= n; ++a)
        std::cout << "---";
    std::cout << '\n';
    for (uint32_t b = 0; b <= n; ++b) {
        std::cout << std::setw(2) << b << " |";
        for (uint32_t a = 0; a <= n; ++a)
            std::cout << std::setw(3) << func(a, b);
        std::cout << '\n';
    }
}

int main() {
    print_table(15, '+', nimsum);
    printf("\n");
    print_table(15, '*', nimprod);
    const uint32_t a = 21508, b = 42689;
    std::cout << '\n';
    std::cout << a << " + " << b << " = " << nimsum(a, b) << '\n';
    std::cout << a << " * " << b << " = " << nimprod(a, b) << '\n';
    return 0;
}

Go: package main

import (
    "fmt"
    "strings"
)


func hpo2(n uint) uint { return n & (-n) }


func lhpo2(n uint) uint {
    q := uint(0)
    m := hpo2(n)
    for m%2 == 0 {
        m = m >> 1
        q++
    }
    return q
}


func nimsum(x, y uint) uint { return x ^ y }


func nimprod(x, y uint) uint {
    if x < 2 || y < 2 {
        return x * y
    }
    h := hpo2(x)
    if x > h {
        return nimprod(h, y) ^ nimprod(x^h, y) 
    }
    if hpo2(y) < y {
        return nimprod(y, x) 
    }
    xp, yp := lhpo2(x), lhpo2(y)
    comp := xp & yp
    if comp == 0 {
        return x * y 
    }
    h = hpo2(comp)
    
    return nimprod(nimprod(x>>h, y>>h), 3<<(h-1))
}

type fnop struct {
    fn func(x, y uint) uint
    op string
}

func main() {
    for _, f := range []fnop{{nimsum, "+"}, {nimprod, "*"}} {
        fmt.Printf(" %s |", f.op)
        for i := 0; i <= 15; i++ {
            fmt.Printf("%3d", i)
        }
        fmt.Println("\n--- " + strings.Repeat("-", 48))
        for i := uint(0); i <= 15; i++ {
            fmt.Printf("%2d |", i)
            for j := uint(0); j <= 15; j++ {
                fmt.Printf("%3d", f.fn(i, j))
            }
            fmt.Println()
        }
        fmt.Println()
    }

    a := uint(21508)
    b := uint(42689)
    fmt.Printf("%d + %d = %d\n", a, b, nimsum(a, b))
    fmt.Printf("%d * %d = %d\n", a, b, nimprod(a, b))
}
Task: Nimber arithmetic
C++: #include <cstdint>
#include <functional>
#include <iomanip>
#include <iostream>


uint32_t hpo2(uint32_t n) {
    return n & -n;
}


uint32_t lhpo2(uint32_t n) {
    uint32_t q = 0, m = hpo2(n);
    for (; m % 2 == 0; m >>= 1, ++q) {}
    return q;
}


uint32_t nimsum(uint32_t x, uint32_t y) {
    return x ^ y;
}


uint32_t nimprod(uint32_t x, uint32_t y) {
    if (x < 2 || y < 2)
        return x * y;
    uint32_t h = hpo2(x);
    if (x > h)
        return nimprod(h, y) ^ nimprod(x ^ h, y);
    if (hpo2(y) < y)
        return nimprod(y, x);
    uint32_t xp = lhpo2(x), yp = lhpo2(y);
    uint32_t comp = xp & yp;
    if (comp == 0)
        return x * y;
    h = hpo2(comp);
    return nimprod(nimprod(x >> h, y >> h), 3 << (h - 1));
}

void print_table(uint32_t n, char op, std::function<uint32_t(uint32_t, uint32_t)> func) {
    std::cout << ' ' << op << " |";
    for (uint32_t a = 0; a <= n; ++a)
        std::cout << std::setw(3) << a;
    std::cout << "\n--- -";
    for (uint32_t a = 0; a <= n; ++a)
        std::cout << "---";
    std::cout << '\n';
    for (uint32_t b = 0; b <= n; ++b) {
        std::cout << std::setw(2) << b << " |";
        for (uint32_t a = 0; a <= n; ++a)
            std::cout << std::setw(3) << func(a, b);
        std::cout << '\n';
    }
}

int main() {
    print_table(15, '+', nimsum);
    printf("\n");
    print_table(15, '*', nimprod);
    const uint32_t a = 21508, b = 42689;
    std::cout << '\n';
    std::cout << a << " + " << b << " = " << nimsum(a, b) << '\n';
    std::cout << a << " * " << b << " = " << nimprod(a, b) << '\n';
    return 0;
}

Python: 
def hpo2(n): return n & (-n)


def lhpo2(n):
    q = 0
    m = hpo2(n)
    while m%2 == 0:
        m = m >> 1
        q += 1
    return q

def nimsum(x,y): return x ^ y

def nimprod(x,y):
    if x < 2 or y < 2:
        return x * y
    h = hpo2(x)
    if x > h:
        return nimprod(h, y) ^ nimprod(x^h, y) 
    if hpo2(y) < y:
        return nimprod(y, x) 
    xp, yp = lhpo2(x), lhpo2(y)
    comp = xp & yp
    if comp == 0:
        return x * y 
    h = hpo2(comp)
    
    return nimprod(nimprod(x>>h, y>>h), 3<<(h-1))

if __name__ == '__main__':
    for f, op in ((nimsum, '+'), (nimprod, '*')):
        print(f" {op} |", end='')
        for i in range(16):
            print(f"{i:3d}", end='')
        print("\n--- " + "-"*48)
        for i in range(16):
            print(f"{i:2d} |", end='')
            for j in range(16):
                print(f"{f(i,j):3d}", end='')
            print()
        print()

    a, b = 21508, 42689
    print(f"{a} + {b} = {nimsum(a,b)}")
    print(f"{a} * {b} = {nimprod(a,b)}")
Task: Nimber arithmetic
Java: import java.util.function.IntBinaryOperator;

public class Nimber {
    public static void main(String[] args) {
        printTable(15, '+', (x, y) -> nimSum(x, y));
        System.out.println();
        printTable(15, '*', (x, y) -> nimProduct(x, y));
        System.out.println();

        int a = 21508, b = 42689;
        System.out.println(a + " + " + b +  " = " + nimSum(a, b));
        System.out.println(a + " * " + b +  " = " + nimProduct(a, b));
    }

    
    public static int nimSum(int x, int y) {
        return x ^ y;
    }

    
    public static int nimProduct(int x, int y) {
        if (x < 2 || y < 2)
            return x * y;
        int h = hpo2(x);
        if (x > h)
            return nimProduct(h, y) ^ nimProduct(x ^ h, y);
        if (hpo2(y) < y)
            return nimProduct(y, x);
        int xp = lhpo2(x), yp = lhpo2(y);
        int comp = xp & yp;
        if (comp == 0)
            return x * y;
        h = hpo2(comp);
        return nimProduct(nimProduct(x >> h, y >> h), 3 << (h - 1));
    }

    
    private static int hpo2(int n) {
        return n & -n;
    }
    
    
    private static int lhpo2(int n) {
        int q = 0, m = hpo2(n);
        for (; m % 2 == 0; m >>= 1, ++q) {}
        return q;
    }

    private static void printTable(int n, char op, IntBinaryOperator func) {
        System.out.print(" " + op + " |");
        for (int a = 0; a <= n; ++a)
            System.out.printf("%3d", a);
        System.out.print("\n--- -");
        for (int a = 0; a <= n; ++a)
            System.out.print("---");
        System.out.println();
        for (int b = 0; b <= n; ++b) {
            System.out.printf("%2d |", b);
            for (int a = 0; a <= n; ++a)
                System.out.printf("%3d", func.applyAsInt(a, b));
            System.out.println();
        }
    }
}

Python: 
def hpo2(n): return n & (-n)


def lhpo2(n):
    q = 0
    m = hpo2(n)
    while m%2 == 0:
        m = m >> 1
        q += 1
    return q

def nimsum(x,y): return x ^ y

def nimprod(x,y):
    if x < 2 or y < 2:
        return x * y
    h = hpo2(x)
    if x > h:
        return nimprod(h, y) ^ nimprod(x^h, y) 
    if hpo2(y) < y:
        return nimprod(y, x) 
    xp, yp = lhpo2(x), lhpo2(y)
    comp = xp & yp
    if comp == 0:
        return x * y 
    h = hpo2(comp)
    
    return nimprod(nimprod(x>>h, y>>h), 3<<(h-1))

if __name__ == '__main__':
    for f, op in ((nimsum, '+'), (nimprod, '*')):
        print(f" {op} |", end='')
        for i in range(16):
            print(f"{i:3d}", end='')
        print("\n--- " + "-"*48)
        for i in range(16):
            print(f"{i:2d} |", end='')
            for j in range(16):
                print(f"{f(i,j):3d}", end='')
            print()
        print()

    a, b = 21508, 42689
    print(f"{a} + {b} = {nimsum(a,b)}")
    print(f"{a} * {b} = {nimprod(a,b)}")