WeixiangYan/CodeTransOcean huggingface dataset:
Task: Greatest subsequential sum

C: #include "stdio.h"

typedef struct Range {
    int start, end, sum;
} Range;

Range maxSubseq(const int sequence[], const int len) {
    int maxSum = 0, thisSum = 0, i = 0;
    int start = 0, end = -1, j;

    for (j = 0; j < len; j++) {
        thisSum += sequence[j];
        if (thisSum < 0) {
            i = j + 1;
            thisSum = 0;
        } else if (thisSum > maxSum) {
            maxSum = thisSum;
            start = i;
            end   = j;
        }
    }

    Range r;
    if (start <= end && start >= 0 && end >= 0) {
        r.start = start;
        r.end = end + 1;
        r.sum = maxSum;
    } else {
        r.start = 0;
        r.end = 0;
        r.sum = 0;
    }
    return r;
}

int main(int argc, char **argv) {
    int a[] = {-1 , -2 , 3 , 5 , 6 , -2 , -1 , 4 , -4 , 2 , -1};
    int alength = sizeof(a)/sizeof(a[0]);

    Range r = maxSubseq(a, alength);
    printf("Max sum = %d\n", r.sum);
    int i;
    for (i = r.start; i < r.end; i++)
        printf("%d ", a[i]);
    printf("\n");

    return 0;
}










Fortran: program MaxSubSeq
  implicit none

  integer, parameter :: an = 11
  integer, dimension(an) :: a = (/ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 /)

  integer, dimension(an,an) :: mix
  integer :: i, j
  integer, dimension(2) :: m

  forall(i=1:an,j=1:an) mix(i,j) = sum(a(i:j))
  m = maxloc(mix)
  
  print *, a(m(1):m(2))

end program MaxSubSeq
Task: Greatest subsequential sum





Java: import java.util.Scanner;
import java.util.ArrayList;

public class Sub{
    private static int[] indices;

    public static void main(String[] args){
        ArrayList<Long> array= new ArrayList<Long>(); 
        Scanner in = new Scanner(System.in);
        while(in.hasNextLong()) array.add(in.nextLong());
        long highSum= Long.MIN_VALUE;
        ArrayList<Long> highSet= new ArrayList<Long>();
        
        for(int subSize= 0;subSize<= array.size();subSize++){
            indices= new int[subSize];
            for(int i= 0;i< subSize;i++) indices[i]= i;
            do{
                long sum= 0;
                ArrayList<Long> temp= new ArrayList<Long>();
                
                for(long index:indices) {sum+= array.get(index); temp.add(array.get(index));}
                if(sum > highSum){
                    highSet= temp;    
                    highSum= sum;
                }
            }while(nextIndices(array));
        }
        System.out.println("Sum: " + highSum + "\nSet: " + 
        		highSet);
    }
    

    private static boolean nextIndices(ArrayList<Long> a) {
        for(int i= indices.length-1;i >= 0;--i){
            indices[i]++;
            for(int j=i+1;j < indices.length;++j){
                indices[j]= indices[j - 1] + 1;
            }
            if(indices[indices.length - 1] < a.size()){
                return true;
            }
        }
        return false;
    }
}






Fortran: program MaxSubSeq
  implicit none

  integer, parameter :: an = 11
  integer, dimension(an) :: a = (/ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 /)

  integer, dimension(an,an) :: mix
  integer :: i, j
  integer, dimension(2) :: m

  forall(i=1:an,j=1:an) mix(i,j) = sum(a(i:j))
  m = maxloc(mix)
  
  print *, a(m(1):m(2))

end program MaxSubSeq
Task: Greatest subsequential sum







Python: def maxsubseq(seq):
  return max((seq[begin:end] for begin in xrange(len(seq)+1)
                             for end in xrange(begin, len(seq)+1)),
             key=sum)




Fortran: program MaxSubSeq
  implicit none

  integer, parameter :: an = 11
  integer, dimension(an) :: a = (/ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 /)

  integer, dimension(an,an) :: mix
  integer :: i, j
  integer, dimension(2) :: m

  forall(i=1:an,j=1:an) mix(i,j) = sum(a(i:j))
  m = maxloc(mix)
  
  print *, a(m(1):m(2))

end program MaxSubSeq
Task: Greatest subsequential sum






PHP: <?php
 
function max_sum_seq($sequence) {

  $sum_start = 0;
  $sum = 0;
  $max_sum = 0;
  $max_start = 0;
  $max_len = 0;
  for ($i = 0; $i < count($sequence); $i += 1) {
    $n = $sequence[$i];
    $sum += $n;
    if ($sum > $max_sum) {
      $max_sum = $sum;
      $max_start = $sum_start;
      $max_len = $i + 1 - $max_start;
    }
    if ($sum < 0) { # start new sequence
      $sum = 0;
      $sum_start = $i + 1;
    }
  }
  return array_slice($sequence, $max_start, $max_len);
}
 
function print_array($arr) {
  if (count($arr) > 0) {
    echo join(" ", $arr);
  } else {
    echo "(empty)";
  }
  echo '<br>';
}  

print_array(max_sum_seq(array(-1, 0, 15, 3, -9, 12, -4)));
print_array(max_sum_seq(array(-1)));
print_array(max_sum_seq(array(4, -10, 3)));
?>





Fortran: program MaxSubSeq
  implicit none

  integer, parameter :: an = 11
  integer, dimension(an) :: a = (/ -1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1 /)

  integer, dimension(an,an) :: mix
  integer :: i, j
  integer, dimension(2) :: m

  forall(i=1:an,j=1:an) mix(i,j) = sum(a(i:j))
  m = maxloc(mix)
  
  print *, a(m(1):m(2))

end program MaxSubSeq
Task: Greatest subsequential sum






PHP: <?php
 
function max_sum_seq($sequence) {

  $sum_start = 0;
  $sum = 0;
  $max_sum = 0;
  $max_start = 0;
  $max_len = 0;
  for ($i = 0; $i < count($sequence); $i += 1) {
    $n = $sequence[$i];
    $sum += $n;
    if ($sum > $max_sum) {
      $max_sum = $sum;
      $max_start = $sum_start;
      $max_len = $i + 1 - $max_start;
    }
    if ($sum < 0) { # start new sequence
      $sum = 0;
      $sum_start = $i + 1;
    }
  }
  return array_slice($sequence, $max_start, $max_len);
}
 
function print_array($arr) {
  if (count($arr) > 0) {
    echo join(" ", $arr);
  } else {
    echo "(empty)";
  }
  echo '<br>';
}  

print_array(max_sum_seq(array(-1, 0, 15, 3, -9, 12, -4)));
print_array(max_sum_seq(array(-1)));
print_array(max_sum_seq(array(4, -10, 3)));
?>
Task: Greatest subsequential sum






PHP: <?php
 
function max_sum_seq($sequence) {

  $sum_start = 0;
  $sum = 0;
  $max_sum = 0;
  $max_start = 0;
  $max_len = 0;
  for ($i = 0; $i < count($sequence); $i += 1) {
    $n = $sequence[$i];
    $sum += $n;
    if ($sum > $max_sum) {
      $max_sum = $sum;
      $max_start = $sum_start;
      $max_len = $i + 1 - $max_start;
    }
    if ($sum < 0) { # start new sequence
      $sum = 0;
      $sum_start = $i + 1;
    }
  }
  return array_slice($sequence, $max_start, $max_len);
}
 
function print_array($arr) {
  if (count($arr) > 0) {
    echo join(" ", $arr);
  } else {
    echo "(empty)";
  }
  echo '<br>';
}  

print_array(max_sum_seq(array(-1, 0, 15, 3, -9, 12, -4)));
print_array(max_sum_seq(array(-1)));
print_array(max_sum_seq(array(4, -10, 3)));
?>






Ada: with Ada.Text_Io; use Ada.Text_Io;

procedure Max_Subarray is
   type Int_Array is array (Positive range <>) of Integer;
   Empty_Error : Exception;
   function Max(Item : Int_Array) return Int_Array is
      Start : Positive;
      Finis : Positive;
      Max_Sum : Integer := Integer'First;
      Sum : Integer;
   begin
      if Item'Length = 0 then
         raise Empty_Error;
      end if;
      
      for I in Item'range loop
         Sum := 0;
         for J in I..Item'Last loop
            Sum := Sum + Item(J);
            if Sum > Max_Sum then
               Max_Sum := Sum;
               Start := I;
               Finis := J;
            end if;
         end loop;
      end loop;
      return Item(Start..Finis);
   end Max;
   A : Int_Array := (-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1);
   B : Int_Array := Max(A);
begin
   for I in B'range loop
      Put_Line(Integer'Image(B(I)));
   end loop;
exception
   when Empty_Error =>
      Put_Line("Array being analyzed has no elements.");
end Max_Subarray;
Task: Integer sequence



C#: using System;
using System.Numerics;

class Program
{
    static void Main()
    {
        BigInteger i = 1;
        while (true)
        {
            Console.WriteLine(i++);
        }
    }
}









Ada: with Ada.Text_IO;
procedure Integers is
   Value : Integer := 1;
begin
   loop
      Ada.Text_IO.Put_Line (Integer'Image (Value));
      Value := Value + 1;  
   end loop;
end Integers;
Task: Integer sequence

C: #include <stdio.h>

int main()
{
	unsigned int i = 0;
	while (++i) printf("%u\n", i);

	return 0;
}











Ada: with Ada.Text_IO;
procedure Integers is
   Value : Integer := 1;
begin
   loop
      Ada.Text_IO.Put_Line (Integer'Image (Value));
      Value := Value + 1;  
   end loop;
end Integers;
Task: Integer sequence


C++: #include <cstdint>
#include <iostream>
#include <limits>

int main()
{
  auto i = std::uintmax_t{};
  
  while (i < std::numeric_limits<decltype(i)>::max())
    std::cout << ++i << '\n';
}










Ada: with Ada.Text_IO;
procedure Integers is
   Value : Integer := 1;
begin
   loop
      Ada.Text_IO.Put_Line (Integer'Image (Value));
      Value := Value + 1;  
   end loop;
end Integers;
Task: Integer sequence




Go: package main

import "fmt"

func main() {
    for i := 1;; i++ {
        fmt.Println(i)
    }
}








Ada: with Ada.Text_IO;
procedure Integers is
   Value : Integer := 1;
begin
   loop
      Ada.Text_IO.Put_Line (Integer'Image (Value));
      Value := Value + 1;  
   end loop;
end Integers;
Task: Integer sequence





Java: public class Count{
    public static void main(String[] args){
        for(long i = 1; ;i++) System.out.println(i);
    }
}







Ada: with Ada.Text_IO;
procedure Integers is
   Value : Integer := 1;
begin
   loop
      Ada.Text_IO.Put_Line (Integer'Image (Value));
      Value := Value + 1;  
   end loop;
end Integers;
Task: Integer sequence







Python: i=1
while i:
    print(i)
    i += 1





Ada: with Ada.Text_IO;
procedure Integers is
   Value : Integer := 1;
begin
   loop
      Ada.Text_IO.Put_Line (Integer'Image (Value));
      Value := Value + 1;  
   end loop;
end Integers;
Task: Integer sequence








VB:     For i As Integer = 0 To Integer.MaxValue
      Console.WriteLine(i)
    Next




Ada: with Ada.Text_IO;
procedure Integers is
   Value : Integer := 1;
begin
   loop
      Ada.Text_IO.Put_Line (Integer'Image (Value));
      Value := Value + 1;  
   end loop;
end Integers;
Task: Integer sequence

C: #include <stdio.h>

int main()
{
	unsigned int i = 0;
	while (++i) printf("%u\n", i);

	return 0;
}
Task: Integer sequence



C#: using System;
using System.Numerics;

class Program
{
    static void Main()
    {
        BigInteger i = 1;
        while (true)
        {
            Console.WriteLine(i++);
        }
    }
}
Task: Integer sequence


C++: #include <cstdint>
#include <iostream>
#include <limits>

int main()
{
  auto i = std::uintmax_t{};
  
  while (i < std::numeric_limits<decltype(i)>::max())
    std::cout << ++i << '\n';
}
Task: Integer sequence





Java: public class Count{
    public static void main(String[] args){
        for(long i = 1; ;i++) System.out.println(i);
    }
}
Task: Integer sequence







Python: i=1
while i:
    print(i)
    i += 1
Task: Integer sequence








VB:     For i As Integer = 0 To Integer.MaxValue
      Console.WriteLine(i)
    Next
Task: Integer sequence




Go: package main

import "fmt"

func main() {
    for i := 1;; i++ {
        fmt.Println(i)
    }
}
Task: Integer sequence



C#: using System;
using System.Numerics;

class Program
{
    static void Main()
    {
        BigInteger i = 1;
        while (true)
        {
            Console.WriteLine(i++);
        }
    }
}








Fortran: program Intseq
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 1
  


  do
    print*, n
    n = n + 1
  end do
end program
Task: Integer sequence


C++: #include <cstdint>
#include <iostream>
#include <limits>

int main()
{
  auto i = std::uintmax_t{};
  
  while (i < std::numeric_limits<decltype(i)>::max())
    std::cout << ++i << '\n';
}









Fortran: program Intseq
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 1
  


  do
    print*, n
    n = n + 1
  end do
end program
Task: Integer sequence

C: #include <stdio.h>

int main()
{
	unsigned int i = 0;
	while (++i) printf("%u\n", i);

	return 0;
}










Fortran: program Intseq
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 1
  


  do
    print*, n
    n = n + 1
  end do
end program
Task: Integer sequence





Java: public class Count{
    public static void main(String[] args){
        for(long i = 1; ;i++) System.out.println(i);
    }
}






Fortran: program Intseq
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 1
  


  do
    print*, n
    n = n + 1
  end do
end program
Task: Integer sequence







Python: i=1
while i:
    print(i)
    i += 1




Fortran: program Intseq
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 1
  


  do
    print*, n
    n = n + 1
  end do
end program
Task: Integer sequence








VB:     For i As Integer = 0 To Integer.MaxValue
      Console.WriteLine(i)
    Next



Fortran: program Intseq
  implicit none
  
  integer, parameter :: i64 = selected_int_kind(18)
  integer(i64) :: n = 1
  


  do
    print*, n
    n = n + 1
  end do
end program
Task: Integer sequence

C: #include <stdio.h>

int main()
{
	unsigned int i = 0;
	while (++i) printf("%u\n", i);

	return 0;
}









COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Sequence.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
*      
       01  I PIC 9(36).

       PROCEDURE DIVISION.
*          
           PERFORM VARYING I FROM 1 BY 1 UNTIL I = 0
               DISPLAY I
           END-PERFORM

           GOBACK
           .
Task: Integer sequence



C#: using System;
using System.Numerics;

class Program
{
    static void Main()
    {
        BigInteger i = 1;
        while (true)
        {
            Console.WriteLine(i++);
        }
    }
}







COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Sequence.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
*      
       01  I PIC 9(36).

       PROCEDURE DIVISION.
*          
           PERFORM VARYING I FROM 1 BY 1 UNTIL I = 0
               DISPLAY I
           END-PERFORM

           GOBACK
           .
Task: Integer sequence


C++: #include <cstdint>
#include <iostream>
#include <limits>

int main()
{
  auto i = std::uintmax_t{};
  
  while (i < std::numeric_limits<decltype(i)>::max())
    std::cout << ++i << '\n';
}








COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Sequence.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
*      
       01  I PIC 9(36).

       PROCEDURE DIVISION.
*          
           PERFORM VARYING I FROM 1 BY 1 UNTIL I = 0
               DISPLAY I
           END-PERFORM

           GOBACK
           .
Task: Integer sequence





Java: public class Count{
    public static void main(String[] args){
        for(long i = 1; ;i++) System.out.println(i);
    }
}





COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Sequence.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
*      
       01  I PIC 9(36).

       PROCEDURE DIVISION.
*          
           PERFORM VARYING I FROM 1 BY 1 UNTIL I = 0
               DISPLAY I
           END-PERFORM

           GOBACK
           .
Task: Integer sequence







Python: i=1
while i:
    print(i)
    i += 1



COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Sequence.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
*      
       01  I PIC 9(36).

       PROCEDURE DIVISION.
*          
           PERFORM VARYING I FROM 1 BY 1 UNTIL I = 0
               DISPLAY I
           END-PERFORM

           GOBACK
           .
Task: Integer sequence








VB:     For i As Integer = 0 To Integer.MaxValue
      Console.WriteLine(i)
    Next


COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Sequence.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
*      
       01  I PIC 9(36).

       PROCEDURE DIVISION.
*          
           PERFORM VARYING I FROM 1 BY 1 UNTIL I = 0
               DISPLAY I
           END-PERFORM

           GOBACK
           .
Task: Integer sequence




Go: package main

import "fmt"

func main() {
    for i := 1;; i++ {
        fmt.Println(i)
    }
}






COBOL:        IDENTIFICATION DIVISION.
       PROGRAM-ID. Int-Sequence.

       DATA DIVISION.
       WORKING-STORAGE SECTION.
*      
       01  I PIC 9(36).

       PROCEDURE DIVISION.
*          
           PERFORM VARYING I FROM 1 BY 1 UNTIL I = 0
               DISPLAY I
           END-PERFORM

           GOBACK
           .
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}









Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Fib is

   X: Positive := Positive'Value(Ada.Command_Line.Argument(1));

   function Fib(P: Positive) return Positive is
   begin
      if P <= 2 then
         return 1;
      else
         return Fib(P-1) + Fib(P-2);
      end if;
   end Fib;

begin
   Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
   Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
end Fib;
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end













Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Fib is

   X: Positive := Positive'Value(Ada.Command_Line.Argument(1));

   function Fib(P: Positive) return Positive is
   begin
      if P <= 2 then
         return 1;
      else
         return Fib(P-1) + Fib(P-2);
      end if;
   end Fib;

begin
   Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
   Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
end Fib;
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}










Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Fib is

   X: Positive := Positive'Value(Ada.Command_Line.Argument(1));

   function Fib(P: Positive) return Positive is
   begin
      if P <= 2 then
         return 1;
      else
         return Fib(P-1) + Fib(P-2);
      end if;
   end Fib;

begin
   Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
   Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
end Fib;
Task: Fibonacci sequence




Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}








Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Fib is

   X: Positive := Positive'Value(Ada.Command_Line.Argument(1));

   function Fib(P: Positive) return Positive is
   begin
      if P <= 2 then
         return 1;
      else
         return Fib(P-1) + Fib(P-2);
      end if;
   end Fib;

begin
   Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
   Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
end Fib;
Task: Fibonacci sequence





Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}







Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Fib is

   X: Positive := Positive'Value(Ada.Command_Line.Argument(1));

   function Fib(P: Positive) return Positive is
   begin
      if P <= 2 then
         return 1;
      else
         return Fib(P-1) + Fib(P-2);
      end if;
   end Fib;

begin
   Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
   Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
end Fib;
Task: Fibonacci sequence







Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),





Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Fib is

   X: Positive := Positive'Value(Ada.Command_Line.Argument(1));

   function Fib(P: Positive) return Positive is
   begin
      if P <= 2 then
         return 1;
      else
         return Fib(P-1) + Fib(P-2);
      end if;
   end Fib;

begin
   Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
   Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
end Fib;
Task: Fibonacci sequence








VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function




Ada: with Ada.Text_IO, Ada.Command_Line;

procedure Fib is

   X: Positive := Positive'Value(Ada.Command_Line.Argument(1));

   function Fib(P: Positive) return Positive is
   begin
      if P <= 2 then
         return 1;
      else
         return Fib(P-1) + Fib(P-2);
      end if;
   end Fib;

begin
   Ada.Text_IO.Put("Fibonacci(" & Integer'Image(X) & " ) = ");
   Ada.Text_IO.Put_Line(Integer'Image(Fib(X)));
end Fib;
Task: Fibonacci sequence

C: 
fun fibb
    loop
        a = funparam[0]
        break (a < 2)

        a--

        
        a -> stack

        
        funparam[0] = a
        call fibb

        
        b = funparam[0]
        stack -> a

        
        b -> stack

        a--

        
        funparam[0] = a
        call fibb

        
        c = funparam[0]
        stack -> b

        
        b += c
        a = b

        funparam[0] = a

        break
    end
end
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}
Task: Fibonacci sequence


C++: #include <iostream>

int main()
{
        unsigned int a = 1, b = 1;
        unsigned int target = 48;
        for(unsigned int n = 3; n <= target; ++n)
        {
                unsigned int fib = a + b;
                std::cout << "F("<< n << ") = " << fib << std::endl;
                a = b;
                b = fib;
        }

        return 0;
}
Task: Fibonacci sequence





Java: public static long itFibN(int n)
{
 if (n < 2)
  return n;
 long ans = 0;
 long n1 = 0;
 long n2 = 1;
 for(n--; n > 0; n--)
 {
  ans = n1 + n2;
  n1 = n2;
  n2 = ans;
 }
 return ans;
}
Task: Fibonacci sequence







Python: from math import *

def analytic_fibonacci(n):
  sqrt_5 = sqrt(5);
  p = (1 + sqrt_5) / 2;
  q = 1/p;
  return int( (p**n + q**n) / sqrt_5 + 0.5 )

for i in range(1,31):
  print analytic_fibonacci(i),
Task: Fibonacci sequence








VB: Public Function Fib(ByVal n As Integer) As Variant
    Dim fib0 As Variant, fib1 As Variant, sum As Variant
    Dim i As Integer
    fib0 = 0
    fib1 = 1
    For i = 1 To n
        sum = fib0 + fib1
        fib0 = fib1
        fib1 = sum
    Next i
    Fib = fib0
End Function
Task: Fibonacci sequence




Go: func fib(a int) int {
  if a < 2 {
    return a
  }
  return fib(a - 1) + fib(a - 2)
}
Task: Fibonacci sequence



C#: public static ulong Fib(uint n) {
    return (n < 2)? n : Fib(n - 1) + Fib(n - 2);
}








Fortran: C     FIBONACCI SEQUENCE - FORTRAN IV
      NN=46
      DO 1 I=0,NN
    1 WRITE(*,300) I,IFIBO(I)
  300 FORMAT(1X,I2,1X,I10)
      END
C
      FUNCTION IFIBO(N)
      IF(N) 9,1,2
    1 IFN=0
      GOTO 9
    2 IF(N-1) 9,3,4
    3 IFN=1
      GOTO 9
    4 IFNM1=0
      IFN=1
      DO 5 I=2,N
      IFNM2=IFNM1
      IFNM1=IFN
    5 IFN=IFNM1+IFNM2
    9 IFIBO=IFN
      END