This commit is contained in:
parent
b514714225
commit
6623e60c0a
|
@ -0,0 +1,92 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main(){
|
||||
weekday := time.Tuesday
|
||||
sundays := 0
|
||||
for i := 1901; i<=2000; i+=1 {
|
||||
var leap int
|
||||
if i%4 == 0 {
|
||||
leap = 1
|
||||
} else {
|
||||
leap = 0
|
||||
}
|
||||
|
||||
inYearOffset := 0
|
||||
//january
|
||||
if weekday == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 31
|
||||
//feb
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 28 + leap
|
||||
//march
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 31
|
||||
//april
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 30
|
||||
//may
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 31
|
||||
//june
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 30
|
||||
//july
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 31
|
||||
//august
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 31
|
||||
//september
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 30
|
||||
//october
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 31
|
||||
//november
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
inYearOffset += 30
|
||||
//december
|
||||
if (int(weekday) + inYearOffset) % 7 == 0 {
|
||||
sundays += 1
|
||||
}
|
||||
fmt.Printf("%d: %d\n", i, inYearOffset + 31)
|
||||
|
||||
|
||||
var offset int
|
||||
if i % 4 == 0 {
|
||||
offset = (366) % 7
|
||||
} else {
|
||||
offset = (365) % 7
|
||||
}
|
||||
weekday = time.Weekday((offset + int(weekday)) % 7)
|
||||
}
|
||||
|
||||
fmt.Printf("Sundays: %d\n", sundays)
|
||||
}
|
Loading…
Reference in New Issue