Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
28
Task/Doomsday-rule/FutureBasic/doomsday-rule.basic
Normal file
28
Task/Doomsday-rule/FutureBasic/doomsday-rule.basic
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
local fn IsLeapYear( year as NSUInteger ) as BOOL
|
||||
BOOL result = YES
|
||||
if ( year mod 4 > 0 ) then result = NO : exit fn
|
||||
if ( year mod 100 = 0 ) and ( year mod 400 > 0 ) then result = NO : exit fn
|
||||
end fn = result
|
||||
|
||||
local fn DoomsdayWeekdayForDate( month as NSUInteger, day as NSUInteger, year as NSUInteger ) as CFStringRef
|
||||
CFArrayRef weekdayNames = @[@"Sunday", @"Monday", @"Tuesday", @"Wednesday", @"Thursday", @"Friday", @"Saturday"]
|
||||
CFArrayRef normalYearDays = @[@4, @1, @7, @4, @2, @6, @4, @1, @5, @3, @7, @5]
|
||||
CFArrayRef leapYearDays = @[@3, @7, @7, @4, @2, @6, @4, @1, @5, @3, @7, @5]
|
||||
CFStringRef dayOfWeek = @""
|
||||
NSUInteger anchorday
|
||||
|
||||
NSUInteger doomsday = ( 2 + 5 * ( year mod 4 ) + 4 * ( year mod 100 ) + 6 * ( year mod 400) ) mod 7
|
||||
if ( fn IsLeapYear( year ) ) then anchorday = intVal( normalYearDays[month-1] ) else anchorday = intVal( leapYearDays[month-1] )
|
||||
NSUInteger weekday = ( doomsday + day - anchorday + 7 ) mod 7
|
||||
if ( weekday == 0 ) then dayOfWeek = @"Sunday" else dayOfWeek = weekdayNames[weekday]
|
||||
end fn = dayOfWeek
|
||||
|
||||
printf @"01-06-1800 : %@", fn DoomsdayWeekdayForDate( 1, 6, 1800 )
|
||||
printf @"03-29-1875 : %@", fn DoomsdayWeekdayForDate( 3, 29, 1875 )
|
||||
printf @"12-07-1915 : %@", fn DoomsdayWeekdayForDate( 12, 7, 1915 )
|
||||
printf @"12-23-1970 : %@", fn DoomsdayWeekdayForDate( 12, 23, 1970 )
|
||||
printf @"05-14-2043 : %@", fn DoomsdayWeekdayForDate( 5, 14, 2043 )
|
||||
printf @"02-12-2077 : %@", fn DoomsdayWeekdayForDate( 2, 12, 2077 )
|
||||
printf @"04-02-2101 : %@", fn DoomsdayWeekdayForDate( 4, 2, 2101 )
|
||||
|
||||
HandleEvents
|
||||
Loading…
Add table
Add a link
Reference in a new issue