Skip to content

Instantly share code, notes, and snippets.

@ayato-p
Last active December 17, 2015 01:49
Show Gist options
  • Save ayato-p/5531012 to your computer and use it in GitHub Desktop.
Save ayato-p/5531012 to your computer and use it in GitHub Desktop.
public class Problem19 {
public static void main(String[] args) {
int count = 0;
for(int y=1901; y<=2000; y++){
for(int m=1; m<=12; m++){
if(dayOfWeek(y, m, 1) == 0){
count++;
}
}
}
System.out.println(count);
}
private static int dayOfWeek(int y, int m, int d){
final int[] t = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4};
y -= (m < 3) ? 1 : 0;
return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7;
}
}
@ayato-p
Copy link
Author

ayato-p commented May 7, 2013

@ayato-p
Copy link
Author

ayato-p commented May 7, 2013

(define (day-of-week y m d)
(let ((t '(0 3 2 5 0 3 5 1 4 6 2 4)
(y (if (< m 3) 1 0)))
(modulo (+ y (/ y 4) (- (/ y 100)) (/ y 400) (list-ref t (- m 1)) d) 7)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment