[SLUG] SLUG meeting dates

Bob Garrood bgarrood at tiscali.co.uk
Fri Aug 11 10:32:35 BST 2006


Hi

There has been some comment on the difficulty of working out SLUG meeting 
dates.  Here is a Ruby program that saves brain strain.

**********************************************************************************
#!/usr/bin/ruby -w

#program to print out slug meeting dates.  Valid 2001-2099.
#set up arrays
days = %w{Monday Tuesday Wednesday }
hath = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
months = %w{January February March April May June July August September 
October November December}
firstday =1 #Jan 1 2001 was Monday, days numbered 0 - 6.

#Find out which year, decide if leap, and calculate 1st Jan.
print  "What year?"
year =gets
printf "%10s", year
year = (year.to_i) -2001
firstday = ((firstday + year) + year/4)%7
year =  year%4
hath[1] = 29 if year ==3

0.upto(11) do
|k|
slug = 0
i = 1  #date
j = firstday  #day of the week	
	while slug ==0 do
	j = j%7
	slug = i if i%3 ==0 and (j >0 and j<4)
	i+=1
	j +=1
	end
if slug==3
ord = "rd  "
else
ord = "th  "
end
printf("%s %2i%s%s\n",days[j-2],slug,ord,months[k])
firstday = (firstday + hath[k])%7
end
*********************************************************************************

This is the output for 2006:

What year?     2006
Tuesday  3rd  January
Monday  6th  February
Monday  6th  March
Monday  3rd  April
Wednesday  3rd  May
Tuesday  6th  June
Monday  3rd  July
Wednesday  9th  August
Wednesday  6th  September
Tuesday  3rd  October
Monday  6th  November
Wednesday  6th  December

Bob




More information about the Scarborough mailing list