WeixiangYan/CodeTransOcean huggingface dataset:
Task: Isqrt (integer square root) of X







Python: def isqrt ( x ):
    q = 1
    while q <= x : 
        q *= 4
    z,r = x,0
    while q > 1 :
        q  /= 4
        t,r = z-r-q,r/2
        if t >= 0 :
            z,r = t,r+q
    return r 

print ' '.join( '%d'%isqrt( n ) for n in xrange( 66 ))
print '\n'.join( '{0:114,} = isqrt( 7^{1:3} )'.format( isqrt( 7**n ),n ) for n in range( 1,204,2 ))




Fortran: MODULE INTEGER_SQUARE_ROOT
    IMPLICIT NONE

    CONTAINS
        
    
    FUNCTION COMMATIZE(NUM) RESULT(OUT_STR)
         INTEGER(16), INTENT(IN) :: NUM
         INTEGER(16) I 
         CHARACTER(83) :: TEMP, OUT_STR
         
         WRITE(TEMP, '(I0)') NUM

         OUT_STR = ""

         DO I=0, LEN_TRIM(TEMP)-1
             IF (MOD(I, 3) .EQ. 0 .AND. I .GT. 0 .AND. I .LT. LEN_TRIM(TEMP)) THEN
                  OUT_STR = "," // TRIM(OUT_STR)
             END IF
             OUT_STR = TEMP(LEN_TRIM(TEMP)-I:LEN_TRIM(TEMP)-I) // TRIM(OUT_STR)
         END DO
    END FUNCTION COMMATIZE


    
    FUNCTION ISQRT(NUM)
        INTEGER(16), INTENT(IN) :: NUM
        INTEGER(16) :: ISQRT
        INTEGER(16) :: Q, Z, R, T
    
        Q = 1
        Z = NUM
        R = 0
        T = 0
    
        DO WHILE (Q .LT. NUM)
            Q = Q * 4
        END DO
    
        DO WHILE (Q .GT. 1)
            Q = Q / 4
            T = Z - R - Q
            R = R / 2
            
            IF (T .GE. 0) THEN
                Z = T
                R = R + Q
            END IF
        END DO
    
        ISQRT = R
    END FUNCTION ISQRT

END MODULE INTEGER_SQUARE_ROOT




PROGRAM ISQRT_DEMO
    USE INTEGER_SQUARE_ROOT
    IMPLICIT NONE


    INTEGER(16), PARAMETER :: MIN_NUM_HZ = 0
    INTEGER(16), PARAMETER :: MAX_NUM_HZ = 65
    INTEGER(16), PARAMETER :: POWER_BASE = 7
    INTEGER(16), PARAMETER :: POWER_MIN = 1
    INTEGER(16), PARAMETER :: POWER_MAX = 73
    INTEGER(16), DIMENSION(MAX_NUM_HZ-MIN_NUM_HZ+1) :: VALUES
    CHARACTER(2) :: HEADER_1
    CHARACTER(83) :: HEADER_2
    CHARACTER(83) :: HEADER_3

    INTEGER(16) :: I

    HEADER_1 = " n"
    HEADER_2 = "7^n"
    HEADER_3 = "isqrt(7^n)"

    WRITE(*,'(A, I0, A, I0)') "Integer square root for numbers ", MIN_NUM_HZ, " to ", MAX_NUM_HZ

    DO I=1, SIZE(VALUES)
        VALUES(I) = ISQRT(MIN_NUM_HZ+I)
    END DO

    WRITE(*,'(100I2)') VALUES
    WRITE(*,*) NEW_LINE('A')
    
    WRITE(*,'(A,A,A,A,A)') HEADER_1, " | ", HEADER_2, " | ", HEADER_3
    WRITE(*,*) REPEAT("-", 8+83*2)

    DO I=POWER_MIN,POWER_MAX, 2
        WRITE(*,'(I2, A, A, A, A)') I, " | " // COMMATIZE(7**I), " | ", COMMATIZE(ISQRT(7**I))
    END DO
        

 END PROGRAM ISQRT_DEMO
Task: Isqrt (integer square root) of X

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

int64_t isqrt(int64_t x) {
    int64_t q = 1, r = 0;
    while (q <= x) {
        q <<= 2;
    }
    while (q > 1) {
        int64_t t;
        q >>= 2;
        t = x - r - q;
        r >>= 1;
        if (t >= 0) {
            x = t;
            r += q;
        }
    }
    return r;
}

int main() {
    int64_t p;
    int n;

    printf("Integer square root for numbers 0 to 65:\n");
    for (n = 0; n <= 65; n++) {
        printf("%lld ", isqrt(n));
    }
    printf("\n\n");

    printf("Integer square roots of odd powers of 7 from 1 to 21:\n");
    printf(" n |              7 ^ n | isqrt(7 ^ n)\n");
    p = 7;
    for (n = 1; n <= 21; n += 2, p *= 49) {
        printf("%2d | %18lld | %12lld\n", n, p, isqrt(p));
    }
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. I-SQRT.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 QUAD-RET-VARS.
          03 X          PIC 9(18).
          03 Q          PIC 9(18).
          03 Z          PIC 9(18).
          03 T          PIC S9(18).
          03 R          PIC 9(18).

       01 TO-65-VARS.
          03 ISQRT-N    PIC 99.
          03 DISP-LN    PIC X(22) VALUE SPACES.
          03 DISP-FMT   PIC Z9.
          03 PTR        PIC 99 VALUE 1.

       01 BIG-SQRT-VARS.
          03 POW-7      PIC 9(18) VALUE 7.
          03 POW-N      PIC 99 VALUE 1.
          03 POW-N-OUT  PIC Z9.
          03 POW-7-OUT  PIC Z(10).

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SQRTS-TO-65.
           PERFORM BIG-SQRTS.
           STOP RUN.

       SQRTS-TO-65.
           PERFORM DISP-SMALL-SQRT
           VARYING ISQRT-N FROM 0 BY 1
           UNTIL ISQRT-N IS GREATER THAN 65.

       DISP-SMALL-SQRT.
           MOVE ISQRT-N TO X.
           PERFORM ISQRT.
           MOVE R TO DISP-FMT.
           STRING DISP-FMT DELIMITED BY SIZE INTO DISP-LN 
           WITH POINTER PTR.
           IF PTR IS GREATER THAN 22, 
               DISPLAY DISP-LN, 
               MOVE 1 TO PTR.

       BIG-SQRTS.
           PERFORM BIG-SQRT 10 TIMES.
 
       BIG-SQRT.
           MOVE POW-7 TO X.
           PERFORM ISQRT.
           MOVE POW-N TO POW-N-OUT. 
           MOVE R TO POW-7-OUT. 
           DISPLAY "ISQRT(7^" POW-N-OUT ") = " POW-7-OUT.
           ADD 2 TO POW-N.
           MULTIPLY 49 BY POW-7.

       ISQRT.
           MOVE 1 TO Q.
           PERFORM MUL-Q-BY-4 UNTIL Q IS GREATER THAN X.
           MOVE X TO Z.
           MOVE ZERO TO R.
           PERFORM ISQRT-STEP UNTIL Q IS NOT GREATER THAN 1. 

       MUL-Q-BY-4.
           MULTIPLY 4 BY Q.

       ISQRT-STEP.
           DIVIDE 4 INTO Q.
           COMPUTE T = Z - R - Q.
           DIVIDE 2 INTO R.
           IF T IS NOT LESS THAN ZERO,
               MOVE T TO Z,
               ADD Q TO R.
Task: Isqrt (integer square root) of X







Python: def isqrt ( x ):
    q = 1
    while q <= x : 
        q *= 4
    z,r = x,0
    while q > 1 :
        q  /= 4
        t,r = z-r-q,r/2
        if t >= 0 :
            z,r = t,r+q
    return r 

print ' '.join( '%d'%isqrt( n ) for n in xrange( 66 ))
print '\n'.join( '{0:114,} = isqrt( 7^{1:3} )'.format( isqrt( 7**n ),n ) for n in range( 1,204,2 ))



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. I-SQRT.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 QUAD-RET-VARS.
          03 X          PIC 9(18).
          03 Q          PIC 9(18).
          03 Z          PIC 9(18).
          03 T          PIC S9(18).
          03 R          PIC 9(18).

       01 TO-65-VARS.
          03 ISQRT-N    PIC 99.
          03 DISP-LN    PIC X(22) VALUE SPACES.
          03 DISP-FMT   PIC Z9.
          03 PTR        PIC 99 VALUE 1.

       01 BIG-SQRT-VARS.
          03 POW-7      PIC 9(18) VALUE 7.
          03 POW-N      PIC 99 VALUE 1.
          03 POW-N-OUT  PIC Z9.
          03 POW-7-OUT  PIC Z(10).

       PROCEDURE DIVISION.
       BEGIN.
           PERFORM SQRTS-TO-65.
           PERFORM BIG-SQRTS.
           STOP RUN.

       SQRTS-TO-65.
           PERFORM DISP-SMALL-SQRT
           VARYING ISQRT-N FROM 0 BY 1
           UNTIL ISQRT-N IS GREATER THAN 65.

       DISP-SMALL-SQRT.
           MOVE ISQRT-N TO X.
           PERFORM ISQRT.
           MOVE R TO DISP-FMT.
           STRING DISP-FMT DELIMITED BY SIZE INTO DISP-LN 
           WITH POINTER PTR.
           IF PTR IS GREATER THAN 22, 
               DISPLAY DISP-LN, 
               MOVE 1 TO PTR.

       BIG-SQRTS.
           PERFORM BIG-SQRT 10 TIMES.
 
       BIG-SQRT.
           MOVE POW-7 TO X.
           PERFORM ISQRT.
           MOVE POW-N TO POW-N-OUT. 
           MOVE R TO POW-7-OUT. 
           DISPLAY "ISQRT(7^" POW-N-OUT ") = " POW-7-OUT.
           ADD 2 TO POW-N.
           MULTIPLY 49 BY POW-7.

       ISQRT.
           MOVE 1 TO Q.
           PERFORM MUL-Q-BY-4 UNTIL Q IS GREATER THAN X.
           MOVE X TO Z.
           MOVE ZERO TO R.
           PERFORM ISQRT-STEP UNTIL Q IS NOT GREATER THAN 1. 

       MUL-Q-BY-4.
           MULTIPLY 4 BY Q.

       ISQRT-STEP.
           DIVIDE 4 INTO Q.
           COMPUTE T = Z - R - Q.
           DIVIDE 2 INTO R.
           IF T IS NOT LESS THAN ZERO,
               MOVE T TO Z,
               ADD Q TO R.
Task: Jewels and stones



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(Count("aAAbbbb", "Aa"));
        Console.WriteLine(Count("ZZ", "z"));
    }

    private static int Count(string stones, string jewels) {
        var bag = jewels.ToHashSet();
        return stones.Count(bag.Contains);
    }
}









Ada: with Ada.Text_IO;

procedure Jewels_And_Stones is

   function Count (Jewels, Stones : in String) return Natural is
      Sum : Natural := 0;
   begin
      for J of Jewels loop
         for S of Stones loop
            if J = S then
               Sum := Sum + 1;
               exit;
            end if;
         end loop;
      end loop;
      return Sum;
   end Count;

   procedure Show (Jewels, Stones : in String) is
      use Ada.Text_IO;
   begin
      Put (Jewels);
      Set_Col (12); Put (Stones);
      Set_Col (20); Put (Count (Jewels => Jewels,
                                Stones => Stones)'Image);
      New_Line;
   end Show;

begin
   Show ("aAAbbbb", "aA");
   Show ("ZZ",      "z");
end Jewels_And_Stones;
Task: Jewels and stones

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

int count_jewels(const char *s, const char *j) {
    int count = 0;
    for ( ; *s; ++s) if (strchr(j, *s)) ++count;
    return count;
}

int main() {
    printf("%d\n", count_jewels("aAAbbbb", "aA"));
    printf("%d\n", count_jewels("ZZ", "z"));
    return 0;
}











Ada: with Ada.Text_IO;

procedure Jewels_And_Stones is

   function Count (Jewels, Stones : in String) return Natural is
      Sum : Natural := 0;
   begin
      for J of Jewels loop
         for S of Stones loop
            if J = S then
               Sum := Sum + 1;
               exit;
            end if;
         end loop;
      end loop;
      return Sum;
   end Count;

   procedure Show (Jewels, Stones : in String) is
      use Ada.Text_IO;
   begin
      Put (Jewels);
      Set_Col (12); Put (Stones);
      Set_Col (20); Put (Count (Jewels => Jewels,
                                Stones => Stones)'Image);
      New_Line;
   end Show;

begin
   Show ("aAAbbbb", "aA");
   Show ("ZZ",      "z");
end Jewels_And_Stones;
Task: Jewels and stones


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

int countJewels(const std::string& s, const std::string& j) {
    int count = 0;
    for (char c : s) {
        if (j.find(c) != std::string::npos) {
            count++;
        }
    }
    return count;
}

int main() {
    using namespace std;

    cout << countJewels("aAAbbbb", "aA") << endl;
    cout << countJewels("ZZ", "z") << endl;

    return 0;
}










Ada: with Ada.Text_IO;

procedure Jewels_And_Stones is

   function Count (Jewels, Stones : in String) return Natural is
      Sum : Natural := 0;
   begin
      for J of Jewels loop
         for S of Stones loop
            if J = S then
               Sum := Sum + 1;
               exit;
            end if;
         end loop;
      end loop;
      return Sum;
   end Count;

   procedure Show (Jewels, Stones : in String) is
      use Ada.Text_IO;
   begin
      Put (Jewels);
      Set_Col (12); Put (Stones);
      Set_Col (20); Put (Count (Jewels => Jewels,
                                Stones => Stones)'Image);
      New_Line;
   end Show;

begin
   Show ("aAAbbbb", "aA");
   Show ("ZZ",      "z");
end Jewels_And_Stones;
Task: Jewels and stones




Go: package main
  
import (
    "fmt"
    "strings"
)

func js(stones, jewels string) (n int) {
    for _, b := range []byte(stones) {
        if strings.IndexByte(jewels, b) >= 0 {
            n++
        }
    }
    return
}

func main() {
    fmt.Println(js("aAAbbbb", "aA"))
}








Ada: with Ada.Text_IO;

procedure Jewels_And_Stones is

   function Count (Jewels, Stones : in String) return Natural is
      Sum : Natural := 0;
   begin
      for J of Jewels loop
         for S of Stones loop
            if J = S then
               Sum := Sum + 1;
               exit;
            end if;
         end loop;
      end loop;
      return Sum;
   end Count;

   procedure Show (Jewels, Stones : in String) is
      use Ada.Text_IO;
   begin
      Put (Jewels);
      Set_Col (12); Put (Stones);
      Set_Col (20); Put (Count (Jewels => Jewels,
                                Stones => Stones)'Image);
      New_Line;
   end Show;

begin
   Show ("aAAbbbb", "aA");
   Show ("ZZ",      "z");
end Jewels_And_Stones;
Task: Jewels and stones





Java: import java.util.HashSet;
import java.util.Set;

public class App {
    private static int countJewels(String stones, String jewels) {
        Set<Character> bag = new HashSet<>();
        for (char c : jewels.toCharArray()) {
            bag.add(c);
        }

        int count = 0;
        for (char c : stones.toCharArray()) {
            if (bag.contains(c)) {
                count++;
            }
        }

        return count;
    }

    public static void main(String[] args) {
        System.out.println(countJewels("aAAbbbb", "aA"));
        System.out.println(countJewels("ZZ", "z"));
    }
}







Ada: with Ada.Text_IO;

procedure Jewels_And_Stones is

   function Count (Jewels, Stones : in String) return Natural is
      Sum : Natural := 0;
   begin
      for J of Jewels loop
         for S of Stones loop
            if J = S then
               Sum := Sum + 1;
               exit;
            end if;
         end loop;
      end loop;
      return Sum;
   end Count;

   procedure Show (Jewels, Stones : in String) is
      use Ada.Text_IO;
   begin
      Put (Jewels);
      Set_Col (12); Put (Stones);
      Set_Col (20); Put (Count (Jewels => Jewels,
                                Stones => Stones)'Image);
      New_Line;
   end Show;

begin
   Show ("aAAbbbb", "aA");
   Show ("ZZ",      "z");
end Jewels_And_Stones;
Task: Jewels and stones







Python: def countJewels(s, j):
    return sum(x in j for x in s)

print countJewels("aAAbbbb", "aA")
print countJewels("ZZ", "z")





Ada: with Ada.Text_IO;

procedure Jewels_And_Stones is

   function Count (Jewels, Stones : in String) return Natural is
      Sum : Natural := 0;
   begin
      for J of Jewels loop
         for S of Stones loop
            if J = S then
               Sum := Sum + 1;
               exit;
            end if;
         end loop;
      end loop;
      return Sum;
   end Count;

   procedure Show (Jewels, Stones : in String) is
      use Ada.Text_IO;
   begin
      Put (Jewels);
      Set_Col (12); Put (Stones);
      Set_Col (20); Put (Count (Jewels => Jewels,
                                Stones => Stones)'Image);
      New_Line;
   end Show;

begin
   Show ("aAAbbbb", "aA");
   Show ("ZZ",      "z");
end Jewels_And_Stones;
Task: Jewels and stones








VB: function contar_joyas(piedras, joyas)
	cont = 0
	for i = 1 to length(piedras)
		bc = instr(joyas, mid(piedras, i, 1), 1)
		if bc <> 0 then cont += 1
	next i
	return cont
end function

print contar_joyas("aAAbbbb", "aA")
print contar_joyas("ZZ", "z")
print contar_joyas("ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz")
print contar_joyas("AB", "")




Ada: with Ada.Text_IO;

procedure Jewels_And_Stones is

   function Count (Jewels, Stones : in String) return Natural is
      Sum : Natural := 0;
   begin
      for J of Jewels loop
         for S of Stones loop
            if J = S then
               Sum := Sum + 1;
               exit;
            end if;
         end loop;
      end loop;
      return Sum;
   end Count;

   procedure Show (Jewels, Stones : in String) is
      use Ada.Text_IO;
   begin
      Put (Jewels);
      Set_Col (12); Put (Stones);
      Set_Col (20); Put (Count (Jewels => Jewels,
                                Stones => Stones)'Image);
      New_Line;
   end Show;

begin
   Show ("aAAbbbb", "aA");
   Show ("ZZ",      "z");
end Jewels_And_Stones;
Task: Jewels and stones

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

int count_jewels(const char *s, const char *j) {
    int count = 0;
    for ( ; *s; ++s) if (strchr(j, *s)) ++count;
    return count;
}

int main() {
    printf("%d\n", count_jewels("aAAbbbb", "aA"));
    printf("%d\n", count_jewels("ZZ", "z"));
    return 0;
}
Task: Jewels and stones



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(Count("aAAbbbb", "Aa"));
        Console.WriteLine(Count("ZZ", "z"));
    }

    private static int Count(string stones, string jewels) {
        var bag = jewels.ToHashSet();
        return stones.Count(bag.Contains);
    }
}
Task: Jewels and stones


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

int countJewels(const std::string& s, const std::string& j) {
    int count = 0;
    for (char c : s) {
        if (j.find(c) != std::string::npos) {
            count++;
        }
    }
    return count;
}

int main() {
    using namespace std;

    cout << countJewels("aAAbbbb", "aA") << endl;
    cout << countJewels("ZZ", "z") << endl;

    return 0;
}
Task: Jewels and stones





Java: import java.util.HashSet;
import java.util.Set;

public class App {
    private static int countJewels(String stones, String jewels) {
        Set<Character> bag = new HashSet<>();
        for (char c : jewels.toCharArray()) {
            bag.add(c);
        }

        int count = 0;
        for (char c : stones.toCharArray()) {
            if (bag.contains(c)) {
                count++;
            }
        }

        return count;
    }

    public static void main(String[] args) {
        System.out.println(countJewels("aAAbbbb", "aA"));
        System.out.println(countJewels("ZZ", "z"));
    }
}
Task: Jewels and stones







Python: def countJewels(s, j):
    return sum(x in j for x in s)

print countJewels("aAAbbbb", "aA")
print countJewels("ZZ", "z")
Task: Jewels and stones








VB: function contar_joyas(piedras, joyas)
	cont = 0
	for i = 1 to length(piedras)
		bc = instr(joyas, mid(piedras, i, 1), 1)
		if bc <> 0 then cont += 1
	next i
	return cont
end function

print contar_joyas("aAAbbbb", "aA")
print contar_joyas("ZZ", "z")
print contar_joyas("ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz", "ABCDEFGHIJKLMNOPQRSTUVWXYZ@abcdefghijklmnopqrstuvwxyz")
print contar_joyas("AB", "")
Task: Jewels and stones




Go: package main
  
import (
    "fmt"
    "strings"
)

func js(stones, jewels string) (n int) {
    for _, b := range []byte(stones) {
        if strings.IndexByte(jewels, b) >= 0 {
            n++
        }
    }
    return
}

func main() {
    fmt.Println(js("aAAbbbb", "aA"))
}
Task: Jewels and stones








VB: Function count_jewels(stones As String, jewels As String) As Integer
    Dim res As Integer: res = 0
    For i = 1 To Len(stones)
        res = res - (InStr(1, jewels, Mid(stones, i, 1), vbBinaryCompare) <> 0)
    Next i
    count_jewels = res
End Function
Public Sub main()
    Debug.Print count_jewels("aAAbbbb", "aA")
    Debug.Print count_jewels("ZZ", "z")
End Sub
Task: Factorial



C#: using System;

class Program
{
    static int Factorial(int number)
    {
        if(number < 0) 
            throw new ArgumentOutOfRangeException(nameof(number), number, "Must be zero or a positive number.");

        var accumulator = 1;
        for (var factor = 1; factor <= number; factor++)
        {
            accumulator *= factor;
        }
        return accumulator;
    }

    static void Main()
    {
        Console.WriteLine(Factorial(10));
    }
}









Ada: function Factorial (N : Positive) return Positive is
   Result : Positive := N;
   Counter : Natural := N - 1;
begin
   for I in reverse 1..Counter loop
      Result := Result * I;
   end loop;
   return Result;
end Factorial;
Task: Factorial

C: int factorial(int n) {
    int result = 1;
    for (int i = 1; i <= n; ++i)
        result *= i;
    return result;
}











Ada: function Factorial (N : Positive) return Positive is
   Result : Positive := N;
   Counter : Natural := N - 1;
begin
   for I in reverse 1..Counter loop
      Result := Result * I;
   end loop;
   return Result;
end Factorial;
Task: Factorial


C++: #include <boost/iterator/counting_iterator.hpp>
#include <algorithm>

int factorial(int n)
{
  
  return std::accumulate(boost::counting_iterator<int>(1), boost::counting_iterator<int>(n+1), 1, std::multiplies<int>());
}










Ada: function Factorial (N : Positive) return Positive is
   Result : Positive := N;
   Counter : Natural := N - 1;
begin
   for I in reverse 1..Counter loop
      Result := Result * I;
   end loop;
   return Result;
end Factorial;
Task: Factorial




Go: package main

import (
    "fmt"
    "math/big"
)

func main() {
    fmt.Println(factorial(800))
}

func factorial(n int64) *big.Int {
    if n < 0 {
        return nil
    }
    r := big.NewInt(1)
    var f big.Int
    for i := int64(2); i <= n; i++ {
        r.Mul(r, f.SetInt64(i))
    }
    return r
}








Ada: function Factorial (N : Positive) return Positive is
   Result : Positive := N;
   Counter : Natural := N - 1;
begin
   for I in reverse 1..Counter loop
      Result := Result * I;
   end loop;
   return Result;
end Factorial;
Task: Factorial





Java: module ShowFactorials
    {
    static <Value extends IntNumber> Value factorial(Value n)
        {
        assert:arg n >= Value.zero();
        return n <= Value.one() ? n : n * factorial(n-Value.one());
        }

    @Inject Console console;
    void run()
        {
        
        UInt128 bigNum = 34;
        console.print($"factorial({bigNum})={factorial(bigNum)}");

        
        for (Int i : 10..-1)
            {
            console.print($"factorial({i})={factorial(i)}");
            }
        }
    }







Ada: function Factorial (N : Positive) return Positive is
   Result : Positive := N;
   Counter : Natural := N - 1;
begin
   for I in reverse 1..Counter loop
      Result := Result * I;
   end loop;
   return Result;
end Factorial;
Task: Factorial







Python: import math
math.factorial(n)





Ada: function Factorial (N : Positive) return Positive is
   Result : Positive := N;
   Counter : Natural := N - 1;
begin
   for I in reverse 1..Counter loop
      Result := Result * I;
   end loop;
   return Result;
end Factorial;
Task: Factorial








VB: print "enter a number, n = ";
input n
print string(n) + "! = " + string(factorial(n))

function factorial(n)
   factorial = 1
   if n > 0 then
      for p = 1 to n
      factorial *= p
      next p
   end if
end function




Ada: function Factorial (N : Positive) return Positive is
   Result : Positive := N;
   Counter : Natural := N - 1;
begin
   for I in reverse 1..Counter loop
      Result := Result * I;
   end loop;
   return Result;
end Factorial;
Task: Factorial

C: int factorial(int n) {
    int result = 1;
    for (int i = 1; i <= n; ++i)
        result *= i;
    return result;
}
Task: Factorial



C#: using System;

class Program
{
    static int Factorial(int number)
    {
        if(number < 0) 
            throw new ArgumentOutOfRangeException(nameof(number), number, "Must be zero or a positive number.");

        var accumulator = 1;
        for (var factor = 1; factor <= number; factor++)
        {
            accumulator *= factor;
        }
        return accumulator;
    }

    static void Main()
    {
        Console.WriteLine(Factorial(10));
    }
}
Task: Factorial


C++: #include <boost/iterator/counting_iterator.hpp>
#include <algorithm>

int factorial(int n)
{
  
  return std::accumulate(boost::counting_iterator<int>(1), boost::counting_iterator<int>(n+1), 1, std::multiplies<int>());
}
Task: Factorial





Java: module ShowFactorials
    {
    static <Value extends IntNumber> Value factorial(Value n)
        {
        assert:arg n >= Value.zero();
        return n <= Value.one() ? n : n * factorial(n-Value.one());
        }

    @Inject Console console;
    void run()
        {
        
        UInt128 bigNum = 34;
        console.print($"factorial({bigNum})={factorial(bigNum)}");

        
        for (Int i : 10..-1)
            {
            console.print($"factorial({i})={factorial(i)}");
            }
        }
    }
Task: Factorial







Python: import math
math.factorial(n)
Task: Factorial








VB: print "enter a number, n = ";
input n
print string(n) + "! = " + string(factorial(n))

function factorial(n)
   factorial = 1
   if n > 0 then
      for p = 1 to n
      factorial *= p
      next p
   end if
end function