WeixiangYan/CodeTransOcean huggingface dataset:
Task: Sum of a series

C: #include <stdio.h>

double Invsqr(double n)
{
	return 1 / (n*n);
}

int main (int argc, char *argv[])
{
	int i, start = 1, end = 1000;
	double sum = 0.0;
	
	for( i = start; i <= end; i++)
		sum += Invsqr((double)i);           
	
	printf("%16.14f\n", sum);
	
	return 0;
}








VB: Private Function sumto(n As Integer) As Double
    Dim res As Double
    For i = 1 To n
        res = res + 1 / i ^ 2
    Next i
    sumto = res
End Function
Public Sub main()
    Debug.Print sumto(1000)
End Sub
Task: Sum of a series


C++: #include <iostream>

double f(double x);

int main()
{
    unsigned int start = 1;
    unsigned int end = 1000;
    double sum = 0;

    for( unsigned int x = start; x <= end; ++x )
    {
        sum += f(x);
    }
    std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
    return 0;
}


double f(double x)
{
    return ( 1.0 / ( x * x ) );
}


C#: class Program
{
    static void Main(string[] args)
    {
        

        List<double> myList = new List<double>();
        for (double i = 1; i < 1001; i++)
        {
            myList.Add(i);
        }
        

        var sum = myList.Sum(x => 1/(x*x));

        Console.WriteLine(sum);
        Console.ReadLine();
    }
}
Task: Sum of a series


C++: #include <iostream>

double f(double x);

int main()
{
    unsigned int start = 1;
    unsigned int end = 1000;
    double sum = 0;

    for( unsigned int x = start; x <= end; ++x )
    {
        sum += f(x);
    }
    std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
    return 0;
}


double f(double x)
{
    return ( 1.0 / ( x * x ) );
}



Go: package main

import ("fmt"; "math")

func main() {
    fmt.Println("known:   ", math.Pi*math.Pi/6)
    sum := 0.
    for i := 1e3; i > 0; i-- {
        sum += 1 / (i * i)
    }
    fmt.Println("computed:", sum)
}
Task: Sum of a series


C++: #include <iostream>

double f(double x);

int main()
{
    unsigned int start = 1;
    unsigned int end = 1000;
    double sum = 0;

    for( unsigned int x = start; x <= end; ++x )
    {
        sum += f(x);
    }
    std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
    return 0;
}


double f(double x)
{
    return ( 1.0 / ( x * x ) );
}




Java: public class Sum{
    public static double f(double x){
       return 1/(x*x);
    }
 
    public static void main(String[] args){
       double start = 1;
       double end = 1000;
       double sum = 0;
 
       for(double x = start;x <= end;x++) sum += f(x);
 
       System.out.println("Sum of f(x) from " + start + " to " + end +" is " + sum);
    }
}
Task: Sum of a series


C++: #include <iostream>

double f(double x);

int main()
{
    unsigned int start = 1;
    unsigned int end = 1000;
    double sum = 0;

    for( unsigned int x = start; x <= end; ++x )
    {
        sum += f(x);
    }
    std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
    return 0;
}


double f(double x)
{
    return ( 1.0 / ( x * x ) );
}






Python: print ( sum(1.0 / (x * x) for x in range(1, 1001)) )
Task: Sum of a series


C++: #include <iostream>

double f(double x);

int main()
{
    unsigned int start = 1;
    unsigned int end = 1000;
    double sum = 0;

    for( unsigned int x = start; x <= end; ++x )
    {
        sum += f(x);
    }
    std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
    return 0;
}


double f(double x)
{
    return ( 1.0 / ( x * x ) );
}







VB: Private Function sumto(n As Integer) As Double
    Dim res As Double
    For i = 1 To n
        res = res + 1 / i ^ 2
    Next i
    sumto = res
End Function
Public Sub main()
    Debug.Print sumto(1000)
End Sub
Task: Sum of a series



C#: class Program
{
    static void Main(string[] args)
    {
        

        List<double> myList = new List<double>();
        for (double i = 1; i < 1001; i++)
        {
            myList.Add(i);
        }
        

        var sum = myList.Sum(x => 1/(x*x));

        Console.WriteLine(sum);
        Console.ReadLine();
    }
}



Java: public class Sum{
    public static double f(double x){
       return 1/(x*x);
    }
 
    public static void main(String[] args){
       double start = 1;
       double end = 1000;
       double sum = 0;
 
       for(double x = start;x <= end;x++) sum += f(x);
 
       System.out.println("Sum of f(x) from " + start + " to " + end +" is " + sum);
    }
}
Task: Sum of a series



C#: class Program
{
    static void Main(string[] args)
    {
        

        List<double> myList = new List<double>();
        for (double i = 1; i < 1001; i++)
        {
            myList.Add(i);
        }
        

        var sum = myList.Sum(x => 1/(x*x));

        Console.WriteLine(sum);
        Console.ReadLine();
    }
}






VB: Private Function sumto(n As Integer) As Double
    Dim res As Double
    For i = 1 To n
        res = res + 1 / i ^ 2
    Next i
    sumto = res
End Function
Public Sub main()
    Debug.Print sumto(1000)
End Sub
Task: Sum of a series





Java: public class Sum{
    public static double f(double x){
       return 1/(x*x);
    }
 
    public static void main(String[] args){
       double start = 1;
       double end = 1000;
       double sum = 0;
 
       for(double x = start;x <= end;x++) sum += f(x);
 
       System.out.println("Sum of f(x) from " + start + " to " + end +" is " + sum);
    }
}



Python: print ( sum(1.0 / (x * x) for x in range(1, 1001)) )
Task: Sum of a series





Java: public class Sum{
    public static double f(double x){
       return 1/(x*x);
    }
 
    public static void main(String[] args){
       double start = 1;
       double end = 1000;
       double sum = 0;
 
       for(double x = start;x <= end;x++) sum += f(x);
 
       System.out.println("Sum of f(x) from " + start + " to " + end +" is " + sum);
    }
}




VB: Private Function sumto(n As Integer) As Double
    Dim res As Double
    For i = 1 To n
        res = res + 1 / i ^ 2
    Next i
    sumto = res
End Function
Public Sub main()
    Debug.Print sumto(1000)
End Sub
Task: Sum of a series




Go: package main

import ("fmt"; "math")

func main() {
    fmt.Println("known:   ", math.Pi*math.Pi/6)
    sum := 0.
    for i := 1e3; i > 0; i-- {
        sum += 1 / (i * i)
    }
    fmt.Println("computed:", sum)
}




Python: print ( sum(1.0 / (x * x) for x in range(1, 1001)) )
Task: Sum of a series







Python: print ( sum(1.0 / (x * x) for x in range(1, 1001)) )


VB: Private Function sumto(n As Integer) As Double
    Dim res As Double
    For i = 1 To n
        res = res + 1 / i ^ 2
    Next i
    sumto = res
End Function
Public Sub main()
    Debug.Print sumto(1000)
End Sub
Task: Sum of a series

C: #include <stdio.h>

double Invsqr(double n)
{
	return 1 / (n*n);
}

int main (int argc, char *argv[])
{
	int i, start = 1, end = 1000;
	double sum = 0.0;
	
	for( i = start; i <= end; i++)
		sum += Invsqr((double)i);           
	
	printf("%16.14f\n", sum);
	
	return 0;
}




Go: package main

import ("fmt"; "math")

func main() {
    fmt.Println("known:   ", math.Pi*math.Pi/6)
    sum := 0.
    for i := 1e3; i > 0; i-- {
        sum += 1 / (i * i)
    }
    fmt.Println("computed:", sum)
}
Task: Sum of a series




Go: package main

import ("fmt"; "math")

func main() {
    fmt.Println("known:   ", math.Pi*math.Pi/6)
    sum := 0.
    for i := 1e3; i > 0; i-- {
        sum += 1 / (i * i)
    }
    fmt.Println("computed:", sum)
}





VB: Private Function sumto(n As Integer) As Double
    Dim res As Double
    For i = 1 To n
        res = res + 1 / i ^ 2
    Next i
    sumto = res
End Function
Public Sub main()
    Debug.Print sumto(1000)
End Sub
Task: Sum of a series



C#: class Program
{
    static void Main(string[] args)
    {
        

        List<double> myList = new List<double>();
        for (double i = 1; i < 1001; i++)
        {
            myList.Add(i);
        }
        

        var sum = myList.Sum(x => 1/(x*x));

        Console.WriteLine(sum);
        Console.ReadLine();
    }
}


Go: package main

import ("fmt"; "math")

func main() {
    fmt.Println("known:   ", math.Pi*math.Pi/6)
    sum := 0.
    for i := 1e3; i > 0; i-- {
        sum += 1 / (i * i)
    }
    fmt.Println("computed:", sum)
}
Task: Sum of a series



C#: class Program
{
    static void Main(string[] args)
    {
        

        List<double> myList = new List<double>();
        for (double i = 1; i < 1001; i++)
        {
            myList.Add(i);
        }
        

        var sum = myList.Sum(x => 1/(x*x));

        Console.WriteLine(sum);
        Console.ReadLine();
    }
}





Python: print ( sum(1.0 / (x * x) for x in range(1, 1001)) )
Task: Sum of a series




Go: package main

import ("fmt"; "math")

func main() {
    fmt.Println("known:   ", math.Pi*math.Pi/6)
    sum := 0.
    for i := 1e3; i > 0; i-- {
        sum += 1 / (i * i)
    }
    fmt.Println("computed:", sum)
}


Java: public class Sum{
    public static double f(double x){
       return 1/(x*x);
    }
 
    public static void main(String[] args){
       double start = 1;
       double end = 1000;
       double sum = 0;
 
       for(double x = start;x <= end;x++) sum += f(x);
 
       System.out.println("Sum of f(x) from " + start + " to " + end +" is " + sum);
    }
}
Task: Sum of a series

C: #include <stdio.h>

double Invsqr(double n)
{
	return 1 / (n*n);
}

int main (int argc, char *argv[])
{
	int i, start = 1, end = 1000;
	double sum = 0.0;
	
	for( i = start; i <= end; i++)
		sum += Invsqr((double)i);           
	
	printf("%16.14f\n", sum);
	
	return 0;
}






PHP: <?php




function sum_of_a_series($n,$k)
{
	$sum_of_a_series = 0;
	for($i=$k;$i<=$n;$i++)
	{
		$sum_of_a_series += (1/($i*$i));
	}
	return $sum_of_a_series;
}

echo sum_of_a_series(1000,1);
Task: Sum of a series



C#: class Program
{
    static void Main(string[] args)
    {
        

        List<double> myList = new List<double>();
        for (double i = 1; i < 1001; i++)
        {
            myList.Add(i);
        }
        

        var sum = myList.Sum(x => 1/(x*x));

        Console.WriteLine(sum);
        Console.ReadLine();
    }
}




PHP: <?php




function sum_of_a_series($n,$k)
{
	$sum_of_a_series = 0;
	for($i=$k;$i<=$n;$i++)
	{
		$sum_of_a_series += (1/($i*$i));
	}
	return $sum_of_a_series;
}

echo sum_of_a_series(1000,1);
Task: Sum of a series


C++: #include <iostream>

double f(double x);

int main()
{
    unsigned int start = 1;
    unsigned int end = 1000;
    double sum = 0;

    for( unsigned int x = start; x <= end; ++x )
    {
        sum += f(x);
    }
    std::cout << "Sum of f(x) from " << start << " to " << end << " is " << sum << std::endl;
    return 0;
}


double f(double x)
{
    return ( 1.0 / ( x * x ) );
}





PHP: <?php




function sum_of_a_series($n,$k)
{
	$sum_of_a_series = 0;
	for($i=$k;$i<=$n;$i++)
	{
		$sum_of_a_series += (1/($i*$i));
	}
	return $sum_of_a_series;
}

echo sum_of_a_series(1000,1);
Task: Sum of a series




Go: package main

import ("fmt"; "math")

func main() {
    fmt.Println("known:   ", math.Pi*math.Pi/6)
    sum := 0.
    for i := 1e3; i > 0; i-- {
        sum += 1 / (i * i)
    }
    fmt.Println("computed:", sum)
}



PHP: <?php




function sum_of_a_series($n,$k)
{
	$sum_of_a_series = 0;
	for($i=$k;$i<=$n;$i++)
	{
		$sum_of_a_series += (1/($i*$i));
	}
	return $sum_of_a_series;
}

echo sum_of_a_series(1000,1);
Task: Sum of a series





Java: public class Sum{
    public static double f(double x){
       return 1/(x*x);
    }
 
    public static void main(String[] args){
       double start = 1;
       double end = 1000;
       double sum = 0;
 
       for(double x = start;x <= end;x++) sum += f(x);
 
       System.out.println("Sum of f(x) from " + start + " to " + end +" is " + sum);
    }
}


PHP: <?php




function sum_of_a_series($n,$k)
{
	$sum_of_a_series = 0;
	for($i=$k;$i<=$n;$i++)
	{
		$sum_of_a_series += (1/($i*$i));
	}
	return $sum_of_a_series;
}

echo sum_of_a_series(1000,1);
Task: Sum of a series






PHP: <?php




function sum_of_a_series($n,$k)
{
	$sum_of_a_series = 0;
	for($i=$k;$i<=$n;$i++)
	{
		$sum_of_a_series += (1/($i*$i));
	}
	return $sum_of_a_series;
}

echo sum_of_a_series(1000,1);


Python: print ( sum(1.0 / (x * x) for x in range(1, 1001)) )
Task: Sum of a series






PHP: <?php




function sum_of_a_series($n,$k)
{
	$sum_of_a_series = 0;
	for($i=$k;$i<=$n;$i++)
	{
		$sum_of_a_series += (1/($i*$i));
	}
	return $sum_of_a_series;
}

echo sum_of_a_series(1000,1);



VB: Public Sub Main() 

  Print "s(1000) = "; sumSeries(1000) 
  Print "zeta(2) = "; Pi * Pi / 6  

End 

Function sumSeries(n As Integer) As Float 

  If n = 0 Then Return 0 
  Dim sum As Float = 0 
  For k As Integer = 1 To n 
    sum += 1.0 / (k * k) 
  Next 
  Return sum 

End Function
Task: Egyptian division

C: '---Ported from the c code example to BaCon by bigbass 

'==================================================================================
FUNCTION EGYPTIAN_DIVISION(long dividend, long divisor, long remainder) TYPE long 
'==================================================================================
'--- remainder is the third  parameter, pass 0 if you do not need the remainder
 
DECLARE powers[64] TYPE long 
DECLARE doublings[64] TYPE long 

	LOCAL i TYPE long
 
	FOR i = 0 TO  63 STEP 1  
		powers[i] = 1 << i
		doublings[i] = divisor << i
		IF (doublings[i] > dividend) THEN
			BREAK
		ENDIF
	NEXT

	LOCAL answer TYPE long
	LOCAL accumulator TYPE long
	answer = 0
	accumulator = 0
 
	WHILE i >= 0
		'--- If the current value of the accumulator added to the
		'--- doublings cell would be less than or equal to the
		'--- dividend then add it to the accumulator
		IF (accumulator + doublings[i] <= dividend) THEN
			accumulator = accumulator + doublings[i]
			answer = answer + powers[i]
		ENDIF
		DECR i
	WEND
 
	IF remainder THEN
		remainder = dividend - accumulator
		PRINT dividend ," / ", divisor, " = " , answer ," remainder " , remainder

        PRINT "Decoded the answer to a standard fraction"
        PRINT  (remainder + 0.0 )/ (divisor + 0.0) + answer
        PRINT

	ELSE 
		PRINT dividend ," / ", divisor , " = " , answer 
	ENDIF
	
	RETURN answer

ENDFUNCTION

 
	'--- the large number divided by the smaller number 
	'--- the third argument is 1 if you want to have a remainder
	'--- and 0 if you dont want to have a remainder 
	
	EGYPTIAN_DIVISION(580,34,1)
	EGYPTIAN_DIVISION(580,34,0)

EGYPTIAN_DIVISION(580,34,1)




Go: package main

import "fmt"

func egyptianDivide(dividend, divisor int) (quotient, remainder int) {
    if dividend < 0 || divisor <= 0 {
        panic("Invalid argument(s)")
    }
    if dividend < divisor {
        return 0, dividend
    }
    powersOfTwo := []int{1}
    doublings := []int{divisor}
    doubling := divisor
    for {
        doubling *= 2
        if doubling > dividend {
            break
        }
        l := len(powersOfTwo)
        powersOfTwo = append(powersOfTwo, powersOfTwo[l-1]*2)
        doublings = append(doublings, doubling)
    }
    answer := 0
    accumulator := 0
    for i := len(doublings) - 1; i >= 0; i-- {
        if accumulator+doublings[i] <= dividend {
            accumulator += doublings[i]
            answer += powersOfTwo[i]
            if accumulator == dividend {
                break
            }
        }
    }
    return answer, dividend - accumulator
}

func main() {
    dividend := 580
    divisor := 34
    quotient, remainder := egyptianDivide(dividend, divisor)
    fmt.Println(dividend, "divided by", divisor, "is", quotient, "with remainder", remainder)
}
Task: Egyptian division


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

typedef unsigned long ulong;


ulong egyptian_division(ulong dividend, ulong divisor, ulong* remainder) {
    constexpr int SIZE = 64;
    ulong powers[SIZE];
    ulong doublings[SIZE];
    int i = 0;

    for (; i < SIZE; ++i) {
        powers[i] = 1 << i;
        doublings[i] = divisor << i;
        if (doublings[i] > dividend) {
            break;
        }
    }

    ulong answer = 0;
    ulong accumulator = 0;

    for (i = i - 1; i >= 0; --i) {
        
        if (accumulator + doublings[i] <= dividend) {
            accumulator += doublings[i];
            answer += powers[i];
        }
    }

    if (remainder) {
        *remainder = dividend - accumulator;
    }
    return answer;
}

void print(ulong a, ulong b) {
    using namespace std;

    ulong x, y;
    x = egyptian_division(a, b, &y);

    cout << a << " / " << b << " = " << x << " remainder " << y << endl;
    assert(a == b * x + y);
}

int main() {
    print(580, 34);

    return 0;
}




Java: import java.util.ArrayList;
import java.util.List;

public class EgyptianDivision {

    
    public static void main(String[] args) {

        divide(580, 34);

    }

    
    public static void divide(int dividend, int divisor) {

        List<Integer> powersOf2 = new ArrayList<>();
        List<Integer> doublings = new ArrayList<>();

        
        int line = 0;
        while ((Math.pow(2, line) * divisor) <= dividend) { 
            int powerOf2 = (int) Math.pow(2, line);
            powersOf2.add(powerOf2);
            doublings.add(powerOf2 * divisor);
            line++;
        }

        int answer = 0;
        int accumulator = 0;

        
        for (int i = powersOf2.size() - 1; i >= 0; i--) {
            if (accumulator + doublings.get(i) <= dividend) {
                accumulator += doublings.get(i);
                answer += powersOf2.get(i);
            }
        }

        System.out.println(String.format("%d, remainder %d", answer, dividend - accumulator));
    }
}
Task: Egyptian division




Go: package main

import "fmt"

func egyptianDivide(dividend, divisor int) (quotient, remainder int) {
    if dividend < 0 || divisor <= 0 {
        panic("Invalid argument(s)")
    }
    if dividend < divisor {
        return 0, dividend
    }
    powersOfTwo := []int{1}
    doublings := []int{divisor}
    doubling := divisor
    for {
        doubling *= 2
        if doubling > dividend {
            break
        }
        l := len(powersOfTwo)
        powersOfTwo = append(powersOfTwo, powersOfTwo[l-1]*2)
        doublings = append(doublings, doubling)
    }
    answer := 0
    accumulator := 0
    for i := len(doublings) - 1; i >= 0; i-- {
        if accumulator+doublings[i] <= dividend {
            accumulator += doublings[i]
            answer += powersOfTwo[i]
            if accumulator == dividend {
                break
            }
        }
    }
    return answer, dividend - accumulator
}

func main() {
    dividend := 580
    divisor := 34
    quotient, remainder := egyptianDivide(dividend, divisor)
    fmt.Println(dividend, "divided by", divisor, "is", quotient, "with remainder", remainder)
}


Java: import java.util.ArrayList;
import java.util.List;

public class EgyptianDivision {

    
    public static void main(String[] args) {

        divide(580, 34);

    }

    
    public static void divide(int dividend, int divisor) {

        List<Integer> powersOf2 = new ArrayList<>();
        List<Integer> doublings = new ArrayList<>();

        
        int line = 0;
        while ((Math.pow(2, line) * divisor) <= dividend) { 
            int powerOf2 = (int) Math.pow(2, line);
            powersOf2.add(powerOf2);
            doublings.add(powerOf2 * divisor);
            line++;
        }

        int answer = 0;
        int accumulator = 0;

        
        for (int i = powersOf2.size() - 1; i >= 0; i--) {
            if (accumulator + doublings.get(i) <= dividend) {
                accumulator += doublings.get(i);
                answer += powersOf2.get(i);
            }
        }

        System.out.println(String.format("%d, remainder %d", answer, dividend - accumulator));
    }
}
Task: Egyptian division





Java: import java.util.ArrayList;
import java.util.List;

public class EgyptianDivision {

    
    public static void main(String[] args) {

        divide(580, 34);

    }

    
    public static void divide(int dividend, int divisor) {

        List<Integer> powersOf2 = new ArrayList<>();
        List<Integer> doublings = new ArrayList<>();

        
        int line = 0;
        while ((Math.pow(2, line) * divisor) <= dividend) { 
            int powerOf2 = (int) Math.pow(2, line);
            powersOf2.add(powerOf2);
            doublings.add(powerOf2 * divisor);
            line++;
        }

        int answer = 0;
        int accumulator = 0;

        
        for (int i = powersOf2.size() - 1; i >= 0; i--) {
            if (accumulator + doublings.get(i) <= dividend) {
                accumulator += doublings.get(i);
                answer += powersOf2.get(i);
            }
        }

        System.out.println(String.format("%d, remainder %d", answer, dividend - accumulator));
    }
}




VB: Option Explicit

Private Type MyTable
    powers_of_2 As Long
    doublings As Long
End Type

Private Type Assemble
    answer As Long
    accumulator As Long
End Type

Private Type Division
    Quotient As Long
    Remainder As Long
End Type

Private Type DivEgyp
    Dividend As Long
    Divisor As Long
End Type

Private Deg As DivEgyp

Sub Main()
Dim d As Division
    Deg.Dividend = 580
    Deg.Divisor = 34
    d = Divise(CreateTable)
    Debug.Print "Quotient = " & d.Quotient & " Remainder = " & d.Remainder
End Sub

Private Function CreateTable() As MyTable()
Dim t() As MyTable, i As Long
    Do
        i = i + 1
        ReDim Preserve t(i)
        t(i).powers_of_2 = 2 ^ (i - 1)
        t(i).doublings = Deg.Divisor * t(i).powers_of_2
    Loop While 2 * t(i).doublings <= Deg.Dividend
    CreateTable = t
End Function

Private Function Divise(t() As MyTable) As Division
Dim a As Assemble, i As Long
    a.accumulator = 0
    a.answer = 0
    For i = UBound(t) To LBound(t) Step -1
        If a.accumulator + t(i).doublings <= Deg.Dividend Then
            a.accumulator = a.accumulator + t(i).doublings
            a.answer = a.answer + t(i).powers_of_2
        End If
    Next
    Divise.Quotient = a.answer
    Divise.Remainder = Deg.Dividend - a.accumulator
End Function
Task: Egyptian division




Go: package main

import "fmt"

func egyptianDivide(dividend, divisor int) (quotient, remainder int) {
    if dividend < 0 || divisor <= 0 {
        panic("Invalid argument(s)")
    }
    if dividend < divisor {
        return 0, dividend
    }
    powersOfTwo := []int{1}
    doublings := []int{divisor}
    doubling := divisor
    for {
        doubling *= 2
        if doubling > dividend {
            break
        }
        l := len(powersOfTwo)
        powersOfTwo = append(powersOfTwo, powersOfTwo[l-1]*2)
        doublings = append(doublings, doubling)
    }
    answer := 0
    accumulator := 0
    for i := len(doublings) - 1; i >= 0; i-- {
        if accumulator+doublings[i] <= dividend {
            accumulator += doublings[i]
            answer += powersOfTwo[i]
            if accumulator == dividend {
                break
            }
        }
    }
    return answer, dividend - accumulator
}

func main() {
    dividend := 580
    divisor := 34
    quotient, remainder := egyptianDivide(dividend, divisor)
    fmt.Println(dividend, "divided by", divisor, "is", quotient, "with remainder", remainder)
}




Python: from itertools import product

def egyptian_divmod(dividend, divisor):
    assert divisor != 0
    pwrs, dbls = [1], [divisor]
    while dbls[-1] <= dividend:
        pwrs.append(pwrs[-1] * 2)
        dbls.append(pwrs[-1] * divisor)
    ans, accum = 0, 0
    for pwr, dbl in zip(pwrs[-2::-1], dbls[-2::-1]):
        if accum + dbl <= dividend:
            accum += dbl
            ans += pwr
    return ans, abs(accum - dividend)

if __name__ == "__main__":
    
    for i, j in product(range(13), range(1, 13)):
            assert egyptian_divmod(i, j) == divmod(i, j)
    
    i, j = 580, 34
    print(f'{i} divided by {j} using the Egyption method is %i remainder %i'
          % egyptian_divmod(i, j))