WeixiangYan/CodeTransOcean huggingface dataset:
Task: Abundant, deficient and perfect number classifications








VB: Option Explicit
 
Public Sub Nb_Classifications()
Dim A As New Collection, D As New Collection, P As New Collection
Dim n As Long, l As Long, s As String, t As Single

    t = Timer
    
    For n = 1 To 20000
        l = SumPropers(n): s = CStr(n)
        Select Case n
            Case Is > l: D.Add s, s
            Case Is < l: A.Add s, s
            Case l: P.Add s, s
        End Select
    Next
    
    
    Debug.Print "Execution Time : " & Timer - t & " seconds."
    Debug.Print "-------------------------------------------"
    Debug.Print "Deficient := " & D.Count
    Debug.Print "Perfect := " & P.Count
    Debug.Print "Abundant := " & A.Count
End Sub

Private Function SumPropers(n As Long) As Long

Dim j As Long
    For j = 1 To n \ 2
        If n Mod j = 0 Then SumPropers = j + SumPropers
    Next
End Function
Task: Abundant, deficient and perfect number classifications




Go: package main

import "fmt"

func pfacSum(i int) int {
    sum := 0
    for p := 1; p <= i/2; p++ {
        if i%p == 0 {
            sum += p
        }
    }
    return sum
}

func main() {
    var d, a, p = 0, 0, 0
    for i := 1; i <= 20000; i++ {
        j := pfacSum(i)
        if j < i {
            d++
        } else if j == i {
            p++
        } else {
            a++
        }
    }
    fmt.Printf("There are %d deficient numbers between 1 and 20000\n", d)
    fmt.Printf("There are %d abundant numbers  between 1 and 20000\n", a)
    fmt.Printf("There are %d perfect numbers between 1 and 20000\n", p)
}
Task: Abundant, deficient and perfect number classifications


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

std::vector<int> findProperDivisors ( int n ) {
   std::vector<int> divisors ;
   for ( int i = 1 ; i < n / 2 + 1 ; i++ ) {
      if ( n % i == 0 ) 
	 divisors.push_back( i ) ;
   }
   return divisors  ;
}

int main( ) {
   std::vector<int> deficients , perfects , abundants , divisors ;
   for ( int n = 1 ; n < 20001 ; n++ ) {
      divisors = findProperDivisors( n ) ;
      int sum = std::accumulate( divisors.begin( ) , divisors.end( ) , 0 ) ;
      if ( sum < n ) {
	 deficients.push_back( n ) ;
      }
      if ( sum == n ) {
	 perfects.push_back( n ) ;
      }
      if ( sum > n ) {
	 abundants.push_back( n ) ;
      }
   }
   std::cout << "Deficient : " << deficients.size( ) << std::endl ;
   std::cout << "Perfect   : " << perfects.size( ) << std::endl ;
   std::cout << "Abundant  : " << abundants.size( ) << std::endl ;
   return 0 ;
}









Fortran:       MODULE FACTORSTUFF	
Concocted by R.N.McLean, MMXV.
       INTEGER LOTS		
       PARAMETER (LOTS = 20000)
       INTEGER KNOWNSUM(LOTS)	
       CONTAINS		
        SUBROUTINE PREPARESUMF	
Convert the Sieve of Eratoshenes to have each slot contain the sum of the proper divisors of its slot number.
Changes to instead count the number of factors, or prime factors, etc. would be simple enough.
         INTEGER F		
          KNOWNSUM(1) = 0		
          KNOWNSUM(2:LOTS) = 1		
          DO F = 2,LOTS/2		
            FORALL(I = F + F:LOTS:F) KNOWNSUM(I) = KNOWNSUM(I) + F	
          END DO			
        END SUBROUTINE PREPARESUMF	
         PURE INTEGER FUNCTION SIGN3(N)	
Confounded by the intrinsic function SIGN distinguishing only two states: < 0 from >= 0. NOT three-way.
         INTEGER, INTENT(IN):: N	
          IF (N) 1,2,3	
    1     SIGN3 = -1	
          RETURN
    2     SIGN3 = 0	
          RETURN
    3     SIGN3 = +1	
        END FUNCTION SIGN3	
      END MODULE FACTORSTUFF	
       PROGRAM THREEWAYS	
       USE FACTORSTUFF		
       INTEGER I		
       INTEGER TEST(LOTS)	
        WRITE (6,*) "Inspecting sums of proper divisors for 1 to",LOTS
        CALL PREPARESUMF		
        FORALL(I = 1:LOTS) TEST(I) = SIGN3(KNOWNSUM(I) - I)	
        WRITE (6,*) "Deficient",COUNT(TEST .LT. 0)	
        WRITE (6,*) "Perfect
        WRITE (6,*) "Abundant ",COUNT(TEST .GT. 0)	
      END
Task: Abundant, deficient and perfect number classifications

C: #include<stdio.h>
#define de 0
#define pe 1
#define ab 2

int main(){
	int sum = 0, i, j;
	int try_max = 0;
	
	int   count_list[3] = {1,0,0};
	for(i=2; i <= 20000; i++){
		
		try_max = i/2;
		
		sum = 1;
		for(j=2; j<try_max; j++){
			
			if (i % j)
				continue; 
			
			try_max = i/j;
			
			sum += j;
			if (j != try_max)
				sum += try_max;
		}
		
		if (sum < i){
			count_list[de]++;
			continue;
		}
		if (sum > i){
			count_list[ab]++;
			continue;
		}
		count_list[pe]++;
	}
	printf("\nThere are %d deficient," ,count_list[de]);
	printf(" %d perfect," ,count_list[pe]);
	printf(" %d abundant numbers between 1 and 20000.\n" ,count_list[ab]);
return 0;
}










Fortran:       MODULE FACTORSTUFF	
Concocted by R.N.McLean, MMXV.
       INTEGER LOTS		
       PARAMETER (LOTS = 20000)
       INTEGER KNOWNSUM(LOTS)	
       CONTAINS		
        SUBROUTINE PREPARESUMF	
Convert the Sieve of Eratoshenes to have each slot contain the sum of the proper divisors of its slot number.
Changes to instead count the number of factors, or prime factors, etc. would be simple enough.
         INTEGER F		
          KNOWNSUM(1) = 0		
          KNOWNSUM(2:LOTS) = 1		
          DO F = 2,LOTS/2		
            FORALL(I = F + F:LOTS:F) KNOWNSUM(I) = KNOWNSUM(I) + F	
          END DO			
        END SUBROUTINE PREPARESUMF	
         PURE INTEGER FUNCTION SIGN3(N)	
Confounded by the intrinsic function SIGN distinguishing only two states: < 0 from >= 0. NOT three-way.
         INTEGER, INTENT(IN):: N	
          IF (N) 1,2,3	
    1     SIGN3 = -1	
          RETURN
    2     SIGN3 = 0	
          RETURN
    3     SIGN3 = +1	
        END FUNCTION SIGN3	
      END MODULE FACTORSTUFF	
       PROGRAM THREEWAYS	
       USE FACTORSTUFF		
       INTEGER I		
       INTEGER TEST(LOTS)	
        WRITE (6,*) "Inspecting sums of proper divisors for 1 to",LOTS
        CALL PREPARESUMF		
        FORALL(I = 1:LOTS) TEST(I) = SIGN3(KNOWNSUM(I) - I)	
        WRITE (6,*) "Deficient",COUNT(TEST .LT. 0)	
        WRITE (6,*) "Perfect
        WRITE (6,*) "Abundant ",COUNT(TEST .GT. 0)	
      END
Task: Abundant, deficient and perfect number classifications





Java: import java.util.stream.LongStream;

public class NumberClassifications {
 
    public static void main(String[] args) {
        int deficient = 0;
        int perfect = 0;
        int abundant = 0;
 
        for (long i = 1; i <= 20_000; i++) {
            long sum = properDivsSum(i);
            if (sum < i)
                deficient++;
            else if (sum == i)
                perfect++;
            else
                abundant++;
        }
        System.out.println("Deficient: " + deficient);
        System.out.println("Perfect: " + perfect);
        System.out.println("Abundant: " + abundant);
    }
 
    public static long properDivsSum(long n) {
        return LongStream.rangeClosed(1, (n + 1) / 2).filter(i -> n != i && n % i == 0).sum();
    }
}






Fortran:       MODULE FACTORSTUFF	
Concocted by R.N.McLean, MMXV.
       INTEGER LOTS		
       PARAMETER (LOTS = 20000)
       INTEGER KNOWNSUM(LOTS)	
       CONTAINS		
        SUBROUTINE PREPARESUMF	
Convert the Sieve of Eratoshenes to have each slot contain the sum of the proper divisors of its slot number.
Changes to instead count the number of factors, or prime factors, etc. would be simple enough.
         INTEGER F		
          KNOWNSUM(1) = 0		
          KNOWNSUM(2:LOTS) = 1		
          DO F = 2,LOTS/2		
            FORALL(I = F + F:LOTS:F) KNOWNSUM(I) = KNOWNSUM(I) + F	
          END DO			
        END SUBROUTINE PREPARESUMF	
         PURE INTEGER FUNCTION SIGN3(N)	
Confounded by the intrinsic function SIGN distinguishing only two states: < 0 from >= 0. NOT three-way.
         INTEGER, INTENT(IN):: N	
          IF (N) 1,2,3	
    1     SIGN3 = -1	
          RETURN
    2     SIGN3 = 0	
          RETURN
    3     SIGN3 = +1	
        END FUNCTION SIGN3	
      END MODULE FACTORSTUFF	
       PROGRAM THREEWAYS	
       USE FACTORSTUFF		
       INTEGER I		
       INTEGER TEST(LOTS)	
        WRITE (6,*) "Inspecting sums of proper divisors for 1 to",LOTS
        CALL PREPARESUMF		
        FORALL(I = 1:LOTS) TEST(I) = SIGN3(KNOWNSUM(I) - I)	
        WRITE (6,*) "Deficient",COUNT(TEST .LT. 0)	
        WRITE (6,*) "Perfect
        WRITE (6,*) "Abundant ",COUNT(TEST .GT. 0)	
      END
Task: Abundant, deficient and perfect number classifications







Python: >>> from proper_divisors import proper_divs
>>> from collections import Counter
>>> 
>>> rangemax = 20000
>>> 
>>> def pdsum(n):
...     return sum(proper_divs(n))
... 
>>> def classify(n, p):
...     return 'perfect' if n == p else 'abundant' if p > n else 'deficient'
... 
>>> classes = Counter(classify(n, pdsum(n)) for n in range(1, 1 + rangemax))
>>> classes.most_common()
[('deficient', 15043), ('abundant', 4953), ('perfect', 4)]
>>>




Fortran:       MODULE FACTORSTUFF	
Concocted by R.N.McLean, MMXV.
       INTEGER LOTS		
       PARAMETER (LOTS = 20000)
       INTEGER KNOWNSUM(LOTS)	
       CONTAINS		
        SUBROUTINE PREPARESUMF	
Convert the Sieve of Eratoshenes to have each slot contain the sum of the proper divisors of its slot number.
Changes to instead count the number of factors, or prime factors, etc. would be simple enough.
         INTEGER F		
          KNOWNSUM(1) = 0		
          KNOWNSUM(2:LOTS) = 1		
          DO F = 2,LOTS/2		
            FORALL(I = F + F:LOTS:F) KNOWNSUM(I) = KNOWNSUM(I) + F	
          END DO			
        END SUBROUTINE PREPARESUMF	
         PURE INTEGER FUNCTION SIGN3(N)	
Confounded by the intrinsic function SIGN distinguishing only two states: < 0 from >= 0. NOT three-way.
         INTEGER, INTENT(IN):: N	
          IF (N) 1,2,3	
    1     SIGN3 = -1	
          RETURN
    2     SIGN3 = 0	
          RETURN
    3     SIGN3 = +1	
        END FUNCTION SIGN3	
      END MODULE FACTORSTUFF	
       PROGRAM THREEWAYS	
       USE FACTORSTUFF		
       INTEGER I		
       INTEGER TEST(LOTS)	
        WRITE (6,*) "Inspecting sums of proper divisors for 1 to",LOTS
        CALL PREPARESUMF		
        FORALL(I = 1:LOTS) TEST(I) = SIGN3(KNOWNSUM(I) - I)	
        WRITE (6,*) "Deficient",COUNT(TEST .LT. 0)	
        WRITE (6,*) "Perfect
        WRITE (6,*) "Abundant ",COUNT(TEST .GT. 0)	
      END
Task: Abundant, deficient and perfect number classifications








VB: Option Explicit
 
Public Sub Nb_Classifications()
Dim A As New Collection, D As New Collection, P As New Collection
Dim n As Long, l As Long, s As String, t As Single

    t = Timer
    
    For n = 1 To 20000
        l = SumPropers(n): s = CStr(n)
        Select Case n
            Case Is > l: D.Add s, s
            Case Is < l: A.Add s, s
            Case l: P.Add s, s
        End Select
    Next
    
    
    Debug.Print "Execution Time : " & Timer - t & " seconds."
    Debug.Print "-------------------------------------------"
    Debug.Print "Deficient := " & D.Count
    Debug.Print "Perfect := " & P.Count
    Debug.Print "Abundant := " & A.Count
End Sub

Private Function SumPropers(n As Long) As Long

Dim j As Long
    For j = 1 To n \ 2
        If n Mod j = 0 Then SumPropers = j + SumPropers
    Next
End Function



Fortran:       MODULE FACTORSTUFF	
Concocted by R.N.McLean, MMXV.
       INTEGER LOTS		
       PARAMETER (LOTS = 20000)
       INTEGER KNOWNSUM(LOTS)	
       CONTAINS		
        SUBROUTINE PREPARESUMF	
Convert the Sieve of Eratoshenes to have each slot contain the sum of the proper divisors of its slot number.
Changes to instead count the number of factors, or prime factors, etc. would be simple enough.
         INTEGER F		
          KNOWNSUM(1) = 0		
          KNOWNSUM(2:LOTS) = 1		
          DO F = 2,LOTS/2		
            FORALL(I = F + F:LOTS:F) KNOWNSUM(I) = KNOWNSUM(I) + F	
          END DO			
        END SUBROUTINE PREPARESUMF	
         PURE INTEGER FUNCTION SIGN3(N)	
Confounded by the intrinsic function SIGN distinguishing only two states: < 0 from >= 0. NOT three-way.
         INTEGER, INTENT(IN):: N	
          IF (N) 1,2,3	
    1     SIGN3 = -1	
          RETURN
    2     SIGN3 = 0	
          RETURN
    3     SIGN3 = +1	
        END FUNCTION SIGN3	
      END MODULE FACTORSTUFF	
       PROGRAM THREEWAYS	
       USE FACTORSTUFF		
       INTEGER I		
       INTEGER TEST(LOTS)	
        WRITE (6,*) "Inspecting sums of proper divisors for 1 to",LOTS
        CALL PREPARESUMF		
        FORALL(I = 1:LOTS) TEST(I) = SIGN3(KNOWNSUM(I) - I)	
        WRITE (6,*) "Deficient",COUNT(TEST .LT. 0)	
        WRITE (6,*) "Perfect
        WRITE (6,*) "Abundant ",COUNT(TEST .GT. 0)	
      END
Task: Leonardo numbers



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(string.Join(" ", Leonardo().Take(25)));
        Console.WriteLine(string.Join(" ", Leonardo(L0: 0, L1: 1, add: 0).Take(25)));
    }

    public static IEnumerable<int> Leonardo(int L0 = 1, int L1 = 1, int add = 1) {
        while (true) {
            yield return L0;
            (L0, L1) = (L1, L0 + L1 + add);
        }
    }
}









Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Leonardo is

   function Leo
     (N      : Natural;
      Step   : Natural := 1;
      First  : Natural := 1;
      Second : Natural := 1) return Natural   is 
      L : array (0..1) of Natural := (First, Second);
	begin
		for i in 1 .. N loop
			L := (L(1), L(0)+L(1)+Step);
		end loop;
		return L (0);
	end Leo;

begin
   Put_Line ("First 25 Leonardo numbers:");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I)));
   end loop;
   New_Line;
   Put_Line ("First 25 Leonardo numbers with L(0) = 0, L(1) = 1, " &
             "step = 0 (fibonacci numbers):");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I, 0, 0, 1)));
   end loop;
   New_Line;
end Leonardo;
Task: Leonardo numbers

C: #include<stdio.h>

void leonardo(int a,int b,int step,int num){
	
	int i,temp;
	
	printf("First 25 Leonardo numbers : \n");
	
	for(i=1;i<=num;i++){
		if(i==1)
			printf(" %d",a);
		else if(i==2)
			printf(" %d",b);
		else{
			printf(" %d",a+b+step);
			temp = a;
			a = b;
			b = temp+b+step;
		}
	}
}

int main()
{
	int a,b,step;
	
	printf("Enter first two Leonardo numbers and increment step : ");
	
	scanf("%d%d%d",&a,&b,&step);
	
	leonardo(a,b,step,25);
	
	return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Leonardo is

   function Leo
     (N      : Natural;
      Step   : Natural := 1;
      First  : Natural := 1;
      Second : Natural := 1) return Natural   is 
      L : array (0..1) of Natural := (First, Second);
	begin
		for i in 1 .. N loop
			L := (L(1), L(0)+L(1)+Step);
		end loop;
		return L (0);
	end Leo;

begin
   Put_Line ("First 25 Leonardo numbers:");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I)));
   end loop;
   New_Line;
   Put_Line ("First 25 Leonardo numbers with L(0) = 0, L(1) = 1, " &
             "step = 0 (fibonacci numbers):");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I, 0, 0, 1)));
   end loop;
   New_Line;
end Leonardo;
Task: Leonardo numbers


C++: #include <iostream>

void leoN( int cnt, int l0 = 1, int l1 = 1, int add = 1 ) {
    int t;
    for( int i = 0; i < cnt; i++ ) {
        std::cout << l0 << " ";
        t = l0 + l1 + add; l0 = l1; l1 = t;
    }
}
int main( int argc, char* argv[] ) {
    std::cout << "Leonardo Numbers: "; leoN( 25 );
    std::cout << "\n\nFibonacci Numbers: "; leoN( 25, 0, 1, 0 );
    return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Leonardo is

   function Leo
     (N      : Natural;
      Step   : Natural := 1;
      First  : Natural := 1;
      Second : Natural := 1) return Natural   is 
      L : array (0..1) of Natural := (First, Second);
	begin
		for i in 1 .. N loop
			L := (L(1), L(0)+L(1)+Step);
		end loop;
		return L (0);
	end Leo;

begin
   Put_Line ("First 25 Leonardo numbers:");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I)));
   end loop;
   New_Line;
   Put_Line ("First 25 Leonardo numbers with L(0) = 0, L(1) = 1, " &
             "step = 0 (fibonacci numbers):");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I, 0, 0, 1)));
   end loop;
   New_Line;
end Leonardo;
Task: Leonardo numbers




Go: package main

import "fmt"

func leonardo(n, l0, l1, add int) []int {
    leo := make([]int, n)
    leo[0] = l0
    leo[1] = l1
    for i := 2; i < n; i++ {
        leo[i] = leo[i - 1] + leo[i - 2] + add
    }
    return leo
}

func main() {
    fmt.Println("The first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:")
    fmt.Println(leonardo(25, 1, 1, 1))
    fmt.Println("\nThe first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:")
    fmt.Println(leonardo(25, 0, 1, 0))
}








Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Leonardo is

   function Leo
     (N      : Natural;
      Step   : Natural := 1;
      First  : Natural := 1;
      Second : Natural := 1) return Natural   is 
      L : array (0..1) of Natural := (First, Second);
	begin
		for i in 1 .. N loop
			L := (L(1), L(0)+L(1)+Step);
		end loop;
		return L (0);
	end Leo;

begin
   Put_Line ("First 25 Leonardo numbers:");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I)));
   end loop;
   New_Line;
   Put_Line ("First 25 Leonardo numbers with L(0) = 0, L(1) = 1, " &
             "step = 0 (fibonacci numbers):");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I, 0, 0, 1)));
   end loop;
   New_Line;
end Leonardo;
Task: Leonardo numbers





Java: import java.util.Arrays;
import java.util.List;

@SuppressWarnings("SameParameterValue")
public class LeonardoNumbers {
    private static List<Integer> leonardo(int n) {
        return leonardo(n, 1, 1, 1);
    }

    private static List<Integer> leonardo(int n, int l0, int l1, int add) {
        Integer[] leo = new Integer[n];
        leo[0] = l0;
        leo[1] = l1;
        for (int i = 2; i < n; i++) {
            leo[i] = leo[i - 1] + leo[i - 2] + add;
        }
        return Arrays.asList(leo);
    }

    public static void main(String[] args) {
        System.out.println("The first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:");
        System.out.println(leonardo(25));
        System.out.println("\nThe first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:");
        System.out.println(leonardo(25, 0, 1, 0));
    }
}







Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Leonardo is

   function Leo
     (N      : Natural;
      Step   : Natural := 1;
      First  : Natural := 1;
      Second : Natural := 1) return Natural   is 
      L : array (0..1) of Natural := (First, Second);
	begin
		for i in 1 .. N loop
			L := (L(1), L(0)+L(1)+Step);
		end loop;
		return L (0);
	end Leo;

begin
   Put_Line ("First 25 Leonardo numbers:");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I)));
   end loop;
   New_Line;
   Put_Line ("First 25 Leonardo numbers with L(0) = 0, L(1) = 1, " &
             "step = 0 (fibonacci numbers):");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I, 0, 0, 1)));
   end loop;
   New_Line;
end Leonardo;
Task: Leonardo numbers







Python: def Leonardo(L_Zero, L_One, Add, Amount):
    terms = [L_Zero,L_One]
    while len(terms) < Amount:
        new = terms[-1] + terms[-2]
        new += Add
        terms.append(new)
    return terms

out = ""
print "First 25 Leonardo numbers:"
for term in Leonardo(1,1,1,25):
    out += str(term) + " "
print out

out = ""
print "Leonardo numbers with fibonacci parameters:"
for term in Leonardo(0,1,0,25):
    out += str(term) + " "
print out





Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Leonardo is

   function Leo
     (N      : Natural;
      Step   : Natural := 1;
      First  : Natural := 1;
      Second : Natural := 1) return Natural   is 
      L : array (0..1) of Natural := (First, Second);
	begin
		for i in 1 .. N loop
			L := (L(1), L(0)+L(1)+Step);
		end loop;
		return L (0);
	end Leo;

begin
   Put_Line ("First 25 Leonardo numbers:");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I)));
   end loop;
   New_Line;
   Put_Line ("First 25 Leonardo numbers with L(0) = 0, L(1) = 1, " &
             "step = 0 (fibonacci numbers):");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I, 0, 0, 1)));
   end loop;
   New_Line;
end Leonardo;
Task: Leonardo numbers








VB: Option Explicit

Private Sub LeonardoNumbers()
Dim L, MyString As String
    Debug.Print "First 25 Leonardo numbers :"
    L = Leo_Numbers(25, 1, 1, 1)
    MyString = Join(L, "; ")
    Debug.Print MyString
    Debug.Print "First 25 Leonardo numbers from 0, 1 with add number = 0"
    L = Leo_Numbers(25, 0, 1, 0)
    MyString = Join(L, "; ")
    Debug.Print MyString
    Debug.Print "If the first prarameter is too small :"
    L = Leo_Numbers(1, 0, 1, 0)
    MyString = Join(L, "; ")
    Debug.Print MyString
End Sub

Public Function Leo_Numbers(HowMany As Long, L_0 As Long, L_1 As Long, Add_Nb As Long)
Dim N As Long, Ltemp

    If HowMany > 1 Then
        ReDim Ltemp(HowMany - 1)
        Ltemp(0) = L_0: Ltemp(1) = L_1
        For N = 2 To HowMany - 1
             Ltemp(N) = Ltemp(N - 1) + Ltemp(N - 2) + Add_Nb
        Next N
    Else
        ReDim Ltemp(0)
        Ltemp(0) = "The first parameter is too small"
    End If
    Leo_Numbers = Ltemp
End Function




Ada: with Ada.Text_IO; use Ada.Text_IO;

procedure Leonardo is

   function Leo
     (N      : Natural;
      Step   : Natural := 1;
      First  : Natural := 1;
      Second : Natural := 1) return Natural   is 
      L : array (0..1) of Natural := (First, Second);
	begin
		for i in 1 .. N loop
			L := (L(1), L(0)+L(1)+Step);
		end loop;
		return L (0);
	end Leo;

begin
   Put_Line ("First 25 Leonardo numbers:");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I)));
   end loop;
   New_Line;
   Put_Line ("First 25 Leonardo numbers with L(0) = 0, L(1) = 1, " &
             "step = 0 (fibonacci numbers):");
   for I in 0 .. 24 loop
      Put (Integer'Image (Leo (I, 0, 0, 1)));
   end loop;
   New_Line;
end Leonardo;
Task: Leonardo numbers

C: #include<stdio.h>

void leonardo(int a,int b,int step,int num){
	
	int i,temp;
	
	printf("First 25 Leonardo numbers : \n");
	
	for(i=1;i<=num;i++){
		if(i==1)
			printf(" %d",a);
		else if(i==2)
			printf(" %d",b);
		else{
			printf(" %d",a+b+step);
			temp = a;
			a = b;
			b = temp+b+step;
		}
	}
}

int main()
{
	int a,b,step;
	
	printf("Enter first two Leonardo numbers and increment step : ");
	
	scanf("%d%d%d",&a,&b,&step);
	
	leonardo(a,b,step,25);
	
	return 0;
}
Task: Leonardo numbers



C#: using System;
using System.Linq;

public class Program
{
    public static void Main() {
        Console.WriteLine(string.Join(" ", Leonardo().Take(25)));
        Console.WriteLine(string.Join(" ", Leonardo(L0: 0, L1: 1, add: 0).Take(25)));
    }

    public static IEnumerable<int> Leonardo(int L0 = 1, int L1 = 1, int add = 1) {
        while (true) {
            yield return L0;
            (L0, L1) = (L1, L0 + L1 + add);
        }
    }
}
Task: Leonardo numbers


C++: #include <iostream>

void leoN( int cnt, int l0 = 1, int l1 = 1, int add = 1 ) {
    int t;
    for( int i = 0; i < cnt; i++ ) {
        std::cout << l0 << " ";
        t = l0 + l1 + add; l0 = l1; l1 = t;
    }
}
int main( int argc, char* argv[] ) {
    std::cout << "Leonardo Numbers: "; leoN( 25 );
    std::cout << "\n\nFibonacci Numbers: "; leoN( 25, 0, 1, 0 );
    return 0;
}
Task: Leonardo numbers





Java: import java.util.Arrays;
import java.util.List;

@SuppressWarnings("SameParameterValue")
public class LeonardoNumbers {
    private static List<Integer> leonardo(int n) {
        return leonardo(n, 1, 1, 1);
    }

    private static List<Integer> leonardo(int n, int l0, int l1, int add) {
        Integer[] leo = new Integer[n];
        leo[0] = l0;
        leo[1] = l1;
        for (int i = 2; i < n; i++) {
            leo[i] = leo[i - 1] + leo[i - 2] + add;
        }
        return Arrays.asList(leo);
    }

    public static void main(String[] args) {
        System.out.println("The first 25 Leonardo numbers with L[0] = 1, L[1] = 1 and add number = 1 are:");
        System.out.println(leonardo(25));
        System.out.println("\nThe first 25 Leonardo numbers with L[0] = 0, L[1] = 1 and add number = 0 are:");
        System.out.println(leonardo(25, 0, 1, 0));
    }
}