WeixiangYan/CodeTransOcean huggingface dataset:
Task: Anagrams



C#: using System;
using System.IO;
using System.Linq;
using System.Net;
using System.Text.RegularExpressions;

namespace Anagram
{
    class Program
    {
        const string DICO_URL = "http:

        static void Main( string[] args )
        {
            WebRequest request = WebRequest.Create(DICO_URL);
            string[] words;
            using (StreamReader sr = new StreamReader(request.GetResponse().GetResponseStream(), true)) {
                words = Regex.Split(sr.ReadToEnd(), @"\r?\n");
            }
            var groups = from string w in words
                         group w by string.Concat(w.OrderBy(x => x)) into c
                         group c by c.Count() into d
                         orderby d.Key descending
                         select d;
            foreach (var c in groups.First()) {
                Console.WriteLine(string.Join(" ", c));
            }
        }
    }
}




PHP: <?php
$words = explode("\n", file_get_contents('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'));
foreach ($words as $word) {
    $chars = str_split($word);
    sort($chars);
    $anagram[implode($chars)][] = $word;
}

$best = max(array_map('count', $anagram));
foreach ($anagram as $ana)
    if (count($ana) == $best)
        print_r($ana);
?>
Task: Anagrams


C++: #include <iostream>
#include <fstream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iterator>
 
int main() {
  std::ifstream in("unixdict.txt");
  typedef  std::map<std::string, std::vector<std::string> > AnagramMap;
  AnagramMap anagrams;
 
  std::string word;
  size_t count = 0;
  while (std::getline(in, word)) {
    std::string key = word;
    std::sort(key.begin(), key.end());
    
    AnagramMap::mapped_type & v = anagrams[key];
    v.push_back(word);
    count = std::max(count, v.size());
  }
 
  in.close();
 
  for (AnagramMap::const_iterator it = anagrams.begin(), e = anagrams.end();
       it != e; it++)
    if (it->second.size() >= count) {
      std::copy(it->second.begin(), it->second.end(),
                std::ostream_iterator<std::string>(std::cout, ", "));
      std::cout << std::endl;
    }
  return 0;
}





PHP: <?php
$words = explode("\n", file_get_contents('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'));
foreach ($words as $word) {
    $chars = str_split($word);
    sort($chars);
    $anagram[implode($chars)][] = $word;
}

$best = max(array_map('count', $anagram));
foreach ($anagram as $ana)
    if (count($ana) == $best)
        print_r($ana);
?>
Task: Anagrams




Go: package main

import (
    "bytes"
    "fmt"
    "io/ioutil"
    "net/http"
    "sort"
)

func main() {
    r, err := http.Get("http:
    if err != nil {
        fmt.Println(err)
        return
    }
    b, err := ioutil.ReadAll(r.Body)
    r.Body.Close()
    if err != nil {
        fmt.Println(err)
        return
    }
    var ma int
    var bs byteSlice
    m := make(map[string][][]byte)
    for _, word := range bytes.Fields(b) {
        bs = append(bs[:0], byteSlice(word)...)
        sort.Sort(bs)
        k := string(bs)
        a := append(m[k], word)
        if len(a) > ma {
            ma = len(a)
        }
        m[k] = a
    }
    for _, a := range m {
        if len(a) == ma {
            fmt.Printf("%s\n", a)
        }
    }
}

type byteSlice []byte

func (b byteSlice) Len() int           { return len(b) }
func (b byteSlice) Swap(i, j int)      { b[i], b[j] = b[j], b[i] }
func (b byteSlice) Less(i, j int) bool { return b[i] < b[j] }



PHP: <?php
$words = explode("\n", file_get_contents('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'));
foreach ($words as $word) {
    $chars = str_split($word);
    sort($chars);
    $anagram[implode($chars)][] = $word;
}

$best = max(array_map('count', $anagram));
foreach ($anagram as $ana)
    if (count($ana) == $best)
        print_r($ana);
?>
Task: Anagrams





Java: import java.net.*;
import java.io.*;
import java.util.*;
 
public class WordsOfEqChars {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http:
        InputStreamReader isr = new InputStreamReader(url.openStream());
        BufferedReader reader = new BufferedReader(isr);

        Map<String, Collection<String>> anagrams = new HashMap<String, Collection<String>>();
        String word;
        int count = 0;
        while ((word = reader.readLine()) != null) {
            char[] chars = word.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            if (!anagrams.containsKey(key))
                anagrams.put(key, new ArrayList<String>());
            anagrams.get(key).add(word);
            count = Math.max(count, anagrams.get(key).size());
        }

        reader.close();

        for (Collection<String> ana : anagrams.values())
            if (ana.size() >= count)
                System.out.println(ana);
    }   
}


PHP: <?php
$words = explode("\n", file_get_contents('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'));
foreach ($words as $word) {
    $chars = str_split($word);
    sort($chars);
    $anagram[implode($chars)][] = $word;
}

$best = max(array_map('count', $anagram));
foreach ($anagram as $ana)
    if (count($ana) == $best)
        print_r($ana);
?>
Task: Anagrams






PHP: <?php
$words = explode("\n", file_get_contents('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'));
foreach ($words as $word) {
    $chars = str_split($word);
    sort($chars);
    $anagram[implode($chars)][] = $word;
}

$best = max(array_map('count', $anagram));
foreach ($anagram as $ana)
    if (count($ana) == $best)
        print_r($ana);
?>


Python: >>> import urllib.request
>>> from collections import defaultdict
>>> words = urllib.request.urlopen('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt').read().split()
>>> anagram = defaultdict(list) 
>>> for word in words:
	anagram[tuple(sorted(word))].append( word )

	
>>> count = max(len(ana) for ana in anagram.values())
>>> for ana in anagram.values():
	if len(ana) >= count:
		print ([x.decode() for x in ana])
Task: Anagrams






PHP: <?php
$words = explode("\n", file_get_contents('http://wiki.puzzlers.org/pub/wordlists/unixdict.txt'));
foreach ($words as $word) {
    $chars = str_split($word);
    sort($chars);
    $anagram[implode($chars)][] = $word;
}

$best = max(array_map('count', $anagram));
foreach ($anagram as $ana)
    if (count($ana) == $best)
        print_r($ana);
?>



VB: dim x as integer, y as integer
dim SortX as integer
dim StrOutPut as string
dim Count as integer
dim MaxCount as integer

dim AnaList as QStringlist
dim wordlist as QStringlist
dim Templist as QStringlist
dim Charlist as Qstringlist


function sortChars(expr as string) as string
    Charlist.clear
    for SortX = 1 to len(expr)
         Charlist.AddItems expr[SortX]
    next
    charlist.sort
    result = Charlist.text - chr$(10) - chr$(13)
end function
 

    wordlist.loadfromfile ("unixdict.txt")

    
    for x = 0 to wordlist.itemcount-1
        AnaList.AddItems sortChars(wordlist.item(x))
    next
       
    
    analist.sort
    MaxCount = 0
    
    for x = 0 to AnaList.Itemcount-1
        Count = 0
        for y = x+1 to AnaList.Itemcount-1
            if AnaList.item(y) = AnaList.item(x) then
                inc(count)
            else
                if count > MaxCount then 
                    Templist.clear
                    MaxCount = Count
                    Templist.AddItems AnaList.item(x)
                elseif count = MaxCount then
                    Templist.AddItems AnaList.item(x)
                end if
                exit for
            end if
        next
    next
       
    
    for x = 0 to Templist.Itemcount-1
        for y = 0 to wordlist.Itemcount-1 
            if Templist.item(x) = sortChars(wordlist.item(y)) then
                StrOutPut = StrOutPut + wordlist.item(y) + "  "
            end if
        next
        StrOutPut = StrOutPut + chr$(13) + chr$(10)
    next

ShowMessage StrOutPut 
End
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}



C#: if (problem)
{
   Environment.Exit(1);
}
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}





Java: if(problem){
   System.exit(integerErrorCode); 
   
   
   
}
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}







Python: import sys
if problem:
    sys.exit(1)
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}








VB: 
If problem then End

If problem then Application.Quit
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}


C#: if (problem)
{
   Environment.Exit(1);
}
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}






Python: import sys
if problem:
    sys.exit(1)
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}







VB: 
If problem then End

If problem then Application.Quit
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}



Go: func main() {
    if problem {
        return
    }
}
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}




Java: if(problem){
   System.exit(integerErrorCode); 
   
   
   
}
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}




Go: func main() {
    if problem {
        return
    }
}
Task: Program termination

C: #include <stdlib.h>

int main(int argc, char **argv)
{
  
     ...
  return 0;  
}

if(problem){
  exit(exit_code);
  
}






PHP: if (problem)
    exit(1);
Task: Program termination


C++: #include <cstdlib>

void problem_occured()
{
  std::exit(EXIT_FAILURE);
}





PHP: if (problem)
    exit(1);
Task: Sum data type

C: #include<stdio.h>

typedef union data{
        int i;
        float f;
        char c;
}united;

int main()
{
        united udat;

        udat.i = 5;
        udat.f = 3.14159;
        udat.c = 'C';

        printf("Integer   i = %d , address of i = %p\n",udat.i,&udat.i);
        printf("Float     f = %f , address of f = %p\n",udat.f,&udat.f);
        printf("Character c = %c , address of c = %p\n",udat.c,&udat.c);

        return 0;
}



C#: #include <iostream>
#include <optional>
#include <string>
#include <variant>
#include <vector>


std::variant<int, std::string, bool, int> myVariant{"Ukraine"}; 

struct Tree
{
  
  
  
  std::variant<std::vector<Tree>, int> Nodes;
};

Tree tree1; 
Tree tree2{2}; 


Tree tree3{std::vector{Tree{3}, Tree{std::vector{Tree{2}, Tree{7}}}, Tree{8}}};


std::optional<int> maybeInt1;    
std::optional<int> maybeInt2{2}; 


int* intPtr1 = nullptr;  

int value = 3;
int* intPtr2 = &value; 


void PrintTree(const Tree& tree)
{
  std::cout << "(";
  if(holds_alternative<int>(tree.Nodes))
  {
    std::cout << get<1>(tree.Nodes);
  }
  else
  {
    for(const auto& subtree : get<0>(tree.Nodes)) PrintTree(subtree);
  }
  std::cout <<")";
}

int main()
{
  std::cout << "myVariant: " << get<std::string>(myVariant) << "\n";

  PrintTree(tree1); std::cout << "\n";
  PrintTree(tree2); std::cout << "\n";
  PrintTree(tree3); std::cout << "\n";

  std::cout << "*maybeInt2: " << *maybeInt2 << "\n";
  std::cout << "intPtr1: " << intPtr1 << "\n";
  std::cout << "*intPtr2: " << *intPtr2 << "\n";
}
Task: Sum data type

C: #include<stdio.h>

typedef union data{
        int i;
        float f;
        char c;
}united;

int main()
{
        united udat;

        udat.i = 5;
        udat.f = 3.14159;
        udat.c = 'C';

        printf("Integer   i = %d , address of i = %p\n",udat.i,&udat.i);
        printf("Float     f = %f , address of f = %p\n",udat.f,&udat.f);
        printf("Character c = %c , address of c = %p\n",udat.c,&udat.c);

        return 0;
}


C++: #include <iostream>
#include <optional>
#include <string>
#include <variant>
#include <vector>


std::variant<int, std::string, bool, int> myVariant{"Ukraine"}; 

struct Tree
{
  
  
  
  std::variant<std::vector<Tree>, int> Nodes;
};

Tree tree1; 
Tree tree2{2}; 


Tree tree3{std::vector{Tree{3}, Tree{std::vector{Tree{2}, Tree{7}}}, Tree{8}}};


std::optional<int> maybeInt1;    
std::optional<int> maybeInt2{2}; 


int* intPtr1 = nullptr;  

int value = 3;
int* intPtr2 = &value; 


void PrintTree(const Tree& tree)
{
  std::cout << "(";
  if(holds_alternative<int>(tree.Nodes))
  {
    std::cout << get<1>(tree.Nodes);
  }
  else
  {
    for(const auto& subtree : get<0>(tree.Nodes)) PrintTree(subtree);
  }
  std::cout <<")";
}

int main()
{
  std::cout << "myVariant: " << get<std::string>(myVariant) << "\n";

  PrintTree(tree1); std::cout << "\n";
  PrintTree(tree2); std::cout << "\n";
  PrintTree(tree3); std::cout << "\n";

  std::cout << "*maybeInt2: " << *maybeInt2 << "\n";
  std::cout << "intPtr1: " << intPtr1 << "\n";
  std::cout << "*intPtr2: " << *intPtr2 << "\n";
}
Task: Sum data type

C: #include<stdio.h>

typedef union data{
        int i;
        float f;
        char c;
}united;

int main()
{
        united udat;

        udat.i = 5;
        udat.f = 3.14159;
        udat.c = 'C';

        printf("Integer   i = %d , address of i = %p\n",udat.i,&udat.i);
        printf("Float     f = %f , address of f = %p\n",udat.f,&udat.f);
        printf("Character c = %c , address of c = %p\n",udat.c,&udat.c);

        return 0;
}





Java: import java.util.Arrays;

public class SumDataType {

    public static void main(String[] args) {
        for ( ObjectStore<?> e : Arrays.asList(new ObjectStore<String>("String"), new ObjectStore<Integer>(23), new ObjectStore<Float>(new Float(3.14159))) ) {
            System.out.println("Object : " + e);
        }
    }
    
    public static class ObjectStore<T> {
        private T object;
        public ObjectStore(T object) {
            this.object = object;
        }
        @Override
        public String toString() {
            return "value [" + object.toString() + "], type = " + object.getClass();
        }
    }

}
Task: Sum data type


C++: #include <iostream>
#include <optional>
#include <string>
#include <variant>
#include <vector>


std::variant<int, std::string, bool, int> myVariant{"Ukraine"}; 

struct Tree
{
  
  
  
  std::variant<std::vector<Tree>, int> Nodes;
};

Tree tree1; 
Tree tree2{2}; 


Tree tree3{std::vector{Tree{3}, Tree{std::vector{Tree{2}, Tree{7}}}, Tree{8}}};


std::optional<int> maybeInt1;    
std::optional<int> maybeInt2{2}; 


int* intPtr1 = nullptr;  

int value = 3;
int* intPtr2 = &value; 


void PrintTree(const Tree& tree)
{
  std::cout << "(";
  if(holds_alternative<int>(tree.Nodes))
  {
    std::cout << get<1>(tree.Nodes);
  }
  else
  {
    for(const auto& subtree : get<0>(tree.Nodes)) PrintTree(subtree);
  }
  std::cout <<")";
}

int main()
{
  std::cout << "myVariant: " << get<std::string>(myVariant) << "\n";

  PrintTree(tree1); std::cout << "\n";
  PrintTree(tree2); std::cout << "\n";
  PrintTree(tree3); std::cout << "\n";

  std::cout << "*maybeInt2: " << *maybeInt2 << "\n";
  std::cout << "intPtr1: " << intPtr1 << "\n";
  std::cout << "*intPtr2: " << *intPtr2 << "\n";
}




Java: import java.util.Arrays;

public class SumDataType {

    public static void main(String[] args) {
        for ( ObjectStore<?> e : Arrays.asList(new ObjectStore<String>("String"), new ObjectStore<Integer>(23), new ObjectStore<Float>(new Float(3.14159))) ) {
            System.out.println("Object : " + e);
        }
    }
    
    public static class ObjectStore<T> {
        private T object;
        public ObjectStore(T object) {
            this.object = object;
        }
        @Override
        public String toString() {
            return "value [" + object.toString() + "], type = " + object.getClass();
        }
    }

}
Task: Sum data type




Go: package main

import (
    "errors"
    "fmt"
)

type (
    IpAddr struct{ v interface{} }
    Ipv4   = [4]uint8
    Ipv6   = string
)

var zero = Ipv4{}

func NewIpAddr(v interface{}) (*IpAddr, error) {
    switch v.(type) {
    case Ipv4, Ipv6:
        return &IpAddr{v}, nil
    default:
        err := errors.New("Type of value must either be Ipv4 or Ipv6.")
        return nil, err
    }
}

func (ip *IpAddr) V4() (Ipv4, error) {
    switch ip.v.(type) {
    case Ipv4:
        return ip.v.(Ipv4), nil
    default:
        err := errors.New("IpAddr instance doesn't currently hold an Ipv4.")
        return zero, err
    }
}

func (ip *IpAddr) SetV4(v Ipv4) {
    ip.v = v
}

func (ip *IpAddr) V6() (Ipv6, error) {
    switch ip.v.(type) {
    case Ipv6:
        return ip.v.(Ipv6), nil
    default:
        err := errors.New("IpAddr instance doesn't currently hold an Ipv6.")
        return "", err
    }
}

func (ip *IpAddr) SetV6(v Ipv6) {
    ip.v = v
}

func check(err error) {
    if err != nil {
        fmt.Println(err)
    }
}

func main() {
    v4 := Ipv4{127, 0, 0, 1}
    ip, _ := NewIpAddr(v4)
    home, _ := ip.V4()
    fmt.Println(home)
    v6 := "::1"
    ip.SetV6(v6)
    loopback, _ := ip.V6()
    fmt.Println(loopback)
    _, err := ip.V4()
    check(err)
    rubbish := 6
    ip, err = NewIpAddr(rubbish)
    check(err)
}


Java: import java.util.Arrays;

public class SumDataType {

    public static void main(String[] args) {
        for ( ObjectStore<?> e : Arrays.asList(new ObjectStore<String>("String"), new ObjectStore<Integer>(23), new ObjectStore<Float>(new Float(3.14159))) ) {
            System.out.println("Object : " + e);
        }
    }
    
    public static class ObjectStore<T> {
        private T object;
        public ObjectStore(T object) {
            this.object = object;
        }
        @Override
        public String toString() {
            return "value [" + object.toString() + "], type = " + object.getClass();
        }
    }

}
Task: Sum data type

C: #include<stdio.h>

typedef union data{
        int i;
        float f;
        char c;
}united;

int main()
{
        united udat;

        udat.i = 5;
        udat.f = 3.14159;
        udat.c = 'C';

        printf("Integer   i = %d , address of i = %p\n",udat.i,&udat.i);
        printf("Float     f = %f , address of f = %p\n",udat.f,&udat.f);
        printf("Character c = %c , address of c = %p\n",udat.c,&udat.c);

        return 0;
}




Go: package main

import (
    "errors"
    "fmt"
)

type (
    IpAddr struct{ v interface{} }
    Ipv4   = [4]uint8
    Ipv6   = string
)

var zero = Ipv4{}

func NewIpAddr(v interface{}) (*IpAddr, error) {
    switch v.(type) {
    case Ipv4, Ipv6:
        return &IpAddr{v}, nil
    default:
        err := errors.New("Type of value must either be Ipv4 or Ipv6.")
        return nil, err
    }
}

func (ip *IpAddr) V4() (Ipv4, error) {
    switch ip.v.(type) {
    case Ipv4:
        return ip.v.(Ipv4), nil
    default:
        err := errors.New("IpAddr instance doesn't currently hold an Ipv4.")
        return zero, err
    }
}

func (ip *IpAddr) SetV4(v Ipv4) {
    ip.v = v
}

func (ip *IpAddr) V6() (Ipv6, error) {
    switch ip.v.(type) {
    case Ipv6:
        return ip.v.(Ipv6), nil
    default:
        err := errors.New("IpAddr instance doesn't currently hold an Ipv6.")
        return "", err
    }
}

func (ip *IpAddr) SetV6(v Ipv6) {
    ip.v = v
}

func check(err error) {
    if err != nil {
        fmt.Println(err)
    }
}

func main() {
    v4 := Ipv4{127, 0, 0, 1}
    ip, _ := NewIpAddr(v4)
    home, _ := ip.V4()
    fmt.Println(home)
    v6 := "::1"
    ip.SetV6(v6)
    loopback, _ := ip.V6()
    fmt.Println(loopback)
    _, err := ip.V4()
    check(err)
    rubbish := 6
    ip, err = NewIpAddr(rubbish)
    check(err)
}
Task: Sum data type


C++: #include <iostream>
#include <optional>
#include <string>
#include <variant>
#include <vector>


std::variant<int, std::string, bool, int> myVariant{"Ukraine"}; 

struct Tree
{
  
  
  
  std::variant<std::vector<Tree>, int> Nodes;
};

Tree tree1; 
Tree tree2{2}; 


Tree tree3{std::vector{Tree{3}, Tree{std::vector{Tree{2}, Tree{7}}}, Tree{8}}};


std::optional<int> maybeInt1;    
std::optional<int> maybeInt2{2}; 


int* intPtr1 = nullptr;  

int value = 3;
int* intPtr2 = &value; 


void PrintTree(const Tree& tree)
{
  std::cout << "(";
  if(holds_alternative<int>(tree.Nodes))
  {
    std::cout << get<1>(tree.Nodes);
  }
  else
  {
    for(const auto& subtree : get<0>(tree.Nodes)) PrintTree(subtree);
  }
  std::cout <<")";
}

int main()
{
  std::cout << "myVariant: " << get<std::string>(myVariant) << "\n";

  PrintTree(tree1); std::cout << "\n";
  PrintTree(tree2); std::cout << "\n";
  PrintTree(tree3); std::cout << "\n";

  std::cout << "*maybeInt2: " << *maybeInt2 << "\n";
  std::cout << "intPtr1: " << intPtr1 << "\n";
  std::cout << "*intPtr2: " << *intPtr2 << "\n";
}



Go: package main

import (
    "errors"
    "fmt"
)

type (
    IpAddr struct{ v interface{} }
    Ipv4   = [4]uint8
    Ipv6   = string
)

var zero = Ipv4{}

func NewIpAddr(v interface{}) (*IpAddr, error) {
    switch v.(type) {
    case Ipv4, Ipv6:
        return &IpAddr{v}, nil
    default:
        err := errors.New("Type of value must either be Ipv4 or Ipv6.")
        return nil, err
    }
}

func (ip *IpAddr) V4() (Ipv4, error) {
    switch ip.v.(type) {
    case Ipv4:
        return ip.v.(Ipv4), nil
    default:
        err := errors.New("IpAddr instance doesn't currently hold an Ipv4.")
        return zero, err
    }
}

func (ip *IpAddr) SetV4(v Ipv4) {
    ip.v = v
}

func (ip *IpAddr) V6() (Ipv6, error) {
    switch ip.v.(type) {
    case Ipv6:
        return ip.v.(Ipv6), nil
    default:
        err := errors.New("IpAddr instance doesn't currently hold an Ipv6.")
        return "", err
    }
}

func (ip *IpAddr) SetV6(v Ipv6) {
    ip.v = v
}

func check(err error) {
    if err != nil {
        fmt.Println(err)
    }
}

func main() {
    v4 := Ipv4{127, 0, 0, 1}
    ip, _ := NewIpAddr(v4)
    home, _ := ip.V4()
    fmt.Println(home)
    v6 := "::1"
    ip.SetV6(v6)
    loopback, _ := ip.V6()
    fmt.Println(loopback)
    _, err := ip.V4()
    check(err)
    rubbish := 6
    ip, err = NewIpAddr(rubbish)
    check(err)
}
Task: Input_Output for pairs of numbers

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

int main(void)
{
	int i, n, a, b, *f;
	scanf("%d", &n);
	f = malloc(sizeof(*f) * n);

	for (i = 0; i < n; i++) {
		if (2 != scanf("%d %d", &a, &b))
			abort();
		f[i] = a + b;
	}

	for (i = 0; i < n; i++)
		printf("%d\n", f[i]);

	return 0;
}



C#: #include <iostream>
#include <vector>
using namespace std;
 
int doStuff(int a, int b) {
	return a + b;
}
 
int main() {
 
	int t;
	cin >> t;
 
	vector<pair<int, int>> list(t);
 
	for(int j=0; j<t; j++){
		cin >> list[j].first >> list[j].second;
	}
 
	cout << endl;
 
	for(int j=0;j<t;j++){
		cout << doStuff(list[j].first, list[j].second) << endl;;
	}
}
Task: Input_Output for pairs of numbers

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

int main(void)
{
	int i, n, a, b, *f;
	scanf("%d", &n);
	f = malloc(sizeof(*f) * n);

	for (i = 0; i < n; i++) {
		if (2 != scanf("%d %d", &a, &b))
			abort();
		f[i] = a + b;
	}

	for (i = 0; i < n; i++)
		printf("%d\n", f[i]);

	return 0;
}




Go: package main

import (
	"fmt"
	"log"
)

func main() {
	var lines int
	n, err := fmt.Scanln(&lines)
	if n != 1 || err != nil {
		log.Fatal(err)
	}

	var a, b int
	for ; lines > 0; lines-- {
		n, err = fmt.Scanln(&a, &b)
		if n != 2 || err != nil {
			log.Fatal(err)
		}
		fmt.Println(a + b)
	}
}