Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.forth > #58180 > unrolled thread

Rosetta: Five weekends

Started by"Robert L." <No_spamming@noWhere_7073.org>
First post2017-04-26 13:54 +0000
Last post2017-04-26 13:54 +0000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.forth


Contents

  Rosetta: Five weekends "Robert L." <No_spamming@noWhere_7073.org> - 2017-04-26 13:54 +0000

#58180 — Rosetta: Five weekends

From"Robert L." <No_spamming@noWhere_7073.org>
Date2017-04-26 13:54 +0000
SubjectRosetta: Five weekends
Message-ID<odq8qm$37b$1@gioia.aioe.org>
> The month of October in 2010 has five Fridays, five Saturdays,
> and five Sundays.
> 
> Task
> 
> Write a program to show all months that have this same
> characteristic of five full weekends from the year 1900
> through 2100 (Gregorian calendar).
> 
> Show the number of months with this property (there should be
> 201).
> 
> Show at least the first and last five dates, in order.

require 'date'

def good month
  d = Date.new(*month)
  d.friday? and d.next_month - d == 31
end

months = (1900..2100).to_a.product((1..12).to_a).select{|month| good month}
lacking_years = 2100 - 1899 - months.map(&:first).uniq.size

puts [*months.take(5), ['...'], *months.last(5)].map{|a| a.join ' '};
puts "#{months.size} months have five weekends.";
puts "#{lacking_years} years lack a five-weekend month."

 ===>
1901 3
1902 8
1903 5
1904 1
1904 7
...
2097 3
2098 8
2099 5
2100 1
2100 10
201 months have five weekends.
29 years lack a five-weekend month.

In Forth?


-- 
"If a government uses the instruments of power in its hands for the purpose of
leading a people to ruin, then rebellion is not only the right but also the
duty of every individual citizen." (Murphy translation)

[toc] | [standalone]


Back to top | Article view | comp.lang.forth


csiph-web