WeixiangYan/CodeTransOcean huggingface dataset:
Task: Five weekends

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

static const char *months[] = {"January", "February", "March", "April", "May",
    "June", "July", "August", "September", "October", "November", "December"};
static int long_months[] = {0, 2, 4, 6, 7, 9, 11};

int main() {
    int n = 0, y, i, m;
    struct tm t = {0};
    printf("Months with five weekends:\n");
    for (y = 1900; y <= 2100; y++) {
        for (i = 0; i < 7; i++) {
            m = long_months[i];
            t.tm_year = y-1900;
	    t.tm_mon = m;
	    t.tm_mday = 1;
            if (mktime(&t) == -1) { 
                printf("Error: %d %s\n", y, months[m]);
                continue;
            }
            if (t.tm_wday == 5) { 
                printf("  %d %s\n", y, months[m]);
                n++;
            }
        }
    }
    printf("%d total\n", n);
    return 0;
}









COBOL:        program-id. five-we.
       data division.
       working-storage section.
       1 wk binary.
        2 int-date pic 9(8).
        2 dow pic 9(4).
        2 friday pic 9(4) value 5.
        2 mo-sub pic 9(4).
        2 months-with-5 pic 9(4) value 0.
        2 years-no-5 pic 9(4) value 0.
        2 5-we-flag pic 9(4) value 0.
         88 5-we-true value 1 when false 0.
       1 31-day-mos pic 9(14) value 01030507081012.
       1 31-day-table redefines 31-day-mos.
        2 mo-no occurs 7 pic 99.
       1 cal-date.
        2 yr pic 9(4).
        2 mo pic 9(2).
        2 da pic 9(2) value 1.
       procedure division.
           perform varying yr from 1900 by 1
           until yr > 2100
               set 5-we-true to false
               perform varying mo-sub from 1 by 1
               until mo-sub > 7
                   move mo-no (mo-sub) to mo
                   compute int-date = function
                       integer-of-date (function numval (cal-date))
                   compute dow = function mod
                       ((int-date - 1) 7) + 1
                   if dow = friday
                       perform output-date
                       add 1 to months-with-5
                       set 5-we-true to true
                   end-if
               end-perform
               if not 5-we-true
                   add 1 to years-no-5
               end-if
           end-perform
           perform output-counts
           stop run
           .

       output-counts.
           display "Months with 5 weekends: " months-with-5
           display "Years without 5 weekends: " years-no-5
           .

       output-date.
           display yr "-" mo
           .
       end program five-we.
Task: Five weekends



C#: using System;

namespace _5_Weekends
{
    class Program
    {
        const int FIRST_YEAR = 1900;
        const int LAST_YEAR = 2100;
        static int[] _31_MONTHS = { 1, 3, 5, 7, 8, 10, 12 }; 

        static void Main(string[] args)
        {
            int totalNum = 0;
            int totalNo5Weekends = 0;

            for (int year = FIRST_YEAR; year <= LAST_YEAR; year++)
            {
                bool has5Weekends = false;

                foreach (int month in _31_MONTHS)
                {
                    DateTime firstDay = new DateTime(year, month, 1);
                    if (firstDay.DayOfWeek == DayOfWeek.Friday)
                    {
                        totalNum++;
                        has5Weekends = true;
                        Console.WriteLine(firstDay.ToString("yyyy - MMMM"));
                    }
                }

                if (!has5Weekends) totalNo5Weekends++;
            }
            Console.WriteLine("Total 5-weekend months between {0} and {1}: {2}", FIRST_YEAR, LAST_YEAR, totalNum);
            Console.WriteLine("Total number of years with no 5-weekend months {0}", totalNo5Weekends);
        }
    }
}







COBOL:        program-id. five-we.
       data division.
       working-storage section.
       1 wk binary.
        2 int-date pic 9(8).
        2 dow pic 9(4).
        2 friday pic 9(4) value 5.
        2 mo-sub pic 9(4).
        2 months-with-5 pic 9(4) value 0.
        2 years-no-5 pic 9(4) value 0.
        2 5-we-flag pic 9(4) value 0.
         88 5-we-true value 1 when false 0.
       1 31-day-mos pic 9(14) value 01030507081012.
       1 31-day-table redefines 31-day-mos.
        2 mo-no occurs 7 pic 99.
       1 cal-date.
        2 yr pic 9(4).
        2 mo pic 9(2).
        2 da pic 9(2) value 1.
       procedure division.
           perform varying yr from 1900 by 1
           until yr > 2100
               set 5-we-true to false
               perform varying mo-sub from 1 by 1
               until mo-sub > 7
                   move mo-no (mo-sub) to mo
                   compute int-date = function
                       integer-of-date (function numval (cal-date))
                   compute dow = function mod
                       ((int-date - 1) 7) + 1
                   if dow = friday
                       perform output-date
                       add 1 to months-with-5
                       set 5-we-true to true
                   end-if
               end-perform
               if not 5-we-true
                   add 1 to years-no-5
               end-if
           end-perform
           perform output-counts
           stop run
           .

       output-counts.
           display "Months with 5 weekends: " months-with-5
           display "Years without 5 weekends: " years-no-5
           .

       output-date.
           display yr "-" mo
           .
       end program five-we.
Task: Five weekends





Java: import java.util.Calendar;
import java.util.GregorianCalendar;

public class FiveFSS {
    private static boolean[] years = new boolean[201];
    private static int[] month31 = {Calendar.JANUARY, Calendar.MARCH, Calendar.MAY,
        Calendar.JULY, Calendar.AUGUST, Calendar.OCTOBER, Calendar.DECEMBER};

    public static void main(String[] args) {
        StringBuilder months = new StringBuilder();
        int numMonths = 0;
        for (int year = 1900; year <= 2100; year++) {
            for (int month : month31) {
                Calendar date = new GregorianCalendar(year, month, 1);
                if (date.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY) {
                    years[year - 1900] = true;
                    numMonths++;
                    
                    months.append((date.get(Calendar.MONTH) + 1) + "-" + year +"\n");
                }
            }
        }
        System.out.println("There are "+numMonths+" months with five weekends from 1900 through 2100:");
        System.out.println(months);
        System.out.println("Years with no five-weekend months:");
        for (int year = 1900; year <= 2100; year++) {
            if(!years[year - 1900]){
                System.out.println(year);
            }
        }
    }
}





COBOL:        program-id. five-we.
       data division.
       working-storage section.
       1 wk binary.
        2 int-date pic 9(8).
        2 dow pic 9(4).
        2 friday pic 9(4) value 5.
        2 mo-sub pic 9(4).
        2 months-with-5 pic 9(4) value 0.
        2 years-no-5 pic 9(4) value 0.
        2 5-we-flag pic 9(4) value 0.
         88 5-we-true value 1 when false 0.
       1 31-day-mos pic 9(14) value 01030507081012.
       1 31-day-table redefines 31-day-mos.
        2 mo-no occurs 7 pic 99.
       1 cal-date.
        2 yr pic 9(4).
        2 mo pic 9(2).
        2 da pic 9(2) value 1.
       procedure division.
           perform varying yr from 1900 by 1
           until yr > 2100
               set 5-we-true to false
               perform varying mo-sub from 1 by 1
               until mo-sub > 7
                   move mo-no (mo-sub) to mo
                   compute int-date = function
                       integer-of-date (function numval (cal-date))
                   compute dow = function mod
                       ((int-date - 1) 7) + 1
                   if dow = friday
                       perform output-date
                       add 1 to months-with-5
                       set 5-we-true to true
                   end-if
               end-perform
               if not 5-we-true
                   add 1 to years-no-5
               end-if
           end-perform
           perform output-counts
           stop run
           .

       output-counts.
           display "Months with 5 weekends: " months-with-5
           display "Years without 5 weekends: " years-no-5
           .

       output-date.
           display yr "-" mo
           .
       end program five-we.
Task: Five weekends







Python: from datetime import (date,
                      timedelta)

DAY = timedelta(days=1)
START, STOP = date(1900, 1, 1), date(2101, 1, 1)
WEEKEND = {6, 5, 4}  
FMT = '%Y %m(%B)'


def five_weekends_per_month(start: date = START,
                            stop: date = STOP) -> list[date]:
    
    current_date = start
    last_month = weekend_days = 0
    five_weekends = []
    while current_date < stop:
        if current_date.month != last_month:
            if weekend_days >= 15:
                five_weekends.append(current_date - DAY)
            weekend_days = 0
            last_month = current_date.month
        if current_date.weekday() in WEEKEND:
            weekend_days += 1
        current_date += DAY
    return five_weekends


dates = five_weekends_per_month()
indent = '  '
print(f"There are {len(dates)} months of which the first and last five are:")
print(indent + ('\n' + indent).join(d.strftime(FMT) for d in dates[:5]))
print(indent + '...')
print(indent + ('\n' + indent).join(d.strftime(FMT) for d in dates[-5:]))

years_without_five_weekends_months = (STOP.year - START.year
                                      - len({d.year for d in dates}))
print(f"\nThere are {years_without_five_weekends_months} years in the "
      f"range that do not have months with five weekends")



COBOL:        program-id. five-we.
       data division.
       working-storage section.
       1 wk binary.
        2 int-date pic 9(8).
        2 dow pic 9(4).
        2 friday pic 9(4) value 5.
        2 mo-sub pic 9(4).
        2 months-with-5 pic 9(4) value 0.
        2 years-no-5 pic 9(4) value 0.
        2 5-we-flag pic 9(4) value 0.
         88 5-we-true value 1 when false 0.
       1 31-day-mos pic 9(14) value 01030507081012.
       1 31-day-table redefines 31-day-mos.
        2 mo-no occurs 7 pic 99.
       1 cal-date.
        2 yr pic 9(4).
        2 mo pic 9(2).
        2 da pic 9(2) value 1.
       procedure division.
           perform varying yr from 1900 by 1
           until yr > 2100
               set 5-we-true to false
               perform varying mo-sub from 1 by 1
               until mo-sub > 7
                   move mo-no (mo-sub) to mo
                   compute int-date = function
                       integer-of-date (function numval (cal-date))
                   compute dow = function mod
                       ((int-date - 1) 7) + 1
                   if dow = friday
                       perform output-date
                       add 1 to months-with-5
                       set 5-we-true to true
                   end-if
               end-perform
               if not 5-we-true
                   add 1 to years-no-5
               end-if
           end-perform
           perform output-counts
           stop run
           .

       output-counts.
           display "Months with 5 weekends: " months-with-5
           display "Years without 5 weekends: " years-no-5
           .

       output-date.
           display yr "-" mo
           .
       end program five-we.
Task: Five weekends








VB: Option Explicit

Sub Main()
Dim y As Long, m As Long, t As String, cpt As Long, cptm As Long
    For y = 1900 To 2100
        t = vbNullString
        For m = 1 To 12 Step 2
            If m = 9 Then m = 8
            If Weekday(DateSerial(y, m, 1)) = vbFriday Then
                t = t & ", " & m
                cptm = cptm + 1
            End If
        Next
        If t <> "" Then
            Debug.Print y & t
        Else
            cpt = cpt + 1
        End If
    Next
    Debug.Print "There is " & cptm & " months with five full weekends from the year 1900 through 2100"
    Debug.Print "There is " & cpt & " years which don
End Sub


COBOL:        program-id. five-we.
       data division.
       working-storage section.
       1 wk binary.
        2 int-date pic 9(8).
        2 dow pic 9(4).
        2 friday pic 9(4) value 5.
        2 mo-sub pic 9(4).
        2 months-with-5 pic 9(4) value 0.
        2 years-no-5 pic 9(4) value 0.
        2 5-we-flag pic 9(4) value 0.
         88 5-we-true value 1 when false 0.
       1 31-day-mos pic 9(14) value 01030507081012.
       1 31-day-table redefines 31-day-mos.
        2 mo-no occurs 7 pic 99.
       1 cal-date.
        2 yr pic 9(4).
        2 mo pic 9(2).
        2 da pic 9(2) value 1.
       procedure division.
           perform varying yr from 1900 by 1
           until yr > 2100
               set 5-we-true to false
               perform varying mo-sub from 1 by 1
               until mo-sub > 7
                   move mo-no (mo-sub) to mo
                   compute int-date = function
                       integer-of-date (function numval (cal-date))
                   compute dow = function mod
                       ((int-date - 1) 7) + 1
                   if dow = friday
                       perform output-date
                       add 1 to months-with-5
                       set 5-we-true to true
                   end-if
               end-perform
               if not 5-we-true
                   add 1 to years-no-5
               end-if
           end-perform
           perform output-counts
           stop run
           .

       output-counts.
           display "Months with 5 weekends: " months-with-5
           display "Years without 5 weekends: " years-no-5
           .

       output-date.
           display yr "-" mo
           .
       end program five-we.
Task: Five weekends







Python: from datetime import timedelta, date

DAY     = timedelta(days=1)
START, STOP = date(1900, 1, 1), date(2101, 1, 1)
WEEKEND = {6, 5, 4}     
FMT     = '%Y %m(%B)'

def fiveweekendspermonth(start=START, stop=STOP):
    'Compute months with five weekends between dates'
    
    when = start
    lastmonth = weekenddays = 0
    fiveweekends = []
    while when < stop:
        year, mon, _mday, _h, _m, _s, wday, _yday, _isdst = when.timetuple()
        if mon != lastmonth:
            if weekenddays >= 15:
                fiveweekends.append(when - DAY)
            weekenddays = 0
            lastmonth = mon
        if wday in WEEKEND:
            weekenddays += 1
        when += DAY
    return fiveweekends

dates = fiveweekendspermonth()
indent = '  '
print('There are %s months of which the first and last five are:' % len(dates))
print(indent +('\n'+indent).join(d.strftime(FMT) for d in dates[:5]))
print(indent +'...')
print(indent +('\n'+indent).join(d.strftime(FMT) for d in dates[-5:]))

print('\nThere are %i years in the range that do not have months with five weekends'
      % len(set(range(START.year, STOP.year)) - {d.year for d in dates}))
Task: Bell numbers

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


size_t bellIndex(int row, int col) {
    return row * (row - 1) / 2 + col;
}

int getBell(int *bellTri, int row, int col) {
    size_t index = bellIndex(row, col);
    return bellTri[index];
}

void setBell(int *bellTri, int row, int col, int value) {
    size_t index = bellIndex(row, col);
    bellTri[index] = value;
}

int *bellTriangle(int n) {
    size_t length = n * (n + 1) / 2;
    int *tri = calloc(length, sizeof(int));
    int i, j;

    setBell(tri, 1, 0, 1);
    for (i = 2; i <= n; ++i) {
        setBell(tri, i, 0, getBell(tri, i - 1, i - 2));
        for (j = 1; j < i; ++j) {
            int value = getBell(tri, i, j - 1) + getBell(tri, i - 1, j - 1);
            setBell(tri, i, j, value);
        }
    }

    return tri;
}

int main() {
    const int rows = 15;
    int *bt = bellTriangle(rows);
    int i, j;

    printf("First fifteen Bell numbers:\n");
    for (i = 1; i <= rows; ++i) {
        printf("%2d: %d\n", i, getBell(bt, i, 0));
    }

    printf("\nThe first ten rows of Bell's triangle:\n");
    for (i = 1; i <= 10; ++i) {
        printf("%d", getBell(bt, i, 0));
        for (j = 1; j < i; ++j) {
            printf(", %d", getBell(bt, i, j));
        }
        printf("\n");
    }

    free(bt);
    return 0;
}











Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
	type Bell_Triangle is array(Positive range <>, Positive range <>) of Natural;
	
	
	procedure Print_Rows (Row : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Row in Triangle'Range(1) then
				for I in Triangle'First(1) .. Row loop
					Put_Line (Triangle (I, 1)'Image);
				end loop;
			end if;
	end Print_Rows;
	
	procedure Print_Triangle (Num : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Num in Triangle'Range then
				for I in Triangle'First(1) .. Num loop
					for J in Triangle'First(2) .. Num loop
						if Triangle (I, J) /= 0 then
							Put (Triangle (I, J)'Image);
						end if;
					end loop;
					New_Line;
				end loop;
			end if;
	end Print_Triangle;
	
	procedure Bell_Numbers is
		Triangle : Bell_Triangle(1..15, 1..15) := (Others => (Others => 0));
		Temp     : Positive := 1;
		begin
			
			Triangle (1, 1) := 1;
			
			for I in Triangle'First(1) + 1 .. Triangle'Last(1) loop
				Triangle (I, 1) := Temp;
				
				for J in Triangle'First(2) .. Triangle'Last(2) - 1 loop
					if Triangle (I - 1, J) /= 0 then
						Triangle (I, J + 1) := Triangle (I, J) + Triangle (I - 1, J);
					else
						Temp := Triangle (I, J);
						exit;
					end if;
				end loop;
			end loop;
			
			Put_Line ("First 15 Bell numbers:");
			Print_Rows (15, Triangle);
			
			New_Line;
			
			Put_Line ("First 10 rows of the Bell triangle:");
			Print_Triangle (10, Triangle);
	end Bell_Numbers;
begin
	Bell_Numbers;
end Main;
Task: Bell numbers


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

#ifdef HAVE_BOOST
#include <boost/multiprecision/cpp_int.hpp>
typedef boost::multiprecision::cpp_int integer;
#else
typedef unsigned int integer;
#endif

auto make_bell_triangle(int n) {
    std::vector<std::vector<integer>> bell(n);
    for (int i = 0; i < n; ++i)
        bell[i].assign(i + 1, 0);
    bell[0][0] = 1;
    for (int i = 1; i < n; ++i) {
        std::vector<integer>& row = bell[i];
        std::vector<integer>& prev_row = bell[i - 1];
        row[0] = prev_row[i - 1];
        for (int j = 1; j <= i; ++j)
            row[j] = row[j - 1] + prev_row[j - 1];
    }
    return bell;
}

int main() {
#ifdef HAVE_BOOST
    const int size = 50;
#else
    const int size = 15;
#endif
    auto bell(make_bell_triangle(size));
    
    const int limit = 15;
    std::cout << "First " << limit << " Bell numbers:\n";
    for (int i = 0; i < limit; ++i)
        std::cout << bell[i][0] << '\n';

#ifdef HAVE_BOOST
    std::cout << "\n50th Bell number is " << bell[49][0] << "\n\n";
#endif

    std::cout << "First 10 rows of the Bell triangle:\n";
    for (int i = 0; i < 10; ++i) {
        std::cout << bell[i][0];
        for (int j = 1; j <= i; ++j)
            std::cout << ' ' << bell[i][j];
        std::cout << '\n';
    }
    return 0;
}










Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
	type Bell_Triangle is array(Positive range <>, Positive range <>) of Natural;
	
	
	procedure Print_Rows (Row : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Row in Triangle'Range(1) then
				for I in Triangle'First(1) .. Row loop
					Put_Line (Triangle (I, 1)'Image);
				end loop;
			end if;
	end Print_Rows;
	
	procedure Print_Triangle (Num : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Num in Triangle'Range then
				for I in Triangle'First(1) .. Num loop
					for J in Triangle'First(2) .. Num loop
						if Triangle (I, J) /= 0 then
							Put (Triangle (I, J)'Image);
						end if;
					end loop;
					New_Line;
				end loop;
			end if;
	end Print_Triangle;
	
	procedure Bell_Numbers is
		Triangle : Bell_Triangle(1..15, 1..15) := (Others => (Others => 0));
		Temp     : Positive := 1;
		begin
			
			Triangle (1, 1) := 1;
			
			for I in Triangle'First(1) + 1 .. Triangle'Last(1) loop
				Triangle (I, 1) := Temp;
				
				for J in Triangle'First(2) .. Triangle'Last(2) - 1 loop
					if Triangle (I - 1, J) /= 0 then
						Triangle (I, J + 1) := Triangle (I, J) + Triangle (I - 1, J);
					else
						Temp := Triangle (I, J);
						exit;
					end if;
				end loop;
			end loop;
			
			Put_Line ("First 15 Bell numbers:");
			Print_Rows (15, Triangle);
			
			New_Line;
			
			Put_Line ("First 10 rows of the Bell triangle:");
			Print_Triangle (10, Triangle);
	end Bell_Numbers;
begin
	Bell_Numbers;
end Main;
Task: Bell numbers




Go: package main

import (
    "fmt"
    "math/big"
)

func bellTriangle(n int) [][]*big.Int {
    tri := make([][]*big.Int, n)
    for i := 0; i < n; i++ {
        tri[i] = make([]*big.Int, i)
        for j := 0; j < i; j++ {
            tri[i][j] = new(big.Int)
        }
    }
    tri[1][0].SetUint64(1)
    for i := 2; i < n; i++ {
        tri[i][0].Set(tri[i-1][i-2])
        for j := 1; j < i; j++ {
            tri[i][j].Add(tri[i][j-1], tri[i-1][j-1])
        }
    }
    return tri
}

func main() {
    bt := bellTriangle(51)
    fmt.Println("First fifteen and fiftieth Bell numbers:")
    for i := 1; i <= 15; i++ {
        fmt.Printf("%2d: %d\n", i, bt[i][0])
    }
    fmt.Println("50:", bt[50][0])
    fmt.Println("\nThe first ten rows of Bell's triangle:")
    for i := 1; i <= 10; i++ {
        fmt.Println(bt[i])
    }    
}








Ada: with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
	type Bell_Triangle is array(Positive range <>, Positive range <>) of Natural;
	
	
	procedure Print_Rows (Row : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Row in Triangle'Range(1) then
				for I in Triangle'First(1) .. Row loop
					Put_Line (Triangle (I, 1)'Image);
				end loop;
			end if;
	end Print_Rows;
	
	procedure Print_Triangle (Num : in Positive; Triangle : in Bell_Triangle) is
		begin
			if Num in Triangle'Range then
				for I in Triangle'First(1) .. Num loop
					for J in Triangle'First(2) .. Num loop
						if Triangle (I, J) /= 0 then
							Put (Triangle (I, J)'Image);
						end if;
					end loop;
					New_Line;
				end loop;
			end if;
	end Print_Triangle;
	
	procedure Bell_Numbers is
		Triangle : Bell_Triangle(1..15, 1..15) := (Others => (Others => 0));
		Temp     : Positive := 1;
		begin
			
			Triangle (1, 1) := 1;
			
			for I in Triangle'First(1) + 1 .. Triangle'Last(1) loop
				Triangle (I, 1) := Temp;
				
				for J in Triangle'First(2) .. Triangle'Last(2) - 1 loop
					if Triangle (I - 1, J) /= 0 then
						Triangle (I, J + 1) := Triangle (I, J) + Triangle (I - 1, J);
					else
						Temp := Triangle (I, J);
						exit;
					end if;
				end loop;
			end loop;
			
			Put_Line ("First 15 Bell numbers:");
			Print_Rows (15, Triangle);
			
			New_Line;
			
			Put_Line ("First 10 rows of the Bell triangle:");
			Print_Triangle (10, Triangle);
	end Bell_Numbers;
begin
	Bell_Numbers;
end Main;