kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Smallest square that begins with n
Go: package main

import (
    "fmt"
    "math"
)

func isSquare(n int) bool {
    s := int(math.Sqrt(float64(n)))
    return s*s == n
}

func main() {
    var squares []int
outer:
    for i := 1; i < 50; i++ {
        if isSquare(i) {
            squares = append(squares, i)
        } else {
            n := i
            limit := 10
            for {
                n *= 10
                for j := 0; j < limit; j++ {
                    s := n + j
                    if isSquare(s) {
                        squares = append(squares, s)
                        continue outer
                    }
                }
                limit *= 10
            }
        }
    }
    fmt.Println("Smallest squares that begin with 'n' in [1, 49]:")
    for i, s := range squares {
        fmt.Printf("%5d  ", s)
        if ((i + 1) % 10) == 0 {
            fmt.Println()
        }
    }
    if (len(squares) % 10) != 0 {
        fmt.Println()
    }
}

Python: 

from itertools import count



def firstSquareWithPrefix(n):
    
    pfx = str(n)
    lng = len(pfx)
    return int(
        next(
            s for s in (
                str(x * x) for x in count(0)
            )
            if pfx == s[0:lng]
        )
    )



def main():
    

    print('\n'.join([
        str(firstSquareWithPrefix(x)) for x in range(1, 50)
    ]))



if __name__ == '__main__':
    main()
Task: Jensen's Device
C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}

C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}
Task: Jensen's Device
C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}

Go: package main

import "fmt"

var i int

func sum(i *int, lo, hi int, term func() float64) float64 {
    temp := 0.0
    for *i = lo; *i <= hi; (*i)++ {
        temp += term()
    }
    return temp
}

func main() {
    fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
}
Task: Jensen's Device
C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}

Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)
Task: Jensen's Device
C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}

Go: package main

import "fmt"

var i int

func sum(i *int, lo, hi int, term func() float64) float64 {
    temp := 0.0
    for *i = lo; *i <= hi; (*i)++ {
        temp += term()
    }
    return temp
}

func main() {
    fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
}
Task: Jensen's Device
C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}

Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)
Task: Jensen's Device
C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}

VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub
Task: Jensen's Device
Go: package main

import "fmt"

var i int

func sum(i *int, lo, hi int, term func() float64) float64 {
    temp := 0.0
    for *i = lo; *i <= hi; (*i)++ {
        temp += term()
    }
    return temp
}

func main() {
    fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
}

Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)
Task: Jensen's Device
Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)

VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub
Task: Jensen's Device
Go: package main

import "fmt"

var i int

func sum(i *int, lo, hi int, term func() float64) float64 {
    temp := 0.0
    for *i = lo; *i <= hi; (*i)++ {
        temp += term()
    }
    return temp
}

func main() {
    fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
}

VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub
Task: Jensen's Device
C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}

VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub
Task: Jensen's Device
C: #include <stdio.h>

int i;
double sum(int *i, int lo, int hi, double (*term)()) {
    double temp = 0;
    for (*i = lo; *i <= hi; (*i)++)
        temp += term();
    return temp;
}

double term_func() { return 1.0 / i; }

int main () {
    printf("%f\n", sum(&i, 1, 100, term_func));
    return 0;
}

PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);
Task: Jensen's Device
C#: using System;

class JensensDevice
{    
    public static double Sum(ref int i, int lo, int hi, Func<double> term)
    {
        double temp = 0.0;
        for (i = lo; i <= hi; i++)
        {
            temp += term();
        }
        return temp;
    }

    static void Main()
    {
        int i = 0;
        Console.WriteLine(Sum(ref i, 1, 100, () => 1.0 / i));
    }
}

PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);
Task: Jensen's Device
Go: package main

import "fmt"

var i int

func sum(i *int, lo, hi int, term func() float64) float64 {
    temp := 0.0
    for *i = lo; *i <= hi; (*i)++ {
        temp += term()
    }
    return temp
}

func main() {
    fmt.Printf("%f\n", sum(&i, 1, 100, func() float64 { return 1.0 / float64(i) }))
}

PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);
Task: Jensen's Device
Python: class Ref(object):
    def __init__(self, value=None):
        self.value = value

def harmonic_sum(i, lo, hi, term):
    
    temp = 0
    i.value = lo
    while i.value <= hi:  
        temp += term() 
        i.value += 1   
    return temp

i = Ref()



print harmonic_sum(i, 1, 100, lambda: 1.0/i.value)

PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);
Task: Jensen's Device
VB: Private Function sum(i As String, ByVal lo As Integer, ByVal hi As Integer, term As String) As Double
    Dim temp As Double
    For k = lo To hi
        temp = temp + Evaluate(Replace(term, i, k))
    Next k
    sum = temp
End Function
Sub Jensen_Device()
    Debug.Print sum("i", 1, 100, "1/i")
    Debug.Print sum("i", 1, 100, "i*i")
    Debug.Print sum("j", 1, 100, "sin(j)")
End Sub

PHP: $i;
function sum (&$i, $lo, $hi, $term) {
    $temp = 0;
    for ($i = $lo; $i <= $hi; $i++) {
        $temp += $term();
    }
    return $temp;
}

echo sum($i, 1, 100, create_function('', 'global $i; return 1 / $i;')), "\n";


function sum ($lo,$hi)
{
 $temp = 0;
 for ($i = $lo; $i <= $hi; $i++)
 {
  $temp += (1 / $i);
 }
 return $temp;
}
echo sum(1,100);
Task: Vampire number
C: #include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>

typedef uint64_t xint;
typedef unsigned long long ull;

xint tens[20];

inline xint max(xint a, xint b) { return a > b ? a : b; }
inline xint min(xint a, xint b) { return a < b ? a : b; }
inline int ndigits(xint x)
{
	int n = 0;
	while (x) n++, x /= 10;
	return n;
}

inline xint dtally(xint x)
{
	xint t = 0;
	while (x) t += 1<<((x%10) * 6), x /= 10;

	return t;
}

int fangs(xint x, xint *f)
{
	int n = 0;
	int nd = ndigits(x);
	if (nd & 1) return 0;
	nd /= 2;

	xint lo, hi;
	lo = max(tens[nd-1], (x + tens[nd] - 2)/ (tens[nd] - 1));
	hi = min(x / lo, sqrt(x));

	xint a, b, t = dtally(x);
	for (a = lo; a <= hi; a++) {
		b = x / a;
		if (a * b == x && ((a%10) || (b%10)) && t == dtally(a) + dtally(b))
			f[n++] = a;
	}

	return n;
}

void show_fangs(xint x, xint *f, xint cnt)
{
	printf("%llu", (ull)x);
	int i;
	for (i = 0; i < cnt; i++)
		printf(" = %llu x %llu", (ull)f[i], (ull)(x / f[i]));
	putchar('\n');
}

int main(void)
{
	int i, j, n;
	xint x, f[16], bigs[] = {16758243290880ULL, 24959017348650ULL, 14593825548650ULL, 0};

	tens[0] = 1;
	for (i = 1; i < 20; i++)
		tens[i] = tens[i-1] * 10;

	for (x = 1, n = 0; n < 25; x++) {
		if (!(j = fangs(x, f))) continue;
		printf("%2d: ", ++n);
		show_fangs(x, f, j);
	}

	putchar('\n');
	for (i = 0; bigs[i]; i++) {
		if ((j = fangs(bigs[i], f)))
			show_fangs(bigs[i], f, j);
		else
			printf("%llu is not vampiric\n", (ull)bigs[i]);
	}

	return 0;
}

Go: package main

import (
    "fmt" 
    "math" 
)

func max(a, b uint64) uint64 {
    if a > b {
        return a
    }
    return b
}

func min(a, b uint64) uint64 {
    if a < b {
        return a
    }
    return b 
}
    
func ndigits(x uint64) (n int) {
    for ; x > 0; x /= 10 {
        n++ 
    }
    return 
}

func dtally(x uint64) (t uint64) {
    for ; x > 0; x /= 10 {
        t += 1 << (x % 10 * 6)
    }
    return 
}

var tens [20]uint64

func init() {
    tens[0] = 1
    for i := 1; i < 20; i++ {
        tens[i] = tens[i-1] * 10
    }
}

func fangs(x uint64) (f []uint64) {
    nd := ndigits(x)
    if nd&1 == 1 {
        return
    }
    nd /= 2
    lo := max(tens[nd-1], (x+tens[nd]-2)/(tens[nd]-1))
    hi := min(x/lo, uint64(math.Sqrt(float64(x))))
    t := dtally(x)
    for a := lo; a <= hi; a++ {
        b := x / a
        if a*b == x &&
            (a%10 > 0 || b%10 > 0) &&
            t == dtally(a)+dtally(b) {
            f = append(f, a)
        }
    }
    return
}

func showFangs(x uint64, f []uint64) {
    fmt.Print(x)
    if len(f) > 1 {
        fmt.Println()
    }
    for _, a := range f {
        fmt.Println(" =", a, "×", x/a)
    }
}

func main() {
    for x, n := uint64(1), 0; n < 26; x++ {
        if f := fangs(x); len(f) > 0 {
            n++
            fmt.Printf("%2d: ", n)
            showFangs(x, f)
        }
    }
    fmt.Println()
    for _, x := range []uint64{16758243290880, 24959017348650, 14593825548650} {
        if f := fangs(x); len(f) > 0 {
            showFangs(x, f)
        } else {
            fmt.Println(x, "is not vampiric")
        }
    }
}
Task: Euler's identity
C: #include <stdio.h>
#include <math.h>
#include <complex.h>
#include <wchar.h>
#include <locale.h>

int main() {
    wchar_t pi = L'\u03c0'; 
    wchar_t ae = L'\u2245'; 
    double complex e = cexp(M_PI * I) + 1.0;
    setlocale(LC_CTYPE, "");
    printf("e ^ %lci + 1 = [%.16f, %.16f] %lc 0\n", pi, creal(e), cimag(e), ae);
    return 0;
}

C#: using System;
using System.Numerics;

public class Program
{
    static void Main() {
        Complex e = Math.E;
        Complex i = Complex.ImaginaryOne;
        Complex π = Math.PI;
        Console.WriteLine(Complex.Pow(e, i * π) + 1);
    }
}
Task: Euler's identity
C: #include <stdio.h>
#include <math.h>
#include <complex.h>
#include <wchar.h>
#include <locale.h>

int main() {
    wchar_t pi = L'\u03c0'; 
    wchar_t ae = L'\u2245'; 
    double complex e = cexp(M_PI * I) + 1.0;
    setlocale(LC_CTYPE, "");
    printf("e ^ %lci + 1 = [%.16f, %.16f] %lc 0\n", pi, creal(e), cimag(e), ae);
    return 0;
}

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

int main() {
  std::cout << std::exp(std::complex<double>(0.0, M_PI)) + 1.0 << std::endl;
  return 0;
}
Task: Euler's identity
C: #include <stdio.h>
#include <math.h>
#include <complex.h>
#include <wchar.h>
#include <locale.h>

int main() {
    wchar_t pi = L'\u03c0'; 
    wchar_t ae = L'\u2245'; 
    double complex e = cexp(M_PI * I) + 1.0;
    setlocale(LC_CTYPE, "");
    printf("e ^ %lci + 1 = [%.16f, %.16f] %lc 0\n", pi, creal(e), cimag(e), ae);
    return 0;
}

Go: package main
 
import (
    "fmt"
    "math"
    "math/cmplx"
)
 
func main() {
    fmt.Println(cmplx.Exp(math.Pi * 1i) + 1.0)
}
Task: Euler's identity
C: #include <stdio.h>
#include <math.h>
#include <complex.h>
#include <wchar.h>
#include <locale.h>

int main() {
    wchar_t pi = L'\u03c0'; 
    wchar_t ae = L'\u2245'; 
    double complex e = cexp(M_PI * I) + 1.0;
    setlocale(LC_CTYPE, "");
    printf("e ^ %lci + 1 = [%.16f, %.16f] %lc 0\n", pi, creal(e), cimag(e), ae);
    return 0;
}

Java: public class EulerIdentity {

    public static void main(String[] args) {
        System.out.println("e ^ (i*Pi) + 1 = " + (new Complex(0, Math.PI).exp()).add(new Complex(1, 0)));
    }

    public static class Complex {

        private double x, y;
        
        public Complex(double re, double im) {
            x = re;
            y = im;
        }
        
        public Complex exp() {
            double exp = Math.exp(x);
            return new Complex(exp * Math.cos(y), exp * Math.sin(y));
        }
        
        public Complex add(Complex a) {
            return new Complex(x + a.x, y + a.y);
        }
        
        @Override
        public String toString() {
            return x + " + " + y + "i";
        }
    }
}
Task: Euler's identity
C: #include <stdio.h>
#include <math.h>
#include <complex.h>
#include <wchar.h>
#include <locale.h>

int main() {
    wchar_t pi = L'\u03c0'; 
    wchar_t ae = L'\u2245'; 
    double complex e = cexp(M_PI * I) + 1.0;
    setlocale(LC_CTYPE, "");
    printf("e ^ %lci + 1 = [%.16f, %.16f] %lc 0\n", pi, creal(e), cimag(e), ae);
    return 0;
}

Python: >>> import math
>>> math.e ** (math.pi * 1j) + 1
1.2246467991473532e-16j
Task: Euler's identity
C#: using System;
using System.Numerics;

public class Program
{
    static void Main() {
        Complex e = Math.E;
        Complex i = Complex.ImaginaryOne;
        Complex π = Math.PI;
        Console.WriteLine(Complex.Pow(e, i * π) + 1);
    }
}

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

int main() {
  std::cout << std::exp(std::complex<double>(0.0, M_PI)) + 1.0 << std::endl;
  return 0;
}
Task: Euler's identity
C++: #include <iostream>
#include <complex>

int main() {
  std::cout << std::exp(std::complex<double>(0.0, M_PI)) + 1.0 << std::endl;
  return 0;
}

Go: package main
 
import (
    "fmt"
    "math"
    "math/cmplx"
)
 
func main() {
    fmt.Println(cmplx.Exp(math.Pi * 1i) + 1.0)
}
Task: Euler's identity
C++: #include <iostream>
#include <complex>

int main() {
  std::cout << std::exp(std::complex<double>(0.0, M_PI)) + 1.0 << std::endl;
  return 0;
}

Java: public class EulerIdentity {

    public static void main(String[] args) {
        System.out.println("e ^ (i*Pi) + 1 = " + (new Complex(0, Math.PI).exp()).add(new Complex(1, 0)));
    }

    public static class Complex {

        private double x, y;
        
        public Complex(double re, double im) {
            x = re;
            y = im;
        }
        
        public Complex exp() {
            double exp = Math.exp(x);
            return new Complex(exp * Math.cos(y), exp * Math.sin(y));
        }
        
        public Complex add(Complex a) {
            return new Complex(x + a.x, y + a.y);
        }
        
        @Override
        public String toString() {
            return x + " + " + y + "i";
        }
    }
}
Task: Euler's identity
C++: #include <iostream>
#include <complex>

int main() {
  std::cout << std::exp(std::complex<double>(0.0, M_PI)) + 1.0 << std::endl;
  return 0;
}

Python: >>> import math
>>> math.e ** (math.pi * 1j) + 1
1.2246467991473532e-16j
Task: Euler's identity
C#: using System;
using System.Numerics;

public class Program
{
    static void Main() {
        Complex e = Math.E;
        Complex i = Complex.ImaginaryOne;
        Complex π = Math.PI;
        Console.WriteLine(Complex.Pow(e, i * π) + 1);
    }
}

Go: package main
 
import (
    "fmt"
    "math"
    "math/cmplx"
)
 
func main() {
    fmt.Println(cmplx.Exp(math.Pi * 1i) + 1.0)
}
Task: Euler's identity
C#: using System;
using System.Numerics;

public class Program
{
    static void Main() {
        Complex e = Math.E;
        Complex i = Complex.ImaginaryOne;
        Complex π = Math.PI;
        Console.WriteLine(Complex.Pow(e, i * π) + 1);
    }
}

Python: >>> import math
>>> math.e ** (math.pi * 1j) + 1
1.2246467991473532e-16j
Task: Euler's identity
Go: package main
 
import (
    "fmt"
    "math"
    "math/cmplx"
)
 
func main() {
    fmt.Println(cmplx.Exp(math.Pi * 1i) + 1.0)
}

Java: public class EulerIdentity {

    public static void main(String[] args) {
        System.out.println("e ^ (i*Pi) + 1 = " + (new Complex(0, Math.PI).exp()).add(new Complex(1, 0)));
    }

    public static class Complex {

        private double x, y;
        
        public Complex(double re, double im) {
            x = re;
            y = im;
        }
        
        public Complex exp() {
            double exp = Math.exp(x);
            return new Complex(exp * Math.cos(y), exp * Math.sin(y));
        }
        
        public Complex add(Complex a) {
            return new Complex(x + a.x, y + a.y);
        }
        
        @Override
        public String toString() {
            return x + " + " + y + "i";
        }
    }
}
Task: Euler's identity
Java: public class EulerIdentity {

    public static void main(String[] args) {
        System.out.println("e ^ (i*Pi) + 1 = " + (new Complex(0, Math.PI).exp()).add(new Complex(1, 0)));
    }

    public static class Complex {

        private double x, y;
        
        public Complex(double re, double im) {
            x = re;
            y = im;
        }
        
        public Complex exp() {
            double exp = Math.exp(x);
            return new Complex(exp * Math.cos(y), exp * Math.sin(y));
        }
        
        public Complex add(Complex a) {
            return new Complex(x + a.x, y + a.y);
        }
        
        @Override
        public String toString() {
            return x + " + " + y + "i";
        }
    }
}

Python: >>> import math
>>> math.e ** (math.pi * 1j) + 1
1.2246467991473532e-16j
Task: Euler's identity
Go: package main
 
import (
    "fmt"
    "math"
    "math/cmplx"
)
 
func main() {
    fmt.Println(cmplx.Exp(math.Pi * 1i) + 1.0)
}

Python: >>> import math
>>> math.e ** (math.pi * 1j) + 1
1.2246467991473532e-16j
Task: Euler's identity
C#: using System;
using System.Numerics;

public class Program
{
    static void Main() {
        Complex e = Math.E;
        Complex i = Complex.ImaginaryOne;
        Complex π = Math.PI;
        Console.WriteLine(Complex.Pow(e, i * π) + 1);
    }
}

Java: public class EulerIdentity {

    public static void main(String[] args) {
        System.out.println("e ^ (i*Pi) + 1 = " + (new Complex(0, Math.PI).exp()).add(new Complex(1, 0)));
    }

    public static class Complex {

        private double x, y;
        
        public Complex(double re, double im) {
            x = re;
            y = im;
        }
        
        public Complex exp() {
            double exp = Math.exp(x);
            return new Complex(exp * Math.cos(y), exp * Math.sin(y));
        }
        
        public Complex add(Complex a) {
            return new Complex(x + a.x, y + a.y);
        }
        
        @Override
        public String toString() {
            return x + " + " + y + "i";
        }
    }
}