This was a thing I did for a high school number theory assignment, which I then turned into a JavaScript program.

(I wrote this in terms of pencil-and-paper arithmetic; my intent at the time was to make it in a similar style to certain "math magic" things, where it was like, do this long series of operations and then suddenly I can figure out your number. I'm not sure if I succeeded in that, and I'm not sure this is the clearest or more efficient way to do this.)

(Note: this does not work for really old dates because they didn't use a calendar with leap years back then.)

- Write down the following numbers
- The year (four-digit form)
- 1/4 of the year (remove any digits after the decimal point)
- The year, leaving off the last two digits
- The number you wrote down for
`b`, leaving off the last two digits

- Add the numbers you wrote for
`a`,`b`, and`d`above, then subtract the number you wrote for`c`. - Repeatedly perform the following steps to the digits of the number you got in the previous step until you have a number less than 7:
- If there are any 7's in the number, change all 7's to 0's.
- If there are any 8's in the number, change all 8's to 1's.
- If there are any 9's in the number, change all 9's to 2's.
- Add six times the thousands digit, two times the hundreds digit, three times the tens digit, and one times the ones digit. If the number is greater than ten thousand, consider all but the last three digits to be the thousands digit (i.e., in the number 123000, multiply 123 by six).

- Find your number on the table below.

- Separate the first two digits of the year from the last two digits of the year (e.g., 1999 becomes 19, 99). If the year has more than four digits, remove any extra digits from the beginning (12345 becomes 23, 45). If the year has fewer than four digits, add zeroes to the beginning (1 becomes 00, 01) (but see the note above about old dates). Call the first two digits
`x`and the last two digits`y`. - Divide
`y`by 4, removing any fractional part. Add that number from the original`y`to get a new`y`. - Do one of the following:
- If
`x`is a multiple of four, leave`y`alone. - If
`x`is even, but not a multiple of four, add 3 to`y`. - If
`x`is one more than a multiple of four (or three less than a multiple of four), add 5 to`y`. - If
`x`is one less than a multiple of four (or three more than a multiple of four), add 1 to`y`.

- If
- Repeatedly perform the following steps to the digits of the number you got in the previous step until you have a number less than 7:
- If there are any 7's in the number, change all 7's to 0's.
- If there are any 8's in the number, change all 8's to 1's.
- If there are any 9's in the number, change all 9's to 2's.
- Add two times the hundreds digit (if any), three times the tens digit, and one times the ones digit.

- Find that number in the table below.

Your number | Friday 13 in these months |
---|---|

0 | January (except leap years), October |

1 | January (leap year only), April, July |

2 | September, December |

3 | June |

4 | February (except leap years), March, November |

5 | February (leap year only), August |

6 | May |

- This works by finding what day of the week October starts on. If you look at a year calendar, you'll notice that in non-leap-years, October always starts on the same day of the week as January. October was chosen instead of January to make the calculations easier.
- For non–leap-years, the day of the week the next year starts on is the day after the previous year started on (e.g., 2006 started on a Saturday, so 2007 starts on a Sunday). If the year is after a leap year, the year starts two days of the week after the previous year; if we look only at the part of the year after February, it's the leap year that's two days after the previous year.
- The first two steps simply add the year to the leap years that have happened up to, and including, that year. A leap year usually happens every four years (so add year÷4 =
`b`), but not every hundred years (so subtract year÷100 =`c`), but yest every four hundred (so add back year÷400 =`d`). - Step three is simply a fancy way of taking the number modulo seven (or taking the remainder when divided by seven). Step 3.1: 7,70,700,7000≡0 (mod 7); step 3.2 8,80,800,8000≡1,10,100,1000 (mod 7); step 3.3 9,90,900,9000≡2,20,200,2000 (mod 7); step 3.4: 1≡1, 10≡3, 100≡2, 1000≡6 (mod 7).
- This happens to give 0 if October starts on a Sunday. The number you get in step 3 is the day of the week October starts on (0=Sun, 1=Mon, etc.). All that's left is to find out when Friday the 13 is.
- The second way takes advantage of the fact that the calendar exactly repeats itself every 400 years. Steps two and three are equivalent to dividing the first two digits by four and then doing step 2 in the first way.