WeixiangYan/CodeTransOcean huggingface dataset:
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
Task: Doubly-linked list_Element definition








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
}
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;
    }
}








Fortran: type node
   real :: data
   type(node), pointer :: next => null(), previous => null()
end type node



type( node ), target :: head
Task: Doubly-linked list_Element definition


C++: template <typename T>
struct Node
{
    Node* next;
    Node* prev;
    T data;
};









Fortran: type node
   real :: data
   type(node), pointer :: next => null(), previous => null()
end type node



type( node ), target :: head
Task: Doubly-linked list_Element definition

C: struct Node 
{
  struct Node *next;
  struct Node *prev;
  void  *data;
};










Fortran: type node
   real :: data
   type(node), pointer :: next => null(), previous => null()
end type node



type( node ), target :: head
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;
   }
}






Fortran: type node
   real :: data
   type(node), pointer :: next => null(), previous => null()
end type node



type( node ), target :: head
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




Fortran: type node
   real :: data
   type(node), pointer :: next => null(), previous => null()
end type node



type( node ), target :: head
Task: Doubly-linked list_Element definition








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



Fortran: type node
   real :: data
   type(node), pointer :: next => null(), previous => null()
end type node



type( node ), target :: head
Task: Dot product



C#: static void Main(string[] args)
{
	Console.WriteLine(DotProduct(new decimal[] { 1, 3, -5 }, new decimal[] { 4, -2, -1 }));
	Console.Read();
}

private static decimal DotProduct(decimal[] vec1, decimal[] vec2) 
{
	if (vec1 == null)
		return 0;

	if (vec2 == null)
		return 0;

	if (vec1.Length != vec2.Length)
		return 0;

	decimal tVal = 0;
	for (int x = 0; x < vec1.Length; x++)
	{
		tVal += vec1[x] * vec2[x];
	}

	return tVal;
}









Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Dot product

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

int dot_product(int *, int *, size_t);

int
main(void)
{
        int a[3] = {1, 3, -5};
        int b[3] = {4, -2, -1};

        printf("%d\n", dot_product(a, b, sizeof(a) / sizeof(a[0])));

        return EXIT_SUCCESS;
}

int
dot_product(int *a, int *b, size_t n)
{
        int sum = 0;
        size_t i;

        for (i = 0; i < n; i++) {
                sum += a[i] * b[i];
        }

        return sum;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Dot product


C++: #include <iostream>
#include <numeric>

int main()
{
    int a[] = { 1, 3, -5 };
    int b[] = { 4, -2, -1 };

    std::cout << std::inner_product(a, a + sizeof(a) / sizeof(a[0]), b, 0) << std::endl;

    return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Dot product




Go: package main

import (
    "errors"
    "fmt"
    "log"
)

var (
    v1 = []int{1, 3, -5}
    v2 = []int{4, -2, -1}
)

func dot(x, y []int) (r int, err error) {
    if len(x) != len(y) {
        return 0, errors.New("incompatible lengths")
    }
    for i, xi := range x {
        r += xi * y[i]
    }
    return
}

func main() {
    d, err := dot([]int{1, 3, -5}, []int{4, -2, -1})
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(d)
}








Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Dot product





Java: public class DotProduct {
	
	public static void main(String[] args) {
		double[] a = {1, 3, -5};
		double[] b = {4, -2, -1};
		
		System.out.println(dotProd(a,b));
	}
	
	public static double dotProd(double[] a, double[] b){
		if(a.length != b.length){
			throw new IllegalArgumentException("The dimensions have to be equal!");
		}
		double sum = 0;
		for(int i = 0; i < a.length; i++){
			sum += a[i] * b[i];
		}
		return sum;
	}
}







Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Dot product







Python: def dotp(a,b):
    assert len(a) == len(b), 'Vector sizes must match'
    return sum(aterm * bterm for aterm,bterm in zip(a, b))

if __name__ == '__main__':
    a, b = [1, 3, -5], [4, -2, -1]
    assert dotp(a,b) == 3





Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Dot product








VB: Private Function dot_product(x As Variant, y As Variant) As Double
    dot_product = WorksheetFunction.SumProduct(x, y)
End Function

Public Sub main()
    Debug.Print dot_product([{1,3,-5}], [{4,-2,-1}])
End Sub




Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Dot product

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

int dot_product(int *, int *, size_t);

int
main(void)
{
        int a[3] = {1, 3, -5};
        int b[3] = {4, -2, -1};

        printf("%d\n", dot_product(a, b, sizeof(a) / sizeof(a[0])));

        return EXIT_SUCCESS;
}

int
dot_product(int *a, int *b, size_t n)
{
        int sum = 0;
        size_t i;

        for (i = 0; i < n; i++) {
                sum += a[i] * b[i];
        }

        return sum;
}
Task: Dot product



C#: static void Main(string[] args)
{
	Console.WriteLine(DotProduct(new decimal[] { 1, 3, -5 }, new decimal[] { 4, -2, -1 }));
	Console.Read();
}

private static decimal DotProduct(decimal[] vec1, decimal[] vec2) 
{
	if (vec1 == null)
		return 0;

	if (vec2 == null)
		return 0;

	if (vec1.Length != vec2.Length)
		return 0;

	decimal tVal = 0;
	for (int x = 0; x < vec1.Length; x++)
	{
		tVal += vec1[x] * vec2[x];
	}

	return tVal;
}
Task: Dot product


C++: #include <iostream>
#include <numeric>

int main()
{
    int a[] = { 1, 3, -5 };
    int b[] = { 4, -2, -1 };

    std::cout << std::inner_product(a, a + sizeof(a) / sizeof(a[0]), b, 0) << std::endl;

    return 0;
}
Task: Dot product





Java: public class DotProduct {
	
	public static void main(String[] args) {
		double[] a = {1, 3, -5};
		double[] b = {4, -2, -1};
		
		System.out.println(dotProd(a,b));
	}
	
	public static double dotProd(double[] a, double[] b){
		if(a.length != b.length){
			throw new IllegalArgumentException("The dimensions have to be equal!");
		}
		double sum = 0;
		for(int i = 0; i < a.length; i++){
			sum += a[i] * b[i];
		}
		return sum;
	}
}
Task: Dot product







Python: def dotp(a,b):
    assert len(a) == len(b), 'Vector sizes must match'
    return sum(aterm * bterm for aterm,bterm in zip(a, b))

if __name__ == '__main__':
    a, b = [1, 3, -5], [4, -2, -1]
    assert dotp(a,b) == 3
Task: Dot product








VB: Private Function dot_product(x As Variant, y As Variant) As Double
    dot_product = WorksheetFunction.SumProduct(x, y)
End Function

Public Sub main()
    Debug.Print dot_product([{1,3,-5}], [{4,-2,-1}])
End Sub
Task: Dot product




Go: package main

import (
    "errors"
    "fmt"
    "log"
)

var (
    v1 = []int{1, 3, -5}
    v2 = []int{4, -2, -1}
)

func dot(x, y []int) (r int, err error) {
    if len(x) != len(y) {
        return 0, errors.New("incompatible lengths")
    }
    for i, xi := range x {
        r += xi * y[i]
    }
    return
}

func main() {
    d, err := dot([]int{1, 3, -5}, []int{4, -2, -1})
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(d)
}
Task: Dot product



C#: static void Main(string[] args)
{
	Console.WriteLine(DotProduct(new decimal[] { 1, 3, -5 }, new decimal[] { 4, -2, -1 }));
	Console.Read();
}

private static decimal DotProduct(decimal[] vec1, decimal[] vec2) 
{
	if (vec1 == null)
		return 0;

	if (vec2 == null)
		return 0;

	if (vec1.Length != vec2.Length)
		return 0;

	decimal tVal = 0;
	for (int x = 0; x < vec1.Length; x++)
	{
		tVal += vec1[x] * vec2[x];
	}

	return tVal;
}








Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product


C++: #include <iostream>
#include <numeric>

int main()
{
    int a[] = { 1, 3, -5 };
    int b[] = { 4, -2, -1 };

    std::cout << std::inner_product(a, a + sizeof(a) / sizeof(a[0]), b, 0) << std::endl;

    return 0;
}









Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product

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

int dot_product(int *, int *, size_t);

int
main(void)
{
        int a[3] = {1, 3, -5};
        int b[3] = {4, -2, -1};

        printf("%d\n", dot_product(a, b, sizeof(a) / sizeof(a[0])));

        return EXIT_SUCCESS;
}

int
dot_product(int *a, int *b, size_t n)
{
        int sum = 0;
        size_t i;

        for (i = 0; i < n; i++) {
                sum += a[i] * b[i];
        }

        return sum;
}










Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product




Go: package main

import (
    "errors"
    "fmt"
    "log"
)

var (
    v1 = []int{1, 3, -5}
    v2 = []int{4, -2, -1}
)

func dot(x, y []int) (r int, err error) {
    if len(x) != len(y) {
        return 0, errors.New("incompatible lengths")
    }
    for i, xi := range x {
        r += xi * y[i]
    }
    return
}

func main() {
    d, err := dot([]int{1, 3, -5}, []int{4, -2, -1})
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println(d)
}







Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product





Java: public class DotProduct {
	
	public static void main(String[] args) {
		double[] a = {1, 3, -5};
		double[] b = {4, -2, -1};
		
		System.out.println(dotProd(a,b));
	}
	
	public static double dotProd(double[] a, double[] b){
		if(a.length != b.length){
			throw new IllegalArgumentException("The dimensions have to be equal!");
		}
		double sum = 0;
		for(int i = 0; i < a.length; i++){
			sum += a[i] * b[i];
		}
		return sum;
	}
}






Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product







Python: def dotp(a,b):
    assert len(a) == len(b), 'Vector sizes must match'
    return sum(aterm * bterm for aterm,bterm in zip(a, b))

if __name__ == '__main__':
    a, b = [1, 3, -5], [4, -2, -1]
    assert dotp(a,b) == 3




Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product








VB: Private Function dot_product(x As Variant, y As Variant) As Double
    dot_product = WorksheetFunction.SumProduct(x, y)
End Function

Public Sub main()
    Debug.Print dot_product([{1,3,-5}], [{4,-2,-1}])
End Sub



Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product






PHP: <?php
function dot_product($v1, $v2) {
  if (count($v1) != count($v2))
    throw new Exception('Arrays have different lengths');
  return array_sum(array_map('bcmul', $v1, $v2));
}

echo dot_product(array(1, 3, -5), array(4, -2, -1)), "\n";
?>





Fortran: program test_dot_product

  write (*, '(i0)') dot_product ([1, 3, -5], [4, -2, -1])

end program test_dot_product
Task: Dot product






PHP: <?php
function dot_product($v1, $v2) {
  if (count($v1) != count($v2))
    throw new Exception('Arrays have different lengths');
  return array_sum(array_map('bcmul', $v1, $v2));
}

echo dot_product(array(1, 3, -5), array(4, -2, -1)), "\n";
?>
Task: Dot product






PHP: <?php
function dot_product($v1, $v2) {
  if (count($v1) != count($v2))
    throw new Exception('Arrays have different lengths');
  return array_sum(array_map('bcmul', $v1, $v2));
}

echo dot_product(array(1, 3, -5), array(4, -2, -1)), "\n";
?>






Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure dot_product is
	type vect is array(Positive range <>) of Integer;
	v1 : vect := (1,3,-5);
	v2 : vect := (4,-2,-1);

	function dotprod(a: vect; b: vect) return Integer is
		sum : Integer := 0;
		begin
		if not (a'Length=b'Length) then raise Constraint_Error; end if;
		for p in a'Range loop
			sum := sum + a(p)*b(p);
		end loop;
		return sum;
	end dotprod;
	
begin
put_line(Integer'Image(dotprod(v1,v2)));
end dot_product;
Task: Count in factors



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

namespace prog
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			for( int i=1; i<=22; i++ )
			{				
				List<int> f = Factorize(i);
				Console.Write( i + ":  " + f[0] );
				for( int j=1; j<f.Count; j++ )
				{
					Console.Write( " * " + f[j] );
				}
				Console.WriteLine();
			}
		}
		
		public static List<int> Factorize( int n )
		{
			List<int> l = new List<int>();
		    
			if ( n == 1 )
			{
				l.Add(1);
			}
			else
			{
				int k = 2;
				while( n > 1 ) 
				{
					while( n % k == 0 )
					{
						l.Add( k );
						n /= k;
					}
					k++;
				}
			}			
			return l;
		}	
	}
}









Ada: with Ada.Command_Line, Ada.Text_IO, Prime_Numbers;
 
procedure Count is
   package Prime_Nums is new Prime_Numbers
     (Number => Natural, Zero => 0, One => 1, Two => 2); use Prime_Nums;
 
   procedure Put (List : Number_List) is
   begin
      for Index in List'Range loop
         Ada.Text_IO.Put (Integer'Image (List (Index)));
         if Index /= List'Last then
            Ada.Text_IO.Put (" x");
         end if;
      end loop;
   end Put;
 
   N     : Natural := 1;
   Max_N : Natural := 15; 
begin
   if Ada.Command_Line.Argument_Count = 1 then 
      Max_N := Integer'Value (Ada.Command_Line.Argument (1));
   end if; 
   loop
      Ada.Text_IO.Put (Integer'Image (N) & ": ");
      Put (Decompose (N));
      Ada.Text_IO.New_Line;
      N := N + 1;
      exit when N > Max_N;
   end loop;
end Count;
Task: Count in factors

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

typedef unsigned long long ULONG;

ULONG get_prime(int idx)
{
        static long n_primes = 0, alloc = 0;
        static ULONG *primes = 0;
        ULONG last, p;
        int i;

        if (idx >= n_primes) {
                if (n_primes >= alloc) {
                        alloc += 16; 
                        primes = realloc(primes, sizeof(ULONG) * alloc);
                }
                if (!n_primes) {
                        primes[0] = 2;
                        primes[1] = 3;
                        n_primes = 2;
                }

                last = primes[n_primes-1];
                while (idx >= n_primes) {
                        last += 2;
                        for (i = 0; i < n_primes; i++) {
                                p = primes[i];
                                if (p * p > last) {
                                        primes[n_primes++] = last;
                                        break;
                                }
                                if (last % p == 0) break;
                        }
                }
        }
        return primes[idx];
}

int main()
{
        ULONG n, x, p;
        int i, first;

        for (x = 1; ; x++) {
                printf("%lld = ", n = x);

                for (i = 0, first = 1; ; i++) {
                        p = get_prime(i);
                        while (n % p == 0) {
                                n /= p;
                                if (!first) printf(" x ");
                                first = 0;
                                printf("%lld", p);
                        }
                        if (n <= p * p) break;
                }

                if (first)      printf("%lld\n", n);
                else if (n > 1) printf(" x %lld\n", n);
                else            printf("\n");
        }
        return 0;
}











Ada: with Ada.Command_Line, Ada.Text_IO, Prime_Numbers;
 
procedure Count is
   package Prime_Nums is new Prime_Numbers
     (Number => Natural, Zero => 0, One => 1, Two => 2); use Prime_Nums;
 
   procedure Put (List : Number_List) is
   begin
      for Index in List'Range loop
         Ada.Text_IO.Put (Integer'Image (List (Index)));
         if Index /= List'Last then
            Ada.Text_IO.Put (" x");
         end if;
      end loop;
   end Put;
 
   N     : Natural := 1;
   Max_N : Natural := 15; 
begin
   if Ada.Command_Line.Argument_Count = 1 then 
      Max_N := Integer'Value (Ada.Command_Line.Argument (1));
   end if; 
   loop
      Ada.Text_IO.Put (Integer'Image (N) & ": ");
      Put (Decompose (N));
      Ada.Text_IO.New_Line;
      N := N + 1;
      exit when N > Max_N;
   end loop;
end Count;
Task: Count in factors


C++: #include <iostream>
#include <iomanip>
using namespace std;

void getPrimeFactors( int li )
{
    int f = 2; string res;
    if ( li == 1 ) res = "1";
    else
    {
	while ( true )
	{
	    if( !( li % f ) ) 
	    {
		res += to_string(f);
		li /= f; if( li == 1 ) break;
		res += " x ";
	    }
	    else f++;
	}
    }
    cout << res << "\n";
}

int main( int argc, char* argv[] )
{
    for ( int x = 1; x < 101; x++ )
    {
	cout << right << setw( 4 ) << x << ": "; 
	getPrimeFactors( x );
    }
    cout << 2144 << ": "; getPrimeFactors( 2144 );
    cout << "\n\n";
    return system( "pause" );
}










Ada: with Ada.Command_Line, Ada.Text_IO, Prime_Numbers;
 
procedure Count is
   package Prime_Nums is new Prime_Numbers
     (Number => Natural, Zero => 0, One => 1, Two => 2); use Prime_Nums;
 
   procedure Put (List : Number_List) is
   begin
      for Index in List'Range loop
         Ada.Text_IO.Put (Integer'Image (List (Index)));
         if Index /= List'Last then
            Ada.Text_IO.Put (" x");
         end if;
      end loop;
   end Put;
 
   N     : Natural := 1;
   Max_N : Natural := 15; 
begin
   if Ada.Command_Line.Argument_Count = 1 then 
      Max_N := Integer'Value (Ada.Command_Line.Argument (1));
   end if; 
   loop
      Ada.Text_IO.Put (Integer'Image (N) & ": ");
      Put (Decompose (N));
      Ada.Text_IO.New_Line;
      N := N + 1;
      exit when N > Max_N;
   end loop;
end Count;
Task: Count in factors




Go: package main

import "fmt"

func main() {
    fmt.Println("1: 1")
    for i := 2; ; i++ {
        fmt.Printf("%d: ", i)
        var x string
        for n, f := i, 2; n != 1; f++ {
            for m := n % f; m == 0; m = n % f {
                fmt.Print(x, f)
                x = "×"
                n /= f
            }
        }
        fmt.Println()
    }
}








Ada: with Ada.Command_Line, Ada.Text_IO, Prime_Numbers;
 
procedure Count is
   package Prime_Nums is new Prime_Numbers
     (Number => Natural, Zero => 0, One => 1, Two => 2); use Prime_Nums;
 
   procedure Put (List : Number_List) is
   begin
      for Index in List'Range loop
         Ada.Text_IO.Put (Integer'Image (List (Index)));
         if Index /= List'Last then
            Ada.Text_IO.Put (" x");
         end if;
      end loop;
   end Put;
 
   N     : Natural := 1;
   Max_N : Natural := 15; 
begin
   if Ada.Command_Line.Argument_Count = 1 then 
      Max_N := Integer'Value (Ada.Command_Line.Argument (1));
   end if; 
   loop
      Ada.Text_IO.Put (Integer'Image (N) & ": ");
      Put (Decompose (N));
      Ada.Text_IO.New_Line;
      N := N + 1;
      exit when N > Max_N;
   end loop;
end Count;