Five weekends: Difference between revisions

Added Easylang
(New post using C++20 syntax and without using external libraries, unlike an existing post.)
(Added Easylang)
 
(2 intermediate revisions by 2 users not shown)
Line 1,778:
 
int month_count = 0;
int blank_years = 0;
for ( int y = 1900; y <= 2100; ++y ) {
bool blank_year = true;
for ( std::chrono::month m : long_months ) {
std::chrono::year_month_day first_of_month{std::chrono::year{y}, m, std::chrono::day{1}};
Line 1,784 ⟶ 1,786:
std::cout << first_of_month.year() << " " << first_of_month.month() << std::endl;
month_count++;
blank_year = false;
}
}
if ( blank_year ) {
blank_years++;
}
}
std::cout << "Found " << month_count << " months with five Fridays, Saturdays and Sundays." << std::endl;
std::cout << "There were " << blank_years << " years with no such months." << std::endl;
}
</syntaxhighlight>
Line 1,804 ⟶ 1,811:
2100 Oct
Found 201 months with five Fridays, Saturdays and Sundays.
There were 29 years with no such months.
</pre>
 
Line 2,292 ⟶ 2,300:
Writeln(Format('Years with no 5 weekend months: %d', [lYearsWithout]));
end.</syntaxhighlight>
 
=={{header|EasyLang}}==
<syntaxhighlight>
func leap year .
return if year mod 4 = 0 and (year mod 100 <> 0 or year mod 400 = 0)
.
func weekday year month day .
normdoom[] = [ 3 7 7 4 2 6 4 1 5 3 7 5 ]
c = year div 100
r = year mod 100
s = r div 12
t = r mod 12
c_anchor = (5 * (c mod 4) + 2) mod 7
doom = (s + t + (t div 4) + c_anchor) mod 7
anchor = normdoom[month]
if leap year = 1 and month <= 2
anchor = (anchor + 1) mod1 7
.
return (doom + day - anchor + 7) mod 7 + 1
.
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
.
.
.
print "Total : " & sum
</syntaxhighlight>
{{out}}
<pre>
1901-Mar
1902-Aug
1903-May
1904-Jan
1904-Jul
.
.
2097-Mar
2098-Aug
2099-May
2100-Jan
2100-Oct
Total : 201
</pre>
 
=={{header|Elixir}}==
Line 7,311 ⟶ 7,368:
{{libheader|Wren-date}}
{{libheader|Wren-seq}}
<syntaxhighlight lang="ecmascriptwren">import "./date" for Date
import "./seq" for Lst
 
var dates = []
2,022

edits