kazuyamaa/multi-language-messages-01 huggingface dataset:
Task: Null object
Go: package main

import "fmt"

var (
    s []int       
    p *int        
    f func()      
    i interface{} 
    m map[int]int 
    c chan int    
)

func main() {
    fmt.Println(s == nil)
    fmt.Println(p == nil)
    fmt.Println(f == nil)
    fmt.Println(i == nil)
    fmt.Println(m == nil)
    fmt.Println(c == nil)
}

Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }
Task: Null object
Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }

Python: x = None
if x is None:
  print "x is None"
else:
  print "x is not None"
Task: Null object
Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }

VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub
Task: Null object
Go: package main

import "fmt"

var (
    s []int       
    p *int        
    f func()      
    i interface{} 
    m map[int]int 
    c chan int    
)

func main() {
    fmt.Println(s == nil)
    fmt.Println(p == nil)
    fmt.Println(f == nil)
    fmt.Println(i == nil)
    fmt.Println(m == nil)
    fmt.Println(c == nil)
}

Python: x = None
if x is None:
  print "x is None"
else:
  print "x is not None"
Task: Null object
Go: package main

import "fmt"

var (
    s []int       
    p *int        
    f func()      
    i interface{} 
    m map[int]int 
    c chan int    
)

func main() {
    fmt.Println(s == nil)
    fmt.Println(p == nil)
    fmt.Println(f == nil)
    fmt.Println(i == nil)
    fmt.Println(m == nil)
    fmt.Println(c == nil)
}

VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub
Task: Null object
Python: x = None
if x is None:
  print "x is None"
else:
  print "x is not None"

VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub
Task: Null object
C: #include <stdio.h>

int main()
{
	char *object = 0;

	if (object == NULL) {
		puts("object is null");
	}
	return 0;
}

C#: if (foo == null)
    Console.WriteLine("foo is null");
Task: Null object
C#: if (foo == null)
    Console.WriteLine("foo is null");

Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }
Task: Null object
C++: #include <iostream>
#include <cstdlib>
if (object == 0) {
   std::cout << "object is null";
}

VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub
Task: Null object
C: #include <stdio.h>

int main()
{
	char *object = 0;

	if (object == NULL) {
		puts("object is null");
	}
	return 0;
}

PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Null object
C#: if (foo == null)
    Console.WriteLine("foo is null");

PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Null object
C++: #include <iostream>
#include <cstdlib>
if (object == 0) {
   std::cout << "object is null";
}

PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Null object
Go: package main

import "fmt"

var (
    s []int       
    p *int        
    f func()      
    i interface{} 
    m map[int]int 
    c chan int    
)

func main() {
    fmt.Println(s == nil)
    fmt.Println(p == nil)
    fmt.Println(f == nil)
    fmt.Println(i == nil)
    fmt.Println(m == nil)
    fmt.Println(c == nil)
}

PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Null object
Java: module NullObject
    {
    void run()
        {
        @Inject Console console;
        console.print($"Null value={Null}, Null.toString()={Null.toString()}");

     
        String? s = Null;       
        String s2 = "test";
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");

     
        Int len = s?.size : 0;
        console.print($"len={len}");

        if (String test ?= s)
            {
            
            }
        else
            {
            s = "a non-null value";
            }

     
        s2 = s;                 
        console.print($"s={s}, s2={s2}, (s==s2)={s==s2}");
        }
    }

PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Null object
Python: x = None
if x is None:
  print "x is None"
else:
  print "x is not None"

PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Null object
VB: Public Sub Main()
    Dim c As VBA.Collection
     
    
    Debug.Print c Is Nothing
     
    
    Set c = New VBA.Collection
    Debug.Print Not c Is Nothing
     
    
    Set c = Nothing
    Debug.Print c Is Nothing
End Sub

PHP: $x = NULL;
if (is_null($x))
  echo "\$x is null\n";
Task: Abelian sandpile model
C++: #include <iostream>
#include "xtensor/xarray.hpp"
#include "xtensor/xio.hpp"
#include "xtensor-io/ximage.hpp"

xt::xarray<int> init_grid (unsigned long x_dim, unsigned long y_dim)
{
    xt::xarray<int>::shape_type shape = { x_dim, y_dim };
    xt::xarray<int> grid(shape);

    grid(x_dim/2, y_dim/2) = 64000;
    
    return grid;
}

int print_grid(xt::xarray<int>& grid)
{
    
    
    

    
    xt::dump_image("grid.jpg", grid);

    return 0;
}

bool iterate_grid(xt::xarray<int>& grid, const unsigned long& x_dim, const unsigned long& y_dim)
{
    bool changed = false;

    for (unsigned long i=0; i < x_dim; ++i)
    {
        for (unsigned long j=0; j < y_dim; ++j)
        {
            if ( grid(i, j) >= 4 )
            {
                grid(i, j) -= 4;
                changed = true;
                try
                {
                    grid.at(i-1, j) += 1;
                    grid.at(i+1, j) += 1;
                    grid.at(i, j-1) += 1;
                    grid.at(i, j+1) += 1;
                }
                catch (const std::out_of_range& oor)
                {
                }
            }
        }
    }

    return changed;
}

int main(int argc, char* argv[])
{
    const unsigned long x_dim { 200 };
    const unsigned long y_dim { 200 };

    xt::xarray<int> grid = init_grid(x_dim, y_dim);
    bool changed { true };

    iterate_grid(grid, x_dim, y_dim);

    while (changed == true)
    {
        changed = iterate_grid(grid, x_dim, y_dim);
    }
    print_grid(grid);

    return 0;
}

Python: import numpy as np
import matplotlib.pyplot as plt


def iterate(grid):
    changed = False
    for ii, arr in enumerate(grid):
        for jj, val in enumerate(arr):
            if val > 3:
                grid[ii, jj] -= 4
                if ii > 0:
                    grid[ii - 1, jj] += 1
                if ii < len(grid)-1:
                    grid[ii + 1, jj] += 1
                if jj > 0:
                    grid[ii, jj - 1] += 1
                if jj < len(grid)-1:
                    grid[ii, jj + 1] += 1
                changed = True
    return grid, changed


def simulate(grid):
    while True:
        grid, changed = iterate(grid)
        if not changed:
            return grid


if __name__ == '__main__':
    start_grid = np.zeros((10, 10))
    start_grid[4:5, 4:5] = 64
    final_grid = simulate(start_grid.copy())
    plt.figure()
    plt.gray()
    plt.imshow(start_grid)
    plt.figure()
    plt.gray()
    plt.imshow(final_grid)
Task: Abelian sandpile model
Go: package main

import (
    "fmt"
    "log"
    "os"
    "strings"
)

const dim = 16 

func check(err error) {
    if err != nil {
        log.Fatal(err)
    }
}


func drawPile(pile [][]uint) {
    chars:= []rune(" ░▓█")
    for _, row := range pile {
        line := make([]rune, len(row))
        for i, elem := range row {
            if elem > 3 { 
                elem = 3
            }
            line[i] = chars[elem]
        }
        fmt.Println(string(line))
    }
}



func writePile(pile [][]uint) {
    file, err := os.Create("output.ppm")
    check(err)
    defer file.Close()
    
    fmt.Fprintf(file, "P3\n%d %d\n255\n", dim, dim)
    bcolors := []string{"125 0 25 ", "125 80 0 ", "186 118 0 ", "224 142 0 "}
    var line strings.Builder
    for _, row := range pile {        
        for _, elem := range row {
            line.WriteString(bcolors[elem])
        }
        file.WriteString(line.String() + "\n")
        line.Reset() 
    }
}


func handlePile(x, y uint, pile [][]uint) {
    if pile[y][x] >= 4 {
        pile[y][x] -= 4
        
        
        if y > 0 {
            pile[y-1][x]++
            if pile[y-1][x] >= 4 {
                handlePile(x, y-1, pile)
            }
        }
        if x > 0 {
            pile[y][x-1]++
            if pile[y][x-1] >= 4 {
                handlePile(x-1, y, pile)
            }
        }
        if y < dim-1 {
            pile[y+1][x]++
            if pile[y+1][x] >= 4 {
                handlePile(x, y+1, pile)
            }
        }
        if x < dim-1 {
            pile[y][x+1]++
            if pile[y][x+1] >= 4 {
                handlePile(x+1, y, pile)
            }
        }

        
        
        

        
        
        handlePile(x, y, pile)
    }
}

func main() {
    
    pile := make([][]uint, dim)
    for i := 0; i < dim; i++ {
        pile[i] = make([]uint, dim)
    }

    
    hdim := uint(dim/2 - 1)
    pile[hdim][hdim] = 16
    handlePile(hdim, hdim, pile)
    drawPile(pile)

    
    
    
}

Python: import numpy as np
import matplotlib.pyplot as plt


def iterate(grid):
    changed = False
    for ii, arr in enumerate(grid):
        for jj, val in enumerate(arr):
            if val > 3:
                grid[ii, jj] -= 4
                if ii > 0:
                    grid[ii - 1, jj] += 1
                if ii < len(grid)-1:
                    grid[ii + 1, jj] += 1
                if jj > 0:
                    grid[ii, jj - 1] += 1
                if jj < len(grid)-1:
                    grid[ii, jj + 1] += 1
                changed = True
    return grid, changed


def simulate(grid):
    while True:
        grid, changed = iterate(grid)
        if not changed:
            return grid


if __name__ == '__main__':
    start_grid = np.zeros((10, 10))
    start_grid[4:5, 4:5] = 64
    final_grid = simulate(start_grid.copy())
    plt.figure()
    plt.gray()
    plt.imshow(start_grid)
    plt.figure()
    plt.gray()
    plt.imshow(final_grid)
Task: Doubly-linked list_Element definition
C: struct Node 
{
  struct Node *next;
  struct Node *prev;
  void  *data;
};

C++: template <typename T>
struct Node
{
    Node* next;
    Node* prev;
    T data;
};
Task: Doubly-linked list_Element definition
C: struct Node 
{
  struct Node *next;
  struct Node *prev;
  void  *data;
};

Go: type dlNode struct {
    string
    next, prev *dlNode
}
Task: Doubly-linked list_Element definition
C: struct Node 
{
  struct Node *next;
  struct Node *prev;
  void  *data;
};

Java: public class Node<T> {
   private T element;
   private Node<T> next, prev;

   public Node<T>(){
      next = prev = element = null;
   }

   public Node<T>(Node<T> n, Node<T> p, T elem){
      next = n;
      prev = p;
      element = elem;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> getNext(){
      return next;
   }

   public void setElem(T elem){
      element = elem;
   }

   public T getElem(){
      return element;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> setPrev(Node<T> p){
      prev = p;
   }

   public getPrev(){
      return prev;
   }
}
Task: Doubly-linked list_Element definition
C: struct Node 
{
  struct Node *next;
  struct Node *prev;
  void  *data;
};

Python: class Node(object):
     def __init__(self, data = None, prev = None, next = None):
         self.prev = prev
         self.next = next
         self.data = data
     def __str__(self):
         return str(self.data)
     def __repr__(self):
         return repr(self.data)
     def iter_forward(self):
         c = self
         while c != None:
             yield c
             c = c.next
     def iter_backward(self):
         c = self
         while c != None:
             yield c
             c = c.prev
Task: Doubly-linked list_Element definition
C: struct Node 
{
  struct Node *next;
  struct Node *prev;
  void  *data;
};

VB: Public Class Node(Of T)
   Public Value As T
   Public [Next] As Node(Of T)
   Public Previous As Node(Of T)
End Class
Task: Doubly-linked list_Element definition
C#: class Link
{
    public int Item { get; set; }
    public Link Prev { get; set; }
    public Link Next { get; set; }

    
    public Link(int item, Link prev = null, Link next = null) {
        Item = item;
        Prev = prev;
        Next = next;
    }
}

C++: template <typename T>
struct Node
{
    Node* next;
    Node* prev;
    T data;
};
Task: Doubly-linked list_Element definition
C++: template <typename T>
struct Node
{
    Node* next;
    Node* prev;
    T data;
};

Go: type dlNode struct {
    string
    next, prev *dlNode
}
Task: Doubly-linked list_Element definition
C++: template <typename T>
struct Node
{
    Node* next;
    Node* prev;
    T data;
};

Java: public class Node<T> {
   private T element;
   private Node<T> next, prev;

   public Node<T>(){
      next = prev = element = null;
   }

   public Node<T>(Node<T> n, Node<T> p, T elem){
      next = n;
      prev = p;
      element = elem;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> getNext(){
      return next;
   }

   public void setElem(T elem){
      element = elem;
   }

   public T getElem(){
      return element;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> setPrev(Node<T> p){
      prev = p;
   }

   public getPrev(){
      return prev;
   }
}
Task: Doubly-linked list_Element definition
C++: template <typename T>
struct Node
{
    Node* next;
    Node* prev;
    T data;
};

VB: Public Class Node(Of T)
   Public Value As T
   Public [Next] As Node(Of T)
   Public Previous As Node(Of T)
End Class
Task: Doubly-linked list_Element definition
C#: class Link
{
    public int Item { get; set; }
    public Link Prev { get; set; }
    public Link Next { get; set; }

    
    public Link(int item, Link prev = null, Link next = null) {
        Item = item;
        Prev = prev;
        Next = next;
    }
}

Java: public class Node<T> {
   private T element;
   private Node<T> next, prev;

   public Node<T>(){
      next = prev = element = null;
   }

   public Node<T>(Node<T> n, Node<T> p, T elem){
      next = n;
      prev = p;
      element = elem;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> getNext(){
      return next;
   }

   public void setElem(T elem){
      element = elem;
   }

   public T getElem(){
      return element;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> setPrev(Node<T> p){
      prev = p;
   }

   public getPrev(){
      return prev;
   }
}
Task: Doubly-linked list_Element definition
C#: class Link
{
    public int Item { get; set; }
    public Link Prev { get; set; }
    public Link Next { get; set; }

    
    public Link(int item, Link prev = null, Link next = null) {
        Item = item;
        Prev = prev;
        Next = next;
    }
}

Python: class Node(object):
     def __init__(self, data = None, prev = None, next = None):
         self.prev = prev
         self.next = next
         self.data = data
     def __str__(self):
         return str(self.data)
     def __repr__(self):
         return repr(self.data)
     def iter_forward(self):
         c = self
         while c != None:
             yield c
             c = c.next
     def iter_backward(self):
         c = self
         while c != None:
             yield c
             c = c.prev
Task: Doubly-linked list_Element definition
C#: class Link
{
    public int Item { get; set; }
    public Link Prev { get; set; }
    public Link Next { get; set; }

    
    public Link(int item, Link prev = null, Link next = null) {
        Item = item;
        Prev = prev;
        Next = next;
    }
}

VB: Public Class Node(Of T)
   Public Value As T
   Public [Next] As Node(Of T)
   Public Previous As Node(Of T)
End Class
Task: Doubly-linked list_Element definition
Go: type dlNode struct {
    string
    next, prev *dlNode
}

Java: public class Node<T> {
   private T element;
   private Node<T> next, prev;

   public Node<T>(){
      next = prev = element = null;
   }

   public Node<T>(Node<T> n, Node<T> p, T elem){
      next = n;
      prev = p;
      element = elem;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> getNext(){
      return next;
   }

   public void setElem(T elem){
      element = elem;
   }

   public T getElem(){
      return element;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> setPrev(Node<T> p){
      prev = p;
   }

   public getPrev(){
      return prev;
   }
}
Task: Doubly-linked list_Element definition
Java: public class Node<T> {
   private T element;
   private Node<T> next, prev;

   public Node<T>(){
      next = prev = element = null;
   }

   public Node<T>(Node<T> n, Node<T> p, T elem){
      next = n;
      prev = p;
      element = elem;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> getNext(){
      return next;
   }

   public void setElem(T elem){
      element = elem;
   }

   public T getElem(){
      return element;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> setPrev(Node<T> p){
      prev = p;
   }

   public getPrev(){
      return prev;
   }
}

Python: class Node(object):
     def __init__(self, data = None, prev = None, next = None):
         self.prev = prev
         self.next = next
         self.data = data
     def __str__(self):
         return str(self.data)
     def __repr__(self):
         return repr(self.data)
     def iter_forward(self):
         c = self
         while c != None:
             yield c
             c = c.next
     def iter_backward(self):
         c = self
         while c != None:
             yield c
             c = c.prev
Task: Doubly-linked list_Element definition
Java: public class Node<T> {
   private T element;
   private Node<T> next, prev;

   public Node<T>(){
      next = prev = element = null;
   }

   public Node<T>(Node<T> n, Node<T> p, T elem){
      next = n;
      prev = p;
      element = elem;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> getNext(){
      return next;
   }

   public void setElem(T elem){
      element = elem;
   }

   public T getElem(){
      return element;
   }

   public void setNext(Node<T> n){
      next = n;
   }

   public Node<T> setPrev(Node<T> p){
      prev = p;
   }

   public getPrev(){
      return prev;
   }
}

VB: Public Class Node(Of T)
   Public Value As T
   Public [Next] As Node(Of T)
   Public Previous As Node(Of T)
End Class
Task: Doubly-linked list_Element definition
Go: type dlNode struct {
    string
    next, prev *dlNode
}

Python: class Node(object):
     def __init__(self, data = None, prev = None, next = None):
         self.prev = prev
         self.next = next
         self.data = data
     def __str__(self):
         return str(self.data)
     def __repr__(self):
         return repr(self.data)
     def iter_forward(self):
         c = self
         while c != None:
             yield c
             c = c.next
     def iter_backward(self):
         c = self
         while c != None:
             yield c
             c = c.prev
Task: Doubly-linked list_Element definition
Go: type dlNode struct {
    string
    next, prev *dlNode
}

VB: Public Class Node(Of T)
   Public Value As T
   Public [Next] As Node(Of T)
   Public Previous As Node(Of T)
End Class
Task: Doubly-linked list_Element definition
C: struct Node 
{
  struct Node *next;
  struct Node *prev;
  void  *data;
};

C#: class Link
{
    public int Item { get; set; }
    public Link Prev { get; set; }
    public Link Next { get; set; }

    
    public Link(int item, Link prev = null, Link next = null) {
        Item = item;
        Prev = prev;
        Next = next;
    }
}
Task: Doubly-linked list_Element definition
C++: template <typename T>
struct Node
{
    Node* next;
    Node* prev;
    T data;
};

Python: class Node(object):
     def __init__(self, data = None, prev = None, next = None):
         self.prev = prev
         self.next = next
         self.data = data
     def __str__(self):
         return str(self.data)
     def __repr__(self):
         return repr(self.data)
     def iter_forward(self):
         c = self
         while c != None:
             yield c
             c = c.next
     def iter_backward(self):
         c = self
         while c != None:
             yield c
             c = c.prev
Task: Doubly-linked list_Element definition
C#: class Link
{
    public int Item { get; set; }
    public Link Prev { get; set; }
    public Link Next { get; set; }

    
    public Link(int item, Link prev = null, Link next = null) {
        Item = item;
        Prev = prev;
        Next = next;
    }
}

Go: type dlNode struct {
    string
    next, prev *dlNode
}
Task: Doubly-linked list_Element definition
Python: class Node(object):
     def __init__(self, data = None, prev = None, next = None):
         self.prev = prev
         self.next = next
         self.data = data
     def __str__(self):
         return str(self.data)
     def __repr__(self):
         return repr(self.data)
     def iter_forward(self):
         c = self
         while c != None:
             yield c
             c = c.next
     def iter_backward(self):
         c = self
         while c != None:
             yield c
             c = c.prev

VB: Public Class Node(Of T)
   Public Value As T
   Public [Next] As Node(Of T)
   Public Previous As Node(Of T)
End Class