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


Groups > comp.lang.forth > #58180

Rosetta: Five weekends

From "Robert L." <No_spamming@noWhere_7073.org>
Newsgroups comp.lang.forth
Subject Rosetta: Five weekends
Date 2017-04-26 13:54 +0000
Organization Aioe.org NNTP Server
Message-ID <odq8qm$37b$1@gioia.aioe.org> (permalink)

Show all headers | View raw


> 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)

Back to comp.lang.forth | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web