WeixiangYan/CodeTransOcean huggingface dataset:
Task: Apply a digital filter (direct form II transposed)




Go: package main

import "fmt"

type filter struct {
    b, a []float64
}

func (f filter) filter(in []float64) []float64 {
    out := make([]float64, len(in))
    s := 1. / f.a[0]
    for i := range in {
        tmp := 0.
        b := f.b
        if i+1 < len(b) {
            b = b[:i+1]
        }
        for j, bj := range b {
            tmp += bj * in[i-j]
        }
        a := f.a[1:]
        if i < len(a) {
            a = a[:i]
        }
        for j, aj := range a {
            tmp -= aj * out[i-j-1]
        }
        out[i] = tmp * s
    }
    return out
}


var bwf = filter{
    a: []float64{1.00000000, -2.77555756e-16, 3.33333333e-01, -1.85037171e-17},
    b: []float64{0.16666667, 0.5, 0.5, 0.16666667},
}

var sig = []float64{
    -0.917843918645, 0.141984778794, 1.20536903482, 0.190286794412,
    -0.662370894973, -1.00700480494, -0.404707073677, 0.800482325044,
    0.743500089861, 1.01090520172, 0.741527555207, 0.277841675195,
    0.400833448236, -0.2085993586, -0.172842103641, -0.134316096293,
    0.0259303398477, 0.490105989562, 0.549391221511, 0.9047198589,
}

func main() {
    for _, v := range bwf.filter(sig) {
        fmt.Printf("%9.6f\n", v)
    }
}
Task: Honeycombs


C++: 


#ifndef HONEYCOMBWIDGET_H
#define HONEYCOMBWIDGET_H

#include <QWidget>
#include <vector>

class HoneycombWidget : public QWidget {
    Q_OBJECT
public:
    HoneycombWidget(QWidget *parent = nullptr);
protected:
    void paintEvent(QPaintEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
private:
    struct Cell {
        Cell(const QPolygon& p, int l, char ch)
            : polygon(p), letter(l), character(ch), selected(false) {}
        QPolygon polygon;
        int letter;
        char character;
        bool selected;
    };
    std::vector<Cell> cells;
};

#endif
Task: String prepend



C#: using System;

namespace PrependString
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "World";
            str = "Hello " + str;
            Console.WriteLine(str);
            Console.ReadKey();
        }
    }
}









Ada: with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Prepend_String is   
   S: Unbounded_String := To_Unbounded_String("World!"); 
begin
   S := "Hello " & S;
   Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;
Task: String prepend

C: #include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    char str[100]="my String";
    char *cstr="Changed ";
    char *dup;
    sprintf(str,"%s%s",cstr,(dup=strdup(str)));
    free(dup);
    printf("%s\n",str);
    return 0;
}











Ada: with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Prepend_String is   
   S: Unbounded_String := To_Unbounded_String("World!"); 
begin
   S := "Hello " & S;
   Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;
Task: String prepend


C++: include <vector>
#include <algorithm>
#include <string>
#include <iostream>

int main( ) {
   std::vector<std::string> myStrings { "prepended to" , "my string" } ;
   std::string prepended = std::accumulate( myStrings.begin( ) , 
	 myStrings.end( ) , std::string( "" ) , []( std::string a , 
	    std::string b ) { return a + b ; } ) ;
   std::cout << prepended << std::endl ;
   return 0 ;
}










Ada: with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Prepend_String is   
   S: Unbounded_String := To_Unbounded_String("World!"); 
begin
   S := "Hello " & S;
   Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;
Task: String prepend




Go: s := "world!"
s = "Hello, " + s








Ada: with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Prepend_String is   
   S: Unbounded_String := To_Unbounded_String("World!"); 
begin
   S := "Hello " & S;
   Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;
Task: String prepend





Java: 
public class Prepend {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("world");
        sb.insert(0, "Hello, ");
        System.out.println(sb);
    }
}







Ada: with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Prepend_String is   
   S: Unbounded_String := To_Unbounded_String("World!"); 
begin
   S := "Hello " & S;
   Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;
Task: String prepend







Python: 


s = "12345678"
s = "0" + s  
print(s)





Ada: with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Prepend_String is   
   S: Unbounded_String := To_Unbounded_String("World!"); 
begin
   S := "Hello " & S;
   Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;
Task: String prepend








VB: Function StringPrepend()
Dim s As String
s = "bar"
s = "foo" & s
Debug.Print s
End Function




Ada: with Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;

procedure Prepend_String is   
   S: Unbounded_String := To_Unbounded_String("World!"); 
begin
   S := "Hello " & S;
   Ada.Text_IO.Put_Line(To_String(S));
end Prepend_String;
Task: String prepend

C: #include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    char str[100]="my String";
    char *cstr="Changed ";
    char *dup;
    sprintf(str,"%s%s",cstr,(dup=strdup(str)));
    free(dup);
    printf("%s\n",str);
    return 0;
}
Task: String prepend



C#: using System;

namespace PrependString
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "World";
            str = "Hello " + str;
            Console.WriteLine(str);
            Console.ReadKey();
        }
    }
}
Task: String prepend


C++: include <vector>
#include <algorithm>
#include <string>
#include <iostream>

int main( ) {
   std::vector<std::string> myStrings { "prepended to" , "my string" } ;
   std::string prepended = std::accumulate( myStrings.begin( ) , 
	 myStrings.end( ) , std::string( "" ) , []( std::string a , 
	    std::string b ) { return a + b ; } ) ;
   std::cout << prepended << std::endl ;
   return 0 ;
}
Task: String prepend





Java: 
public class Prepend {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("world");
        sb.insert(0, "Hello, ");
        System.out.println(sb);
    }
}
Task: String prepend







Python: 


s = "12345678"
s = "0" + s  
print(s)
Task: String prepend








VB: Function StringPrepend()
Dim s As String
s = "bar"
s = "foo" & s
Debug.Print s
End Function
Task: String prepend




Go: s := "world!"
s = "Hello, " + s
Task: String prepend



C#: using System;

namespace PrependString
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "World";
            str = "Hello " + str;
            Console.WriteLine(str);
            Console.ReadKey();
        }
    }
}








Fortran:       INTEGER*4 I,TEXT(66)
      DATA TEXT(1),TEXT(2),TEXT(3)/"Wo","rl","d

      WRITE (6,1) (TEXT(I), I = 1,3)
    1 FORMAT ("Hello ",66A2)

      DO 2 I = 1,3
    2   TEXT(I + 3) = TEXT(I)
      TEXT(1) = "He"
      TEXT(2) = "ll"
      TEXT(3) = "o "

      WRITE (6,3) (TEXT(I), I = 1,6)
    3 FORMAT (66A2)
      END
Task: String prepend


C++: include <vector>
#include <algorithm>
#include <string>
#include <iostream>

int main( ) {
   std::vector<std::string> myStrings { "prepended to" , "my string" } ;
   std::string prepended = std::accumulate( myStrings.begin( ) , 
	 myStrings.end( ) , std::string( "" ) , []( std::string a , 
	    std::string b ) { return a + b ; } ) ;
   std::cout << prepended << std::endl ;
   return 0 ;
}









Fortran:       INTEGER*4 I,TEXT(66)
      DATA TEXT(1),TEXT(2),TEXT(3)/"Wo","rl","d

      WRITE (6,1) (TEXT(I), I = 1,3)
    1 FORMAT ("Hello ",66A2)

      DO 2 I = 1,3
    2   TEXT(I + 3) = TEXT(I)
      TEXT(1) = "He"
      TEXT(2) = "ll"
      TEXT(3) = "o "

      WRITE (6,3) (TEXT(I), I = 1,6)
    3 FORMAT (66A2)
      END
Task: String prepend

C: #include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    char str[100]="my String";
    char *cstr="Changed ";
    char *dup;
    sprintf(str,"%s%s",cstr,(dup=strdup(str)));
    free(dup);
    printf("%s\n",str);
    return 0;
}










Fortran:       INTEGER*4 I,TEXT(66)
      DATA TEXT(1),TEXT(2),TEXT(3)/"Wo","rl","d

      WRITE (6,1) (TEXT(I), I = 1,3)
    1 FORMAT ("Hello ",66A2)

      DO 2 I = 1,3
    2   TEXT(I + 3) = TEXT(I)
      TEXT(1) = "He"
      TEXT(2) = "ll"
      TEXT(3) = "o "

      WRITE (6,3) (TEXT(I), I = 1,6)
    3 FORMAT (66A2)
      END
Task: String prepend





Java: 
public class Prepend {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("world");
        sb.insert(0, "Hello, ");
        System.out.println(sb);
    }
}






Fortran:       INTEGER*4 I,TEXT(66)
      DATA TEXT(1),TEXT(2),TEXT(3)/"Wo","rl","d

      WRITE (6,1) (TEXT(I), I = 1,3)
    1 FORMAT ("Hello ",66A2)

      DO 2 I = 1,3
    2   TEXT(I + 3) = TEXT(I)
      TEXT(1) = "He"
      TEXT(2) = "ll"
      TEXT(3) = "o "

      WRITE (6,3) (TEXT(I), I = 1,6)
    3 FORMAT (66A2)
      END
Task: String prepend







Python: 


s = "12345678"
s = "0" + s  
print(s)




Fortran:       INTEGER*4 I,TEXT(66)
      DATA TEXT(1),TEXT(2),TEXT(3)/"Wo","rl","d

      WRITE (6,1) (TEXT(I), I = 1,3)
    1 FORMAT ("Hello ",66A2)

      DO 2 I = 1,3
    2   TEXT(I + 3) = TEXT(I)
      TEXT(1) = "He"
      TEXT(2) = "ll"
      TEXT(3) = "o "

      WRITE (6,3) (TEXT(I), I = 1,6)
    3 FORMAT (66A2)
      END
Task: String prepend








VB: Function StringPrepend()
Dim s As String
s = "bar"
s = "foo" & s
Debug.Print s
End Function



Fortran:       INTEGER*4 I,TEXT(66)
      DATA TEXT(1),TEXT(2),TEXT(3)/"Wo","rl","d

      WRITE (6,1) (TEXT(I), I = 1,3)
    1 FORMAT ("Hello ",66A2)

      DO 2 I = 1,3
    2   TEXT(I + 3) = TEXT(I)
      TEXT(1) = "He"
      TEXT(2) = "ll"
      TEXT(3) = "o "

      WRITE (6,3) (TEXT(I), I = 1,6)
    3 FORMAT (66A2)
      END
Task: String prepend

C: #include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    char str[100]="my String";
    char *cstr="Changed ";
    char *dup;
    sprintf(str,"%s%s",cstr,(dup=strdup(str)));
    free(dup);
    printf("%s\n",str);
    return 0;
}









COBOL:        identification division.
       program-id. prepend.
       data division.
       working-storage section.
       1 str pic x(30) value "World!".
       1 binary.
        2 len pic 9(4) value 0.
        2 scratch pic 9(4) value 0.
       procedure division.
       begin.
           perform rev-sub-str
           move function reverse ("Hello ") to str (len + 1:)
           perform rev-sub-str
           display str
           stop run
           .

       rev-sub-str.
           move 0 to len scratch
           inspect function reverse (str)
           tallying scratch for leading spaces
               len for characters after space
           move function reverse (str (1:len)) to str
           .
       end program prepend.
Task: String prepend



C#: using System;

namespace PrependString
{
    class Program
    {
        static void Main(string[] args)
        {
            string str = "World";
            str = "Hello " + str;
            Console.WriteLine(str);
            Console.ReadKey();
        }
    }
}







COBOL:        identification division.
       program-id. prepend.
       data division.
       working-storage section.
       1 str pic x(30) value "World!".
       1 binary.
        2 len pic 9(4) value 0.
        2 scratch pic 9(4) value 0.
       procedure division.
       begin.
           perform rev-sub-str
           move function reverse ("Hello ") to str (len + 1:)
           perform rev-sub-str
           display str
           stop run
           .

       rev-sub-str.
           move 0 to len scratch
           inspect function reverse (str)
           tallying scratch for leading spaces
               len for characters after space
           move function reverse (str (1:len)) to str
           .
       end program prepend.
Task: String prepend


C++: include <vector>
#include <algorithm>
#include <string>
#include <iostream>

int main( ) {
   std::vector<std::string> myStrings { "prepended to" , "my string" } ;
   std::string prepended = std::accumulate( myStrings.begin( ) , 
	 myStrings.end( ) , std::string( "" ) , []( std::string a , 
	    std::string b ) { return a + b ; } ) ;
   std::cout << prepended << std::endl ;
   return 0 ;
}








COBOL:        identification division.
       program-id. prepend.
       data division.
       working-storage section.
       1 str pic x(30) value "World!".
       1 binary.
        2 len pic 9(4) value 0.
        2 scratch pic 9(4) value 0.
       procedure division.
       begin.
           perform rev-sub-str
           move function reverse ("Hello ") to str (len + 1:)
           perform rev-sub-str
           display str
           stop run
           .

       rev-sub-str.
           move 0 to len scratch
           inspect function reverse (str)
           tallying scratch for leading spaces
               len for characters after space
           move function reverse (str (1:len)) to str
           .
       end program prepend.
Task: String prepend





Java: 
public class Prepend {
    public static void main(String[] args) {
        StringBuilder sb = new StringBuilder("world");
        sb.insert(0, "Hello, ");
        System.out.println(sb);
    }
}





COBOL:        identification division.
       program-id. prepend.
       data division.
       working-storage section.
       1 str pic x(30) value "World!".
       1 binary.
        2 len pic 9(4) value 0.
        2 scratch pic 9(4) value 0.
       procedure division.
       begin.
           perform rev-sub-str
           move function reverse ("Hello ") to str (len + 1:)
           perform rev-sub-str
           display str
           stop run
           .

       rev-sub-str.
           move 0 to len scratch
           inspect function reverse (str)
           tallying scratch for leading spaces
               len for characters after space
           move function reverse (str (1:len)) to str
           .
       end program prepend.
Task: String prepend







Python: 


s = "12345678"
s = "0" + s  
print(s)



COBOL:        identification division.
       program-id. prepend.
       data division.
       working-storage section.
       1 str pic x(30) value "World!".
       1 binary.
        2 len pic 9(4) value 0.
        2 scratch pic 9(4) value 0.
       procedure division.
       begin.
           perform rev-sub-str
           move function reverse ("Hello ") to str (len + 1:)
           perform rev-sub-str
           display str
           stop run
           .

       rev-sub-str.
           move 0 to len scratch
           inspect function reverse (str)
           tallying scratch for leading spaces
               len for characters after space
           move function reverse (str (1:len)) to str
           .
       end program prepend.
Task: String prepend








VB: Function StringPrepend()
Dim s As String
s = "bar"
s = "foo" & s
Debug.Print s
End Function


COBOL:        identification division.
       program-id. prepend.
       data division.
       working-storage section.
       1 str pic x(30) value "World!".
       1 binary.
        2 len pic 9(4) value 0.
        2 scratch pic 9(4) value 0.
       procedure division.
       begin.
           perform rev-sub-str
           move function reverse ("Hello ") to str (len + 1:)
           perform rev-sub-str
           display str
           stop run
           .

       rev-sub-str.
           move 0 to len scratch
           inspect function reverse (str)
           tallying scratch for leading spaces
               len for characters after space
           move function reverse (str (1:len)) to str
           .
       end program prepend.
Task: String prepend




Go: s := "world!"
s = "Hello, " + s






COBOL:        identification division.
       program-id. prepend.
       data division.
       working-storage section.
       1 str pic x(30) value "World!".
       1 binary.
        2 len pic 9(4) value 0.
        2 scratch pic 9(4) value 0.
       procedure division.
       begin.
           perform rev-sub-str
           move function reverse ("Hello ") to str (len + 1:)
           perform rev-sub-str
           display str
           stop run
           .

       rev-sub-str.
           move 0 to len scratch
           inspect function reverse (str)
           tallying scratch for leading spaces
               len for characters after space
           move function reverse (str (1:len)) to str
           .
       end program prepend.
Task: Currency



C#: using System;
using System.Collections.Generic;

namespace Currency
{
    class Program
    {
        static void Main(string[] args)
        {
            MenuItem hamburger = new MenuItem() { Name = "Hamburger", Price = 5.5M };
            MenuItem milkshake = new MenuItem() { Name = "Milkshake", Price = 2.86M };

            IList<CartItem> cart = new List<CartItem>();
            cart.Add(new CartItem() { item = hamburger, quantity = 4000000000000000 });
            cart.Add(new CartItem() { item = milkshake, quantity = 2 });

            decimal total = CalculateTotal(cart);

            Console.WriteLine(string.Format("Total before tax: {0:C}", total));

            
            decimal tax = total * 0.0765M;

            Console.WriteLine(string.Format("Tax: {0:C}", tax));

            total += tax;

            Console.WriteLine(string.Format("Total with tax: {0:C}", total));
        }

        private static decimal CalculateTotal(IList<CartItem> cart)
        {
            decimal total = 0M;

            foreach (CartItem item in cart)
            {
                total += item.quantity * item.item.Price;
            }

            return total;
        }

        private struct MenuItem
        {
            public string Name { get; set; }
            public decimal Price { get; set; }
        }

        private struct CartItem
        {
            public MenuItem item { get; set; }
            public decimal quantity { get; set; }
        }
    }
}









Ada: with Ada.Text_IO;

procedure Currency is
   type Dollar is delta 0.01 range 0.0 .. 24_000_000_000_000_000.0;
   package Dollar_IO is new Ada.Text_IO.Fixed_IO(Dollar);

   hamburger_cost : constant := 5.50;
   milkshake_cost : constant := 2.86;
   tax_rate : constant := 0.0765;

   total_cost : constant := hamburger_cost * 4_000_000_000_000_000.0 + milkshake_cost * 2;
   total_tax : constant := total_cost * tax_rate;
   total_with_tax : constant := total_cost + total_tax;
begin
   Ada.Text_IO.Put("Price before tax:");
   Dollar_IO.Put(total_cost);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Tax:             ");
   Dollar_IO.Put(total_tax);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Total:           ");
   Dollar_IO.Put(total_with_tax);
   Ada.Text_IO.New_Line;
end Currency;
Task: Currency

C: 	mpf_set_d(burgerUnitPrice,5.50);
	mpf_set_d(milkshakePrice,2 * 2.86);
	mpf_set_d(burgerNum,4000000000000000);
	mpf_set_d(milkshakeNum,2);











Ada: with Ada.Text_IO;

procedure Currency is
   type Dollar is delta 0.01 range 0.0 .. 24_000_000_000_000_000.0;
   package Dollar_IO is new Ada.Text_IO.Fixed_IO(Dollar);

   hamburger_cost : constant := 5.50;
   milkshake_cost : constant := 2.86;
   tax_rate : constant := 0.0765;

   total_cost : constant := hamburger_cost * 4_000_000_000_000_000.0 + milkshake_cost * 2;
   total_tax : constant := total_cost * tax_rate;
   total_with_tax : constant := total_cost + total_tax;
begin
   Ada.Text_IO.Put("Price before tax:");
   Dollar_IO.Put(total_cost);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Tax:             ");
   Dollar_IO.Put(total_tax);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Total:           ");
   Dollar_IO.Put(total_with_tax);
   Ada.Text_IO.New_Line;
end Currency;
Task: Currency




Go: package main

import (
    "fmt"
    "log"
    "math/big"
)


type DC int64

func (dc DC) String() string {
    d := dc / 100
    if dc < 0 {
        dc = -dc
    }
    return fmt.Sprintf("%d.%02d", d, dc%100)
}


func (dc DC) Extend(n int) DC {
    return dc * DC(n)
}

var one = big.NewInt(1)
var hundred = big.NewRat(100, 1)


func ParseDC(s string) (DC, bool) {
    r, ok := new(big.Rat).SetString(s)
    if !ok {
        return 0, false
    }
    r.Mul(r, hundred)
    if r.Denom().Cmp(one) != 0 {
        return 0, false
    }
    return DC(r.Num().Int64()), true
}


type TR struct {
    *big.Rat
}
func NewTR() TR {
    return TR{new(big.Rat)}
}


func (tr TR) SetString(s string) (TR, bool) {
    if _, ok := tr.Rat.SetString(s); !ok {
        return TR{}, false
    }
    return tr, true
}

var half = big.NewRat(1, 2)


func (tr TR) Tax(dc DC) DC {
    r := big.NewRat(int64(dc), 1)
    r.Add(r.Mul(r, tr.Rat), half)
    return DC(new(big.Int).Div(r.Num(), r.Denom()).Int64())
}

func main() {
    hamburgerPrice, ok := ParseDC("5.50")
    if !ok {
        log.Fatal("Invalid hamburger price")
    }
    milkshakePrice, ok := ParseDC("2.86")
    if !ok {
        log.Fatal("Invalid milkshake price")
    }
    taxRate, ok := NewTR().SetString("0.0765")
    if !ok {
        log.Fatal("Invalid tax rate")
    }

    totalBeforeTax := hamburgerPrice.Extend(4000000000000000) +
        milkshakePrice.Extend(2)
    tax := taxRate.Tax(totalBeforeTax)
    total := totalBeforeTax + tax

    fmt.Printf("Total before tax: %22s\n", totalBeforeTax)
    fmt.Printf("             Tax: %22s\n", tax)
    fmt.Printf("           Total: %22s\n", total)
}








Ada: with Ada.Text_IO;

procedure Currency is
   type Dollar is delta 0.01 range 0.0 .. 24_000_000_000_000_000.0;
   package Dollar_IO is new Ada.Text_IO.Fixed_IO(Dollar);

   hamburger_cost : constant := 5.50;
   milkshake_cost : constant := 2.86;
   tax_rate : constant := 0.0765;

   total_cost : constant := hamburger_cost * 4_000_000_000_000_000.0 + milkshake_cost * 2;
   total_tax : constant := total_cost * tax_rate;
   total_with_tax : constant := total_cost + total_tax;
begin
   Ada.Text_IO.Put("Price before tax:");
   Dollar_IO.Put(total_cost);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Tax:             ");
   Dollar_IO.Put(total_tax);
   Ada.Text_IO.New_Line;

   Ada.Text_IO.Put("Total:           ");
   Dollar_IO.Put(total_with_tax);
   Ada.Text_IO.New_Line;
end Currency;