kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Nested function
C: #include<stdlib.h>
#include<stdio.h>

typedef struct{
	char str[30];
}item;

item* makeList(char* separator){
	int counter = 0,i;
	item* list = (item*)malloc(3*sizeof(item));
	
	item makeItem(){
		item holder;
		
		char names[5][10] = {"first","second","third","fourth","fifth"};
		
		sprintf(holder.str,"%d%s%s",++counter,separator,names[counter]);
		
		return holder;
	}
	
	for(i=0;i<3;i++)
		list[i] = makeItem();
	
	return list;
}

int main()
{
	int i;
	item* list = makeList(". ");
	
	for(i=0;i<3;i++)
		printf("\n%s",list[i].str);
	
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
 
std::vector<std::string> makeList(std::string separator) {
  auto counter = 0;
  auto makeItem = [&](std::string item) {
    return std::to_string(++counter) + separator + item;
  };
  return {makeItem("first"), makeItem("second"), makeItem("third")};
}

int main() {
  for (auto item : makeList(". "))
    std::cout << item << "\n";
}
Task: Nested function
C: #include<stdlib.h>
#include<stdio.h>

typedef struct{
	char str[30];
}item;

item* makeList(char* separator){
	int counter = 0,i;
	item* list = (item*)malloc(3*sizeof(item));
	
	item makeItem(){
		item holder;
		
		char names[5][10] = {"first","second","third","fourth","fifth"};
		
		sprintf(holder.str,"%d%s%s",++counter,separator,names[counter]);
		
		return holder;
	}
	
	for(i=0;i<3;i++)
		list[i] = makeItem();
	
	return list;
}

int main()
{
	int i;
	item* list = makeList(". ");
	
	for(i=0;i<3;i++)
		printf("\n%s",list[i].str);
	
	return 0;
}

Go: package main
import "fmt"

func makeList(separator string) string {
    counter := 1

    makeItem := func(item string) string {
        result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
        counter += 1
        return result
    }

    return makeItem("first") + makeItem("second") + makeItem("third")
}

func main() {
    fmt.Print(makeList(". "))
}
Task: Nested function
C: #include<stdlib.h>
#include<stdio.h>

typedef struct{
	char str[30];
}item;

item* makeList(char* separator){
	int counter = 0,i;
	item* list = (item*)malloc(3*sizeof(item));
	
	item makeItem(){
		item holder;
		
		char names[5][10] = {"first","second","third","fourth","fifth"};
		
		sprintf(holder.str,"%d%s%s",++counter,separator,names[counter]);
		
		return holder;
	}
	
	for(i=0;i<3;i++)
		list[i] = makeItem();
	
	return list;
}

int main()
{
	int i;
	item* list = makeList(". ");
	
	for(i=0;i<3;i++)
		printf("\n%s",list[i].str);
	
	return 0;
}

Java: module NestedFunction
    {
    static String makeList(String separator)
        {
        Int counter = 1;

        function String(String) makeItem = item -> $"{counter++}{separator}{item}\n";

        return makeItem("first")
             + makeItem("second")
             + makeItem("third");
        }

    void run()
        {
        @Inject Console console;
        console.print(makeList(". "));
        }
    }
Task: Nested function
C: #include<stdlib.h>
#include<stdio.h>

typedef struct{
	char str[30];
}item;

item* makeList(char* separator){
	int counter = 0,i;
	item* list = (item*)malloc(3*sizeof(item));
	
	item makeItem(){
		item holder;
		
		char names[5][10] = {"first","second","third","fourth","fifth"};
		
		sprintf(holder.str,"%d%s%s",++counter,separator,names[counter]);
		
		return holder;
	}
	
	for(i=0;i<3;i++)
		list[i] = makeItem();
	
	return list;
}

int main()
{
	int i;
	item* list = makeList(". ");
	
	for(i=0;i<3;i++)
		printf("\n%s",list[i].str);
	
	return 0;
}

Python: def makeList(separator):
    counter = 1

    def makeItem(item):
        nonlocal counter
        result = str(counter) + separator + item + "\n"
        counter += 1
        return result

    return makeItem("first") + makeItem("second") + makeItem("third")

print(makeList(". "))
Task: Nested function
C: #include<stdlib.h>
#include<stdio.h>

typedef struct{
	char str[30];
}item;

item* makeList(char* separator){
	int counter = 0,i;
	item* list = (item*)malloc(3*sizeof(item));
	
	item makeItem(){
		item holder;
		
		char names[5][10] = {"first","second","third","fourth","fifth"};
		
		sprintf(holder.str,"%d%s%s",++counter,separator,names[counter]);
		
		return holder;
	}
	
	for(i=0;i<3;i++)
		list[i] = makeItem();
	
	return list;
}

int main()
{
	int i;
	item* list = makeList(". ");
	
	for(i=0;i<3;i++)
		printf("\n%s",list[i].str);
	
	return 0;
}

VB: Option Explicit

Private Const Sep As String = ". "
Private Counter As Integer
Sub Main()
Dim L As Variant
    Counter = 0
    L = MakeList(Array("first", "second", "third"))
    Debug.Print L
End Sub
Function MakeList(Datas) As Variant
Dim i As Integer
    For i = LBound(Datas) To UBound(Datas)
        MakeList = MakeList & MakeItem(Datas(i))
    Next i
End Function
Function MakeItem(Item As Variant) As Variant
    Counter = Counter + 1
    MakeItem = Counter & Sep & Item & vbCrLf
End Function
Task: Nested function
C#: string MakeList(string separator)
{
    int counter = 1;

    Func<string, string> makeItem = item => counter++ + separator + item + "\n";

    return makeItem("first") + makeItem("second") + makeItem("third");
}

Console.WriteLine(MakeList(". "));

C++: #include <iostream>
#include <string>
#include <vector>
 
std::vector<std::string> makeList(std::string separator) {
  auto counter = 0;
  auto makeItem = [&](std::string item) {
    return std::to_string(++counter) + separator + item;
  };
  return {makeItem("first"), makeItem("second"), makeItem("third")};
}

int main() {
  for (auto item : makeList(". "))
    std::cout << item << "\n";
}
Task: Nested function
C++: #include <iostream>
#include <string>
#include <vector>
 
std::vector<std::string> makeList(std::string separator) {
  auto counter = 0;
  auto makeItem = [&](std::string item) {
    return std::to_string(++counter) + separator + item;
  };
  return {makeItem("first"), makeItem("second"), makeItem("third")};
}

int main() {
  for (auto item : makeList(". "))
    std::cout << item << "\n";
}

Go: package main
import "fmt"

func makeList(separator string) string {
    counter := 1

    makeItem := func(item string) string {
        result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
        counter += 1
        return result
    }

    return makeItem("first") + makeItem("second") + makeItem("third")
}

func main() {
    fmt.Print(makeList(". "))
}
Task: Nested function
C++: #include <iostream>
#include <string>
#include <vector>
 
std::vector<std::string> makeList(std::string separator) {
  auto counter = 0;
  auto makeItem = [&](std::string item) {
    return std::to_string(++counter) + separator + item;
  };
  return {makeItem("first"), makeItem("second"), makeItem("third")};
}

int main() {
  for (auto item : makeList(". "))
    std::cout << item << "\n";
}

Java: module NestedFunction
    {
    static String makeList(String separator)
        {
        Int counter = 1;

        function String(String) makeItem = item -> $"{counter++}{separator}{item}\n";

        return makeItem("first")
             + makeItem("second")
             + makeItem("third");
        }

    void run()
        {
        @Inject Console console;
        console.print(makeList(". "));
        }
    }
Task: Nested function
C++: #include <iostream>
#include <string>
#include <vector>
 
std::vector<std::string> makeList(std::string separator) {
  auto counter = 0;
  auto makeItem = [&](std::string item) {
    return std::to_string(++counter) + separator + item;
  };
  return {makeItem("first"), makeItem("second"), makeItem("third")};
}

int main() {
  for (auto item : makeList(". "))
    std::cout << item << "\n";
}

Python: def makeList(separator):
    counter = 1

    def makeItem(item):
        nonlocal counter
        result = str(counter) + separator + item + "\n"
        counter += 1
        return result

    return makeItem("first") + makeItem("second") + makeItem("third")

print(makeList(". "))
Task: Nested function
C++: #include <iostream>
#include <string>
#include <vector>
 
std::vector<std::string> makeList(std::string separator) {
  auto counter = 0;
  auto makeItem = [&](std::string item) {
    return std::to_string(++counter) + separator + item;
  };
  return {makeItem("first"), makeItem("second"), makeItem("third")};
}

int main() {
  for (auto item : makeList(". "))
    std::cout << item << "\n";
}

VB: Option Explicit

Private Const Sep As String = ". "
Private Counter As Integer
Sub Main()
Dim L As Variant
    Counter = 0
    L = MakeList(Array("first", "second", "third"))
    Debug.Print L
End Sub
Function MakeList(Datas) As Variant
Dim i As Integer
    For i = LBound(Datas) To UBound(Datas)
        MakeList = MakeList & MakeItem(Datas(i))
    Next i
End Function
Function MakeItem(Item As Variant) As Variant
    Counter = Counter + 1
    MakeItem = Counter & Sep & Item & vbCrLf
End Function
Task: Nested function
C#: string MakeList(string separator)
{
    int counter = 1;

    Func<string, string> makeItem = item => counter++ + separator + item + "\n";

    return makeItem("first") + makeItem("second") + makeItem("third");
}

Console.WriteLine(MakeList(". "));

Go: package main
import "fmt"

func makeList(separator string) string {
    counter := 1

    makeItem := func(item string) string {
        result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
        counter += 1
        return result
    }

    return makeItem("first") + makeItem("second") + makeItem("third")
}

func main() {
    fmt.Print(makeList(". "))
}
Task: Nested function
C#: string MakeList(string separator)
{
    int counter = 1;

    Func<string, string> makeItem = item => counter++ + separator + item + "\n";

    return makeItem("first") + makeItem("second") + makeItem("third");
}

Console.WriteLine(MakeList(". "));

Java: module NestedFunction
    {
    static String makeList(String separator)
        {
        Int counter = 1;

        function String(String) makeItem = item -> $"{counter++}{separator}{item}\n";

        return makeItem("first")
             + makeItem("second")
             + makeItem("third");
        }

    void run()
        {
        @Inject Console console;
        console.print(makeList(". "));
        }
    }
Task: Nested function
C#: string MakeList(string separator)
{
    int counter = 1;

    Func<string, string> makeItem = item => counter++ + separator + item + "\n";

    return makeItem("first") + makeItem("second") + makeItem("third");
}

Console.WriteLine(MakeList(". "));

Python: def makeList(separator):
    counter = 1

    def makeItem(item):
        nonlocal counter
        result = str(counter) + separator + item + "\n"
        counter += 1
        return result

    return makeItem("first") + makeItem("second") + makeItem("third")

print(makeList(". "))
Task: Nested function
C#: string MakeList(string separator)
{
    int counter = 1;

    Func<string, string> makeItem = item => counter++ + separator + item + "\n";

    return makeItem("first") + makeItem("second") + makeItem("third");
}

Console.WriteLine(MakeList(". "));

VB: Option Explicit

Private Const Sep As String = ". "
Private Counter As Integer
Sub Main()
Dim L As Variant
    Counter = 0
    L = MakeList(Array("first", "second", "third"))
    Debug.Print L
End Sub
Function MakeList(Datas) As Variant
Dim i As Integer
    For i = LBound(Datas) To UBound(Datas)
        MakeList = MakeList & MakeItem(Datas(i))
    Next i
End Function
Function MakeItem(Item As Variant) As Variant
    Counter = Counter + 1
    MakeItem = Counter & Sep & Item & vbCrLf
End Function
Task: Nested function
Go: package main
import "fmt"

func makeList(separator string) string {
    counter := 1

    makeItem := func(item string) string {
        result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
        counter += 1
        return result
    }

    return makeItem("first") + makeItem("second") + makeItem("third")
}

func main() {
    fmt.Print(makeList(". "))
}

Java: module NestedFunction
    {
    static String makeList(String separator)
        {
        Int counter = 1;

        function String(String) makeItem = item -> $"{counter++}{separator}{item}\n";

        return makeItem("first")
             + makeItem("second")
             + makeItem("third");
        }

    void run()
        {
        @Inject Console console;
        console.print(makeList(". "));
        }
    }
Task: Nested function
Java: module NestedFunction
    {
    static String makeList(String separator)
        {
        Int counter = 1;

        function String(String) makeItem = item -> $"{counter++}{separator}{item}\n";

        return makeItem("first")
             + makeItem("second")
             + makeItem("third");
        }

    void run()
        {
        @Inject Console console;
        console.print(makeList(". "));
        }
    }

Python: def makeList(separator):
    counter = 1

    def makeItem(item):
        nonlocal counter
        result = str(counter) + separator + item + "\n"
        counter += 1
        return result

    return makeItem("first") + makeItem("second") + makeItem("third")

print(makeList(". "))
Task: Nested function
Go: package main
import "fmt"

func makeList(separator string) string {
    counter := 1

    makeItem := func(item string) string {
        result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
        counter += 1
        return result
    }

    return makeItem("first") + makeItem("second") + makeItem("third")
}

func main() {
    fmt.Print(makeList(". "))
}

Python: def makeList(separator):
    counter = 1

    def makeItem(item):
        nonlocal counter
        result = str(counter) + separator + item + "\n"
        counter += 1
        return result

    return makeItem("first") + makeItem("second") + makeItem("third")

print(makeList(". "))
Task: Nested function
Go: package main
import "fmt"

func makeList(separator string) string {
    counter := 1

    makeItem := func(item string) string {
        result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
        counter += 1
        return result
    }

    return makeItem("first") + makeItem("second") + makeItem("third")
}

func main() {
    fmt.Print(makeList(". "))
}

VB: Option Explicit

Private Const Sep As String = ". "
Private Counter As Integer
Sub Main()
Dim L As Variant
    Counter = 0
    L = MakeList(Array("first", "second", "third"))
    Debug.Print L
End Sub
Function MakeList(Datas) As Variant
Dim i As Integer
    For i = LBound(Datas) To UBound(Datas)
        MakeList = MakeList & MakeItem(Datas(i))
    Next i
End Function
Function MakeItem(Item As Variant) As Variant
    Counter = Counter + 1
    MakeItem = Counter & Sep & Item & vbCrLf
End Function
Task: Nested function
Python: def makeList(separator):
    counter = 1

    def makeItem(item):
        nonlocal counter
        result = str(counter) + separator + item + "\n"
        counter += 1
        return result

    return makeItem("first") + makeItem("second") + makeItem("third")

print(makeList(". "))

VB: Option Explicit

Private Const Sep As String = ". "
Private Counter As Integer
Sub Main()
Dim L As Variant
    Counter = 0
    L = MakeList(Array("first", "second", "third"))
    Debug.Print L
End Sub
Function MakeList(Datas) As Variant
Dim i As Integer
    For i = LBound(Datas) To UBound(Datas)
        MakeList = MakeList & MakeItem(Datas(i))
    Next i
End Function
Function MakeItem(Item As Variant) As Variant
    Counter = Counter + 1
    MakeItem = Counter & Sep & Item & vbCrLf
End Function
Task: Nested function
Java: module NestedFunction
    {
    static String makeList(String separator)
        {
        Int counter = 1;

        function String(String) makeItem = item -> $"{counter++}{separator}{item}\n";

        return makeItem("first")
             + makeItem("second")
             + makeItem("third");
        }

    void run()
        {
        @Inject Console console;
        console.print(makeList(". "));
        }
    }

VB: Option Explicit

Private Const Sep As String = ". "
Private Counter As Integer
Sub Main()
Dim L As Variant
    Counter = 0
    L = MakeList(Array("first", "second", "third"))
    Debug.Print L
End Sub
Function MakeList(Datas) As Variant
Dim i As Integer
    For i = LBound(Datas) To UBound(Datas)
        MakeList = MakeList & MakeItem(Datas(i))
    Next i
End Function
Function MakeItem(Item As Variant) As Variant
    Counter = Counter + 1
    MakeItem = Counter & Sep & Item & vbCrLf
End Function
Task: Nested function
C: #include<stdlib.h>
#include<stdio.h>

typedef struct{
	char str[30];
}item;

item* makeList(char* separator){
	int counter = 0,i;
	item* list = (item*)malloc(3*sizeof(item));
	
	item makeItem(){
		item holder;
		
		char names[5][10] = {"first","second","third","fourth","fifth"};
		
		sprintf(holder.str,"%d%s%s",++counter,separator,names[counter]);
		
		return holder;
	}
	
	for(i=0;i<3;i++)
		list[i] = makeItem();
	
	return list;
}

int main()
{
	int i;
	item* list = makeList(". ");
	
	for(i=0;i<3;i++)
		printf("\n%s",list[i].str);
	
	return 0;
}

PHP: <?
function makeList($separator) {
  $counter = 1;

  $makeItem = function ($item) use ($separator, &$counter) {
    return $counter++ . $separator . $item . "\n";
  };

  return $makeItem("first") . $makeItem("second") . $makeItem("third");
}

echo makeList(". ");
?>
Task: Nested function
C#: string MakeList(string separator)
{
    int counter = 1;

    Func<string, string> makeItem = item => counter++ + separator + item + "\n";

    return makeItem("first") + makeItem("second") + makeItem("third");
}

Console.WriteLine(MakeList(". "));

PHP: <?
function makeList($separator) {
  $counter = 1;

  $makeItem = function ($item) use ($separator, &$counter) {
    return $counter++ . $separator . $item . "\n";
  };

  return $makeItem("first") . $makeItem("second") . $makeItem("third");
}

echo makeList(". ");
?>
Task: Nested function
C++: #include <iostream>
#include <string>
#include <vector>
 
std::vector<std::string> makeList(std::string separator) {
  auto counter = 0;
  auto makeItem = [&](std::string item) {
    return std::to_string(++counter) + separator + item;
  };
  return {makeItem("first"), makeItem("second"), makeItem("third")};
}

int main() {
  for (auto item : makeList(". "))
    std::cout << item << "\n";
}

PHP: <?
function makeList($separator) {
  $counter = 1;

  $makeItem = function ($item) use ($separator, &$counter) {
    return $counter++ . $separator . $item . "\n";
  };

  return $makeItem("first") . $makeItem("second") . $makeItem("third");
}

echo makeList(". ");
?>
Task: Nested function
Go: package main
import "fmt"

func makeList(separator string) string {
    counter := 1

    makeItem := func(item string) string {
        result := fmt.Sprintf("%d%s%s\n", counter, separator, item)
        counter += 1
        return result
    }

    return makeItem("first") + makeItem("second") + makeItem("third")
}

func main() {
    fmt.Print(makeList(". "))
}

PHP: <?
function makeList($separator) {
  $counter = 1;

  $makeItem = function ($item) use ($separator, &$counter) {
    return $counter++ . $separator . $item . "\n";
  };

  return $makeItem("first") . $makeItem("second") . $makeItem("third");
}

echo makeList(". ");
?>
Task: Nested function
Java: module NestedFunction
    {
    static String makeList(String separator)
        {
        Int counter = 1;

        function String(String) makeItem = item -> $"{counter++}{separator}{item}\n";

        return makeItem("first")
             + makeItem("second")
             + makeItem("third");
        }

    void run()
        {
        @Inject Console console;
        console.print(makeList(". "));
        }
    }

PHP: <?
function makeList($separator) {
  $counter = 1;

  $makeItem = function ($item) use ($separator, &$counter) {
    return $counter++ . $separator . $item . "\n";
  };

  return $makeItem("first") . $makeItem("second") . $makeItem("third");
}

echo makeList(". ");
?>
Task: Nested function
Python: def makeList(separator):
    counter = 1

    def makeItem(item):
        nonlocal counter
        result = str(counter) + separator + item + "\n"
        counter += 1
        return result

    return makeItem("first") + makeItem("second") + makeItem("third")

print(makeList(". "))

PHP: <?
function makeList($separator) {
  $counter = 1;

  $makeItem = function ($item) use ($separator, &$counter) {
    return $counter++ . $separator . $item . "\n";
  };

  return $makeItem("first") . $makeItem("second") . $makeItem("third");
}

echo makeList(". ");
?>
Task: Nested function
VB: Option Explicit

Private Const Sep As String = ". "
Private Counter As Integer
Sub Main()
Dim L As Variant
    Counter = 0
    L = MakeList(Array("first", "second", "third"))
    Debug.Print L
End Sub
Function MakeList(Datas) As Variant
Dim i As Integer
    For i = LBound(Datas) To UBound(Datas)
        MakeList = MakeList & MakeItem(Datas(i))
    Next i
End Function
Function MakeItem(Item As Variant) As Variant
    Counter = Counter + 1
    MakeItem = Counter & Sep & Item & vbCrLf
End Function

PHP: <?
function makeList($separator) {
  $counter = 1;

  $makeItem = function ($item) use ($separator, &$counter) {
    return $counter++ . $separator . $item . "\n";
  };

  return $makeItem("first") . $makeItem("second") . $makeItem("third");
}

echo makeList(". ");
?>
Task: Matrix chain multiplication
C#: using System;

class MatrixChainOrderOptimizer {
    private int[,] m;
    private int[,] s;

    void OptimalMatrixChainOrder(int[] dims) {
        int n = dims.Length - 1;
        m = new int[n, n];
        s = new int[n, n];
        for (int len = 1; len < n; ++len) {
            for (int i = 0; i < n - len; ++i) {
                int j = i + len;
                m[i, j] = Int32.MaxValue;
                for (int k = i; k < j; ++k) {
                    int temp = dims[i] * dims[k + 1] * dims[j + 1];
                    int cost = m[i, k] + m[k + 1, j] + temp;
                    if (cost < m[i, j]) {
                        m[i, j] = cost;
                        s[i, j] = k;
                    }
                }
            }
        }
    }

    void PrintOptimalChainOrder(int i, int j) {
        if (i == j)
            Console.Write((char)(i + 65));
        else {
            Console.Write("(");
            PrintOptimalChainOrder(i, s[i, j]);
            PrintOptimalChainOrder(s[i, j] + 1, j);
            Console.Write(")");
        }
    }

    static void Main() {
        var mcoo = new MatrixChainOrderOptimizer();
        var dimsList = new int[3][];
        dimsList[0] = new int[4] {5, 6, 3, 1};
        dimsList[1] = new int[13] {1, 5, 25, 30, 100, 70, 2, 1, 100, 250, 1, 1000, 2};
        dimsList[2] = new int[12] {1000, 1, 500, 12, 1, 700, 2500, 3, 2, 5, 14, 10};
        for (int i = 0; i < dimsList.Length; ++i) {
            Console.Write("Dims  : [");
            int n = dimsList[i].Length;
            for (int j = 0; j < n; ++j) {
                Console.Write(dimsList[i][j]);
                if (j < n - 1)
                    Console.Write(", ");
                else
                    Console.WriteLine("]");
            }
            mcoo.OptimalMatrixChainOrder(dimsList[i]);
            Console.Write("Order : ");
            mcoo.PrintOptimalChainOrder(0, n - 2);
            Console.WriteLine("\nCost  : {0}\n",  mcoo.m[0, n - 2]);
        }
    }
}

Python: def parens(n):
    def aux(n, k):
        if n == 1:
            yield k
        elif n == 2:
            yield [k, k + 1]
        else:
            a = []
            for i in range(1, n):
                for u in aux(i, k):
                    for v in aux(n - i, k + i):
                        yield [u, v]
    yield from aux(n, 0)