WeixiangYan/CodeTransOcean huggingface dataset:
Task: Inheritance_Single






PHP: class Animal {

}

class Dog extends Animal {

}

class Cat extends Animal {

}

class Lab extends Dog {

}

class Collie extends Dog {

}






Ada: package Inheritance is
   type Animal is tagged private;
   type Dog is new Animal with private;
   type Cat is new Animal with private;
   type Lab is new Dog with private;
   type Collie is new Dog with private;
private
   type Animal is tagged null record;
   type Dog is new Animal with null record;
   type Cat is new Animal with null record;
   type Lab is new Dog with null record;
   type Collie is new Dog with null record;
end Inheritance;
Task: Inheritance_Single






PHP: class Animal {

}

class Dog extends Animal {

}

class Cat extends Animal {

}

class Lab extends Dog {

}

class Collie extends Dog {

}




COBOL:        CLASS-ID. Animal.
           
       END CLASS Animal.
       
       CLASS-ID. Dog INHERITS Animal.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS Animal.

           
       END CLASS Dog.
       
       CLASS-ID. Cat INHERITS Animal. 
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS Animal. 

           
       END CLASS Cat.
           
       CLASS-ID. Lab INHERITS Dog.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS Dog.

           
       END CLASS Lab.
       
       CLASS-ID. Collie INHERITS Dog.
       ENVIRONMENT DIVISION.
       CONFIGURATION SECTION.
       REPOSITORY.
           CLASS Dog.

           
       END CLASS Collie.
Task: Averages_Mode



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

namespace Test
{
    class Program
    {
     
        static void Main(string[] args)
        {
            
            List<int> myList = new List<int>() { 1, 1, 2, 4, 4 }; 

            var query =     from numbers in myList 
                            group numbers by numbers 
                            into groupedNumbers
                            select new { Number = groupedNumbers.Key, Count = groupedNumbers.Count() }; 
            
            int max = query.Max(g => g.Count);
            IEnumerable<int> modes = query.Where(x => x.Count == max).Select(x => x.Number);
            foreach (var item in modes)
            {
                Console.WriteLine(item);
            }
            
            Console.ReadLine();
        }

             
       
    }
     
    
}









Ada: generic
   type Element_Type is private;
   type Element_Array is array (Positive range <>) of Element_Type;
package Mode is

   function Get_Mode (Set : Element_Array) return Element_Array;

end Mode;
Task: Averages_Mode

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

typedef struct { double v; int c; } vcount;

int cmp_dbl(const void *a, const void *b)
{
	double x = *(const double*)a - *(const double*)b;
	return x < 0 ? -1 : x > 0;
}

int vc_cmp(const void *a, const void *b)
{
	return ((const vcount*)b)->c - ((const vcount*)a)->c;
}

int get_mode(double* x, int len, vcount **list)
{
	int i, j;
	vcount *vc;

	
	qsort(x, len, sizeof(double), cmp_dbl);

	
	for (i = 0, j = 1; i < len - 1; i++, j += (x[i] != x[i + 1]));

	*list = vc = malloc(sizeof(vcount) * j);
	vc[0].v = x[0];
	vc[0].c = 1;

	
	for (i = j = 0; i < len - 1; i++, vc[j].c++)
		if (x[i] != x[i + 1]) vc[++j].v = x[i + 1];

	
	qsort(vc, j + 1, sizeof(vcount), vc_cmp);

	
	for (i = 0; i <= j && vc[i].c == vc[0].c; i++);

	return i;
}

int main()
{
	double values[] = { 1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 12, 12, 17 };
#	define len sizeof(values)/sizeof(double)
	vcount *vc;

	int i, n_modes = get_mode(values, len, &vc);

	printf("got %d modes:\n", n_modes);
	for (i = 0; i < n_modes; i++)
		printf("\tvalue = %g, count = %d\n", vc[i].v, vc[i].c);

	free(vc);
	return 0;
}











Ada: generic
   type Element_Type is private;
   type Element_Array is array (Positive range <>) of Element_Type;
package Mode is

   function Get_Mode (Set : Element_Array) return Element_Array;

end Mode;
Task: Averages_Mode


C++: #include <iterator>
#include <utility>
#include <algorithm>
#include <list>
#include <iostream>


template<typename T> struct referring
{
  referring(T const& t): value(t) {}
  template<typename Iter>
   bool operator()(std::pair<Iter, int> const& p) const
  {
    return *p.first == value;
  }
  T const& value;
};









template<typename FwdIterator, typename OutIterator>
 void mode(FwdIterator first, FwdIterator last, OutIterator result)
{
  typedef typename std::iterator_traits<FwdIterator>::value_type value_type;
  typedef std::list<std::pair<FwdIterator, int> > count_type;
  typedef typename count_type::iterator count_iterator;

  
  count_type counts;

  while (first != last)
  {
    count_iterator element = std::find_if(counts.begin(), counts.end(),
                                          referring<value_type>(*first));
    if (element == counts.end())
      counts.push_back(std::make_pair(first, 1));
    else
      ++element->second;
    ++first;
  }

  
  int max = 0;
  for (count_iterator i = counts.begin(); i != counts.end(); ++i)
    if (i->second > max)
      max = i->second;

  
  for (count_iterator i = counts.begin(); i != counts.end(); ++i)
    if (i->second == max)
      *result++ = *i->first;
}


int main()
{
  int values[] = { 1, 2, 3, 1, 2, 4, 2, 5, 2, 3, 3, 1, 3, 6 };
  median(values, values + sizeof(values)/sizeof(int),
         std::ostream_iterator<int>(std::cout, " "));
  std::cout << std::endl;
  return 0;
}










Ada: generic
   type Element_Type is private;
   type Element_Array is array (Positive range <>) of Element_Type;
package Mode is

   function Get_Mode (Set : Element_Array) return Element_Array;

end Mode;
Task: Averages_Mode




Go: package main

import "fmt"

func main() {
    fmt.Println(mode([]int{2, 7, 1, 8, 2}))
    fmt.Println(mode([]int{2, 7, 1, 8, 2, 8}))
}

func mode(a []int) []int {
    m := make(map[int]int)
    for _, v := range a {
        m[v]++
    }
    var mode []int
    var n int
    for k, v := range m {
        switch {
        case v < n:
        case v > n:
            n = v
            mode = append(mode[:0], k)
        default:
            mode = append(mode, k)
        }
    }
    return mode
}








Ada: generic
   type Element_Type is private;
   type Element_Array is array (Positive range <>) of Element_Type;
package Mode is

   function Get_Mode (Set : Element_Array) return Element_Array;

end Mode;
Task: Averages_Mode





Java: import java.util.*;

public class Mode {
    public static <T> List<T> mode(List<? extends T> coll) {
        Map<T, Integer> seen = new HashMap<T, Integer>();
        int max = 0;
        List<T> maxElems = new ArrayList<T>();
        for (T value : coll) {
            if (seen.containsKey(value))
                seen.put(value, seen.get(value) + 1);
            else
                seen.put(value, 1);
            if (seen.get(value) > max) {
                max = seen.get(value);
                maxElems.clear();
                maxElems.add(value);
            } else if (seen.get(value) == max) {
                maxElems.add(value);
            }
        }
        return maxElems;
    }

    public static void main(String[] args) {
        System.out.println(mode(Arrays.asList(1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17))); 
        System.out.println(mode(Arrays.asList(1, 1, 2, 4, 4))); 
    }
}







Ada: generic
   type Element_Type is private;
   type Element_Array is array (Positive range <>) of Element_Type;
package Mode is

   function Get_Mode (Set : Element_Array) return Element_Array;

end Mode;
Task: Averages_Mode







Python: >>> from collections import defaultdict
>>> def modes(values):
	count = defaultdict(int)
	for v in values:
		count[v] +=1
	best = max(count.values())
	return [k for k,v in count.items() if v == best]

>>> modes([1,3,6,6,6,6,7,7,12,12,17])
[6]
>>> modes((1,1,2,4,4))
[1, 4]





Ada: generic
   type Element_Type is private;
   type Element_Array is array (Positive range <>) of Element_Type;
package Mode is

   function Get_Mode (Set : Element_Array) return Element_Array;

end Mode;
Task: Averages_Mode








VB: Public Sub main()
    s = [{1,2,3,3,3,4,4,4,5,5,6}]
    t = WorksheetFunction.Mode_Mult(s)
    For Each x In t
        Debug.Print x;
    Next x
End Sub




Ada: generic
   type Element_Type is private;
   type Element_Array is array (Positive range <>) of Element_Type;
package Mode is

   function Get_Mode (Set : Element_Array) return Element_Array;

end Mode;
Task: Averages_Mode

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

typedef struct { double v; int c; } vcount;

int cmp_dbl(const void *a, const void *b)
{
	double x = *(const double*)a - *(const double*)b;
	return x < 0 ? -1 : x > 0;
}

int vc_cmp(const void *a, const void *b)
{
	return ((const vcount*)b)->c - ((const vcount*)a)->c;
}

int get_mode(double* x, int len, vcount **list)
{
	int i, j;
	vcount *vc;

	
	qsort(x, len, sizeof(double), cmp_dbl);

	
	for (i = 0, j = 1; i < len - 1; i++, j += (x[i] != x[i + 1]));

	*list = vc = malloc(sizeof(vcount) * j);
	vc[0].v = x[0];
	vc[0].c = 1;

	
	for (i = j = 0; i < len - 1; i++, vc[j].c++)
		if (x[i] != x[i + 1]) vc[++j].v = x[i + 1];

	
	qsort(vc, j + 1, sizeof(vcount), vc_cmp);

	
	for (i = 0; i <= j && vc[i].c == vc[0].c; i++);

	return i;
}

int main()
{
	double values[] = { 1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 12, 12, 17 };
#	define len sizeof(values)/sizeof(double)
	vcount *vc;

	int i, n_modes = get_mode(values, len, &vc);

	printf("got %d modes:\n", n_modes);
	for (i = 0; i < n_modes; i++)
		printf("\tvalue = %g, count = %d\n", vc[i].v, vc[i].c);

	free(vc);
	return 0;
}
Task: Averages_Mode



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

namespace Test
{
    class Program
    {
     
        static void Main(string[] args)
        {
            
            List<int> myList = new List<int>() { 1, 1, 2, 4, 4 }; 

            var query =     from numbers in myList 
                            group numbers by numbers 
                            into groupedNumbers
                            select new { Number = groupedNumbers.Key, Count = groupedNumbers.Count() }; 
            
            int max = query.Max(g => g.Count);
            IEnumerable<int> modes = query.Where(x => x.Count == max).Select(x => x.Number);
            foreach (var item in modes)
            {
                Console.WriteLine(item);
            }
            
            Console.ReadLine();
        }

             
       
    }
     
    
}
Task: Averages_Mode


C++: #include <iterator>
#include <utility>
#include <algorithm>
#include <list>
#include <iostream>


template<typename T> struct referring
{
  referring(T const& t): value(t) {}
  template<typename Iter>
   bool operator()(std::pair<Iter, int> const& p) const
  {
    return *p.first == value;
  }
  T const& value;
};









template<typename FwdIterator, typename OutIterator>
 void mode(FwdIterator first, FwdIterator last, OutIterator result)
{
  typedef typename std::iterator_traits<FwdIterator>::value_type value_type;
  typedef std::list<std::pair<FwdIterator, int> > count_type;
  typedef typename count_type::iterator count_iterator;

  
  count_type counts;

  while (first != last)
  {
    count_iterator element = std::find_if(counts.begin(), counts.end(),
                                          referring<value_type>(*first));
    if (element == counts.end())
      counts.push_back(std::make_pair(first, 1));
    else
      ++element->second;
    ++first;
  }

  
  int max = 0;
  for (count_iterator i = counts.begin(); i != counts.end(); ++i)
    if (i->second > max)
      max = i->second;

  
  for (count_iterator i = counts.begin(); i != counts.end(); ++i)
    if (i->second == max)
      *result++ = *i->first;
}


int main()
{
  int values[] = { 1, 2, 3, 1, 2, 4, 2, 5, 2, 3, 3, 1, 3, 6 };
  median(values, values + sizeof(values)/sizeof(int),
         std::ostream_iterator<int>(std::cout, " "));
  std::cout << std::endl;
  return 0;
}
Task: Averages_Mode





Java: import java.util.*;

public class Mode {
    public static <T> List<T> mode(List<? extends T> coll) {
        Map<T, Integer> seen = new HashMap<T, Integer>();
        int max = 0;
        List<T> maxElems = new ArrayList<T>();
        for (T value : coll) {
            if (seen.containsKey(value))
                seen.put(value, seen.get(value) + 1);
            else
                seen.put(value, 1);
            if (seen.get(value) > max) {
                max = seen.get(value);
                maxElems.clear();
                maxElems.add(value);
            } else if (seen.get(value) == max) {
                maxElems.add(value);
            }
        }
        return maxElems;
    }

    public static void main(String[] args) {
        System.out.println(mode(Arrays.asList(1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17))); 
        System.out.println(mode(Arrays.asList(1, 1, 2, 4, 4))); 
    }
}
Task: Averages_Mode







Python: >>> from collections import defaultdict
>>> def modes(values):
	count = defaultdict(int)
	for v in values:
		count[v] +=1
	best = max(count.values())
	return [k for k,v in count.items() if v == best]

>>> modes([1,3,6,6,6,6,7,7,12,12,17])
[6]
>>> modes((1,1,2,4,4))
[1, 4]
Task: Averages_Mode








VB: Public Sub main()
    s = [{1,2,3,3,3,4,4,4,5,5,6}]
    t = WorksheetFunction.Mode_Mult(s)
    For Each x In t
        Debug.Print x;
    Next x
End Sub
Task: Averages_Mode




Go: package main

import "fmt"

func main() {
    fmt.Println(mode([]int{2, 7, 1, 8, 2}))
    fmt.Println(mode([]int{2, 7, 1, 8, 2, 8}))
}

func mode(a []int) []int {
    m := make(map[int]int)
    for _, v := range a {
        m[v]++
    }
    var mode []int
    var n int
    for k, v := range m {
        switch {
        case v < n:
        case v > n:
            n = v
            mode = append(mode[:0], k)
        default:
            mode = append(mode, k)
        }
    }
    return mode
}
Task: Averages_Mode



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

namespace Test
{
    class Program
    {
     
        static void Main(string[] args)
        {
            
            List<int> myList = new List<int>() { 1, 1, 2, 4, 4 }; 

            var query =     from numbers in myList 
                            group numbers by numbers 
                            into groupedNumbers
                            select new { Number = groupedNumbers.Key, Count = groupedNumbers.Count() }; 
            
            int max = query.Max(g => g.Count);
            IEnumerable<int> modes = query.Where(x => x.Count == max).Select(x => x.Number);
            foreach (var item in modes)
            {
                Console.WriteLine(item);
            }
            
            Console.ReadLine();
        }

             
       
    }
     
    
}








Fortran: program mode_test
  use Qsort_Module only Qsort => sort
  implicit none

  integer, parameter    :: S = 10
  integer, dimension(S) :: a1 = (/ -1, 7, 7, 2, 2, 2, -1, 7, -3, -3 /)
  integer, dimension(S) :: a2 = (/  1, 1, 1, 1, 1, 0, 2, 2, 2, 2 /)
  integer, dimension(S) :: a3 = (/  0, 0, -1, -1, 9, 9, 3, 3, 7, 7 /)

  integer, dimension(S) :: o
  integer               :: l, trash

  print *, stat_mode(a1)

  trash = stat_mode(a1, o, l)
  print *, o(1:l)
  trash = stat_mode(a2, o, l)
  print *, o(1:l)
  trash = stat_mode(a3, o, l)
  print *, o(1:l)

contains

  
  
  
  
  
  
  integer function stat_mode(a, others, otherslen, ok)
    integer, dimension(:), intent(in) :: a
    logical, optional, intent(out)    :: ok
    integer, dimension(size(a,1)), optional, intent(out) :: others
    integer, optional, intent(out)    :: otherslen

    
    
    
    integer, dimension(size(a, 1)) :: ta, freq, idx
    integer                        :: rs, i, tm, ml, tf

    if ( present(ok) ) ok = .false.

    select case ( size(a, 1) )
    case (0)  
       return
    case (1)
       if ( present(ok) ) ok = .true.
       stat_mode = a(1)
       return
    case default
       if ( present(ok) ) ok = .true.
       ta = a         
       call sort(ta)  
       freq = 1
       idx = 0
       rs = 1         
       
       do i = 2, size(ta, 1)
          if ( ta(i-1) == ta(i) ) then
             freq(rs) = freq(rs) + 1
          else
             idx(rs) = i-1
             rs = rs + 1
          end if
       end do
       idx(rs) = i-1
         
       ml = maxloc(freq(1:rs), 1)  
       tf = freq(ml)               
       tm = ta(idx(ml))            

       
       if ( present(others) ) then
          i = 1
          others(1) = tm
          do
             freq(ml) = 0
             ml = maxloc(freq(1:rs), 1)
             if ( tf == freq(ml) ) then 
                i = i + 1               
                others(i) = ta(idx(ml))
             else
                exit
             end if
          end do
                
          if ( present(otherslen) ) then
             otherslen = i
          end if

       end if
       stat_mode = tm
    end select

  end function stat_mode

end program mode_test
Task: Averages_Mode





Java: import java.util.*;

public class Mode {
    public static <T> List<T> mode(List<? extends T> coll) {
        Map<T, Integer> seen = new HashMap<T, Integer>();
        int max = 0;
        List<T> maxElems = new ArrayList<T>();
        for (T value : coll) {
            if (seen.containsKey(value))
                seen.put(value, seen.get(value) + 1);
            else
                seen.put(value, 1);
            if (seen.get(value) > max) {
                max = seen.get(value);
                maxElems.clear();
                maxElems.add(value);
            } else if (seen.get(value) == max) {
                maxElems.add(value);
            }
        }
        return maxElems;
    }

    public static void main(String[] args) {
        System.out.println(mode(Arrays.asList(1, 3, 6, 6, 6, 6, 7, 7, 12, 12, 17))); 
        System.out.println(mode(Arrays.asList(1, 1, 2, 4, 4))); 
    }
}






Fortran: program mode_test
  use Qsort_Module only Qsort => sort
  implicit none

  integer, parameter    :: S = 10
  integer, dimension(S) :: a1 = (/ -1, 7, 7, 2, 2, 2, -1, 7, -3, -3 /)
  integer, dimension(S) :: a2 = (/  1, 1, 1, 1, 1, 0, 2, 2, 2, 2 /)
  integer, dimension(S) :: a3 = (/  0, 0, -1, -1, 9, 9, 3, 3, 7, 7 /)

  integer, dimension(S) :: o
  integer               :: l, trash

  print *, stat_mode(a1)

  trash = stat_mode(a1, o, l)
  print *, o(1:l)
  trash = stat_mode(a2, o, l)
  print *, o(1:l)
  trash = stat_mode(a3, o, l)
  print *, o(1:l)

contains

  
  
  
  
  
  
  integer function stat_mode(a, others, otherslen, ok)
    integer, dimension(:), intent(in) :: a
    logical, optional, intent(out)    :: ok
    integer, dimension(size(a,1)), optional, intent(out) :: others
    integer, optional, intent(out)    :: otherslen

    
    
    
    integer, dimension(size(a, 1)) :: ta, freq, idx
    integer                        :: rs, i, tm, ml, tf

    if ( present(ok) ) ok = .false.

    select case ( size(a, 1) )
    case (0)  
       return
    case (1)
       if ( present(ok) ) ok = .true.
       stat_mode = a(1)
       return
    case default
       if ( present(ok) ) ok = .true.
       ta = a         
       call sort(ta)  
       freq = 1
       idx = 0
       rs = 1         
       
       do i = 2, size(ta, 1)
          if ( ta(i-1) == ta(i) ) then
             freq(rs) = freq(rs) + 1
          else
             idx(rs) = i-1
             rs = rs + 1
          end if
       end do
       idx(rs) = i-1
         
       ml = maxloc(freq(1:rs), 1)  
       tf = freq(ml)               
       tm = ta(idx(ml))            

       
       if ( present(others) ) then
          i = 1
          others(1) = tm
          do
             freq(ml) = 0
             ml = maxloc(freq(1:rs), 1)
             if ( tf == freq(ml) ) then 
                i = i + 1               
                others(i) = ta(idx(ml))
             else
                exit
             end if
          end do
                
          if ( present(otherslen) ) then
             otherslen = i
          end if

       end if
       stat_mode = tm
    end select

  end function stat_mode

end program mode_test
Task: Averages_Mode







Python: >>> from collections import defaultdict
>>> def modes(values):
	count = defaultdict(int)
	for v in values:
		count[v] +=1
	best = max(count.values())
	return [k for k,v in count.items() if v == best]

>>> modes([1,3,6,6,6,6,7,7,12,12,17])
[6]
>>> modes((1,1,2,4,4))
[1, 4]




Fortran: program mode_test
  use Qsort_Module only Qsort => sort
  implicit none

  integer, parameter    :: S = 10
  integer, dimension(S) :: a1 = (/ -1, 7, 7, 2, 2, 2, -1, 7, -3, -3 /)
  integer, dimension(S) :: a2 = (/  1, 1, 1, 1, 1, 0, 2, 2, 2, 2 /)
  integer, dimension(S) :: a3 = (/  0, 0, -1, -1, 9, 9, 3, 3, 7, 7 /)

  integer, dimension(S) :: o
  integer               :: l, trash

  print *, stat_mode(a1)

  trash = stat_mode(a1, o, l)
  print *, o(1:l)
  trash = stat_mode(a2, o, l)
  print *, o(1:l)
  trash = stat_mode(a3, o, l)
  print *, o(1:l)

contains

  
  
  
  
  
  
  integer function stat_mode(a, others, otherslen, ok)
    integer, dimension(:), intent(in) :: a
    logical, optional, intent(out)    :: ok
    integer, dimension(size(a,1)), optional, intent(out) :: others
    integer, optional, intent(out)    :: otherslen

    
    
    
    integer, dimension(size(a, 1)) :: ta, freq, idx
    integer                        :: rs, i, tm, ml, tf

    if ( present(ok) ) ok = .false.

    select case ( size(a, 1) )
    case (0)  
       return
    case (1)
       if ( present(ok) ) ok = .true.
       stat_mode = a(1)
       return
    case default
       if ( present(ok) ) ok = .true.
       ta = a         
       call sort(ta)  
       freq = 1
       idx = 0
       rs = 1         
       
       do i = 2, size(ta, 1)
          if ( ta(i-1) == ta(i) ) then
             freq(rs) = freq(rs) + 1
          else
             idx(rs) = i-1
             rs = rs + 1
          end if
       end do
       idx(rs) = i-1
         
       ml = maxloc(freq(1:rs), 1)  
       tf = freq(ml)               
       tm = ta(idx(ml))            

       
       if ( present(others) ) then
          i = 1
          others(1) = tm
          do
             freq(ml) = 0
             ml = maxloc(freq(1:rs), 1)
             if ( tf == freq(ml) ) then 
                i = i + 1               
                others(i) = ta(idx(ml))
             else
                exit
             end if
          end do
                
          if ( present(otherslen) ) then
             otherslen = i
          end if

       end if
       stat_mode = tm
    end select

  end function stat_mode

end program mode_test