Data update
This commit is contained in:
parent
4bb20c9b71
commit
cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions
23
Task/Five-weekends/Ada/five-weekends.adb
Normal file
23
Task/Five-weekends/Ada/five-weekends.adb
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
with Ada.Text_IO; use Ada.Text_IO;
|
||||
with Ada.Calendar.Formatting; use Ada.Calendar;
|
||||
|
||||
use Ada.Calendar.Formatting;
|
||||
|
||||
procedure Five_Weekends is
|
||||
Months : Natural := 0;
|
||||
begin
|
||||
for Year in Year_Number range 1901..2100 loop
|
||||
for Month in Month_Number range 1..12 loop
|
||||
begin
|
||||
if Day_Of_Week (Formatting.Time_Of (Year, Month, 31)) = Sunday then
|
||||
Put_Line (Year_Number'Image (Year) & Month_Number'Image (Month));
|
||||
Months := Months + 1;
|
||||
end if;
|
||||
exception
|
||||
when Time_Error =>
|
||||
null;
|
||||
end;
|
||||
end loop;
|
||||
end loop;
|
||||
Put_Line ("Number of months:" & Integer'Image (Months));
|
||||
end Five_Weekends;
|
||||
41
Task/Five-weekends/AutoIt/five-weekends.au3
Normal file
41
Task/Five-weekends/AutoIt/five-weekends.au3
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#include <Date.au3>
|
||||
#include <Array.au3>
|
||||
$array = Five_weekends(1)
|
||||
_ArrayDisplay($array)
|
||||
$array = Five_weekends(2)
|
||||
_ArrayDisplay($array)
|
||||
$array = Five_weekends(3)
|
||||
_ArrayDisplay($array)
|
||||
|
||||
Func Five_weekends($ret = 1)
|
||||
If $ret < 1 Or $ret > 3 Then Return SetError(1, 0, 0)
|
||||
Local $avDateArray[1]
|
||||
Local $avYearArray[1]
|
||||
Local $avMonthArray[1]
|
||||
For $iYear = 1900 To 2100
|
||||
Local $checkyear = False
|
||||
For $iMonth = 1 To 12
|
||||
If _DateDaysInMonth($iYear, $iMonth) <> 31 Then ContinueLoop ; Month has less then 31 Days
|
||||
If _DateToDayOfWeek($iYear, $iMonth, "01") <> 6 Then ContinueLoop ;First Day is not a Friday
|
||||
_ArrayAdd($avMonthArray, $iYear & "-" & _DateToMonth($iMonth))
|
||||
$checkyear = True
|
||||
For $s = 1 To 31
|
||||
Local $Date = _DateToDayOfWeek($iYear, $iMonth, $s)
|
||||
If $Date = 6 Or $Date = 7 Or $Date = 1 Then ; if Date is Friday, Saturday or Sunday
|
||||
_ArrayAdd($avDateArray, $iYear & "\" & StringFormat("%02d", $iMonth) & "\" & StringFormat("%02d", $s))
|
||||
EndIf
|
||||
Next
|
||||
Next
|
||||
If Not $checkyear Then _ArrayAdd($avYearArray, $iYear)
|
||||
Next
|
||||
$avDateArray[0] = UBound($avDateArray) - 1
|
||||
$avYearArray[0] = UBound($avYearArray) - 1
|
||||
$avMonthArray[0] = UBound($avMonthArray) - 1
|
||||
If $ret = 1 Then
|
||||
Return $avDateArray
|
||||
ElseIf $ret = 2 Then
|
||||
Return $avYearArray
|
||||
ElseIf $ret = 3 Then
|
||||
Return $avMonthArray
|
||||
EndIf
|
||||
EndFunc ;==>Five_weekends
|
||||
53
Task/Five-weekends/COBOL/five-weekends.cob
Normal file
53
Task/Five-weekends/COBOL/five-weekends.cob
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
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.
|
||||
13
Task/Five-weekends/Crystal/five-weekends.cr
Normal file
13
Task/Five-weekends/Crystal/five-weekends.cr
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
years = (1900..2100).to_a
|
||||
long_months = [1, 3, 5, 7, 8, 10, 12]
|
||||
five_wknd_months = years.cartesian_product(long_months).select {|year, month|
|
||||
Time.utc(year, month, 1).friday?
|
||||
}
|
||||
puts "#{five_wknd_months.size} months with 5 weekends:"
|
||||
puts five_wknd_months.first(10).map {|y, m| "#{m}/#{y}" }.join(" ")
|
||||
puts " ..."
|
||||
puts five_wknd_months.last(10).map {|y, m| "#{m}/#{y}" }.join(" ")
|
||||
puts
|
||||
years_without = years - five_wknd_months.map {|year, _| year }
|
||||
puts "#{years_without.size} years without 5-weekend-months:"
|
||||
puts years_without.join(" ")
|
||||
|
|
@ -18,12 +18,17 @@ func weekday year month day .
|
|||
mdays[] = [ 31 28 31 30 31 30 31 31 30 31 30 31 ]
|
||||
mon$[] = [ "Jan" "Feb" "Mar" "Apr" "May" "Jun" "Jul" "Aug" "Sep" "Oct" "Nov" "Dec" ]
|
||||
#
|
||||
for year = 1900 to 2100
|
||||
for m to 12
|
||||
if mdays[m] = 31 and weekday year m 1 = 6
|
||||
print year & "-" & mon$[m]
|
||||
sum += 1
|
||||
for year = 1900 to 2100 : for m to 12
|
||||
if mdays[m] = 31 and weekday year m 1 = 6
|
||||
cnt += 1
|
||||
if cnt <= 5 or cnt >= 197
|
||||
print year & "-" & mon$[m] & " "
|
||||
if cnt = 5
|
||||
print "."
|
||||
print "."
|
||||
.
|
||||
.
|
||||
.
|
||||
.
|
||||
print "Total : " & sum
|
||||
print ""
|
||||
print "Total : " & cnt
|
||||
|
|
|
|||
42
Task/Five-weekends/Euphoria/five-weekends.eu
Normal file
42
Task/Five-weekends/Euphoria/five-weekends.eu
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
--Five Weekend task from Rosetta Code wiki
|
||||
--User:Lnettnay
|
||||
|
||||
include std/datetime.e
|
||||
|
||||
atom numbermonths = 0
|
||||
sequence longmonths = {1, 3, 5, 7, 8, 10, 12}
|
||||
sequence yearsmonths = {}
|
||||
atom none = 0
|
||||
datetime dt
|
||||
|
||||
for year = 1900 to 2100 do
|
||||
atom flag = 0
|
||||
for month = 1 to length(longmonths) do
|
||||
dt = new(year, longmonths[month], 1)
|
||||
if weeks_day(dt) = 6 then --Friday is day 6
|
||||
flag = 1
|
||||
numbermonths += 1
|
||||
yearsmonths = append(yearsmonths, {year, longmonths[month]})
|
||||
end if
|
||||
end for
|
||||
|
||||
if flag = 0 then
|
||||
none += 1
|
||||
end if
|
||||
end for
|
||||
|
||||
puts(1, "Number of months with five full weekends from 1900 to 2100 = ")
|
||||
? numbermonths
|
||||
|
||||
puts(1, "First five and last five years, months\n")
|
||||
|
||||
for count = 1 to 5 do
|
||||
? yearsmonths[count]
|
||||
end for
|
||||
|
||||
for count = length(yearsmonths) - 4 to length(yearsmonths) do
|
||||
? yearsmonths[count]
|
||||
end for
|
||||
|
||||
puts(1, "Number of years that have no months with five full weekends = ")
|
||||
? none
|
||||
38
Task/Five-weekends/Pluto/five-weekends.pluto
Normal file
38
Task/Five-weekends/Pluto/five-weekends.pluto
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
local fmt = require "fmt"
|
||||
|
||||
local dates = {}
|
||||
local years = {}
|
||||
for y = 1900, 2100 do
|
||||
local has_five = false
|
||||
for m = 1, 12 do
|
||||
local fri = 0
|
||||
local sat = 0
|
||||
local sun = 0
|
||||
for d = 1, fmt.month(m, y) do
|
||||
local t = os.time({year = y, month = m, day = d})
|
||||
local dow = tonumber(os.date("%u", t))
|
||||
if dow == 5 then
|
||||
fri += 1
|
||||
elseif dow == 6 then
|
||||
sat += 1
|
||||
elseif dow == 7 then
|
||||
sun += 1
|
||||
end
|
||||
end
|
||||
local fd = os.date("%b - %Y", os.time({year = y, month = m, day = 1}))
|
||||
if fri == 5 and sat == 5 and sun == 5 then
|
||||
dates:insert(fd)
|
||||
has_five = true
|
||||
end
|
||||
end
|
||||
if !has_five then years:insert(y) end
|
||||
end
|
||||
|
||||
print("Between 1900 and 2100:-")
|
||||
print($" There are {#dates} months that have five full weekends.")
|
||||
print(" The first 5 are:")
|
||||
for i = 1, 5 do print($" {dates[i]}") end
|
||||
print(" and the last 5 are:")
|
||||
for i = -4, 0 do print($" {dates[#dates + i]}") end
|
||||
print($"\n There are {#years} years that do not have at least one five-weekend month, namely:")
|
||||
fmt.tprint(" %d", years, 10)
|
||||
20
Task/Five-weekends/PowerShell/five-weekends.ps1
Normal file
20
Task/Five-weekends/PowerShell/five-weekends.ps1
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
$fiveWeekends = @()
|
||||
$yearsWithout = @()
|
||||
foreach ($y in 1900..2100) {
|
||||
$hasFiveWeekendMonth = $FALSE
|
||||
foreach ($m in @("01","03","05","07","08",10,12)) {
|
||||
if ((Get-Date "$y-$m-1").DayOfWeek -eq "Friday") {
|
||||
$fiveWeekends += "$y-$m"
|
||||
$hasFiveWeekendMonth = $TRUE
|
||||
}
|
||||
}
|
||||
if ($hasFiveWeekendMonth -eq $FALSE) {
|
||||
$yearsWithout += $y
|
||||
}
|
||||
}
|
||||
Write-Output "Between the years 1900 and 2100, inclusive, there are $($fiveWeekends.count) months with five full weekends:"
|
||||
Write-Output "$($fiveWeekends[0..4] -join ","),...,$($fiveWeekends[-5..-1] -join ",")"
|
||||
|
||||
Write-Output ""
|
||||
Write-Output "Extra Credit: these $($yearsWithout.count) years have no such month:"
|
||||
Write-Output ($yearsWithout -join ",")
|
||||
64
Task/Five-weekends/Rebol/five-weekends.rebol
Normal file
64
Task/Five-weekends/Rebol/five-weekends.rebol
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
Rebol [
|
||||
title: "Rosetta code: Five weekends"
|
||||
file: %Five_weekends.r3
|
||||
url: https://rosettacode.org/wiki/Five_weekends
|
||||
]
|
||||
|
||||
five-weekends: function/with [
|
||||
"Show all months that have five full weekends."
|
||||
start [integer!] "Start year"
|
||||
end [integer!] "End year"
|
||||
][
|
||||
boring-years: total-fw-months: awesome-years: 0
|
||||
for year start end 1 [
|
||||
fw-months: clear []
|
||||
;; A month has five weekends when its first day is a Saturday (weekday 7)
|
||||
foreach month long-months [
|
||||
if 1 = get-day year month 1 6 [
|
||||
++ total-fw-months
|
||||
append fw-months month-names/:month
|
||||
]
|
||||
]
|
||||
prin ajoin [as-yellow year ": "]
|
||||
print switch count: length? fw-months [
|
||||
0 [
|
||||
++ boring-years
|
||||
as-red "Boring year!"
|
||||
]
|
||||
1 [
|
||||
ajoin ["1 month: " fw-months]
|
||||
]
|
||||
2 [
|
||||
++ awesome-years
|
||||
ajoin [as-green count " months: " ajoin/with fw-months ", "]
|
||||
]
|
||||
]
|
||||
]
|
||||
print-horizontal-line
|
||||
print ["Total five-weekend months: " total-fw-months]
|
||||
print ["Total years with no five-weekend months: " boring-years ]
|
||||
print ["Total years with 2+ five-weekend months: " awesome-years]
|
||||
][
|
||||
;; Return the day-of-month for the Nth weekday in a given month,
|
||||
;; or NONE if that occurrence falls outside the month.
|
||||
get-day: function [
|
||||
year [integer!]
|
||||
month [integer!]
|
||||
week [integer!]
|
||||
weekday [integer!]
|
||||
][
|
||||
date: to-date reduce [1 month year] ; first-of-month
|
||||
;; Rebol weekday is Mon=1 .. Sun=7; shift to Sun=1 .. Sat=7
|
||||
weekday-1st: (date/weekday + 1) % 7
|
||||
;; Days from the 1st to the target weekday in the requested week
|
||||
offset: (week - 1) * 7 + (weekday - weekday-1st)
|
||||
target-date: date + offset
|
||||
;; Return the day number only if it still falls within the same month or none
|
||||
if target-date/month = month [target-date/day]
|
||||
]
|
||||
month-names: system/locale/months
|
||||
;; Months with 31 days are the only ones that can hold five full weekends
|
||||
long-months: [1 3 5 7 8 10 12]
|
||||
]
|
||||
|
||||
five-weekends 1900 2100
|
||||
26
Task/Five-weekends/V-(Vlang)/five-weekends.v
Normal file
26
Task/Five-weekends/V-(Vlang)/five-weekends.v
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import math
|
||||
|
||||
fn main() {
|
||||
mut sum, mut oldsum, mut leap := 0, 0, 0
|
||||
mut m, mut x := f64(0), f64(0)
|
||||
mut month := []int{len: 12, init: index}
|
||||
mo := [4,0,0,3,5,1,3,6,2,4,0,2]
|
||||
mon := [31,28,31,30,31,30,31,31,30,31,30,31]
|
||||
mont := ["January","February","March","April","May","June",
|
||||
"July","August","September","October","November","December"]
|
||||
for year in 1900..2101 {
|
||||
if year < 2100 {leap = year - 1900} else {leap = year - 1904}
|
||||
m = ((year - 1900) % 7) + math.fmod(leap / 4, 7)
|
||||
oldsum = sum
|
||||
for n in 0..12 {
|
||||
month[n] = int(math.fmod(mo[n] + m, 7))
|
||||
x = math.fmod(month[n] + 1, 7)
|
||||
if x == 2 && mon[n] == 31 {
|
||||
sum += 1
|
||||
println("${year} - ${mont[n]}")
|
||||
}
|
||||
}
|
||||
if sum == oldsum {println("${year} - (none)")}
|
||||
}
|
||||
println("Total: ${sum}")
|
||||
}
|
||||
11
Task/Five-weekends/VBScript/five-weekends.vbs
Normal file
11
Task/Five-weekends/VBScript/five-weekends.vbs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
For y = 1900 To 2100
|
||||
For m = 1 To 12
|
||||
d = DateSerial(y, m + 1, 1) - 1
|
||||
If Day(d) = 31 And Weekday(d) = vbSunday Then
|
||||
WScript.Echo y & ", " & MonthName(m)
|
||||
i = i + 1
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
WScript.Echo vbCrLf & "Total = " & i & " months"
|
||||
Loading…
Add table
Add a link
Reference in a new issue