Quote:

Using your favorite calculator find a future Friday the 13th where the sum of the digits that make up the date equals 13. E.g. if the date were MM/DD/YYYY (or DD.MM.YYYY) then M+M+D+D+Y+Y+Y+Y = 13. E.g. today is 13.03.2009, 1 + 3 + 3 + 2 + 9 <> 13.
Can you find the next one after that?

Thanks to all that participated and provided solutions.

As Monte quickly pointed out the first two are:

5-13-2011 and 4-13-2012

I created 3 solutions for the 12C. The 12C has two date functions:

- DATE. Put a date in Y and a number in X and DATE will compute the future (or past) date and will also display the day-of-week, however the day-of-week is not stored, so it cannot be used in a program.

- Delta Days. Put two dates on the stack and DDYS will return the difference in days.

My first program uses brute force to find the next and future Friday the 13ths with a digit sum of 13. To use, set the 12C in D.MY mode (cannot be programmed) and input any Friday date on the stack in D.MY format (e.g. 13.032009) and then press R/S. This program will test each Friday until another 13th is found, then a digit sum is used to check. After discovered you can press R/S again to get the next date.

**NOTE**: The DATE function includes a built-in PSE. Yup, its slow.

Time to first solution: 7 min 26 sec

Code:

01 f6 14 Rv 27 x=0

02 ENTER 15 STO 1 28 GTO 30

03 7 16 0 29 GTO 20

04 DATE 17 STO 0 30 RCL 0

05 ENTER 18 RCL 1 31 9

06 INTG 19 FRAC 32 -

07 1 20 1 33 x=0

08 3 21 0 34 GTO 37

09 - 22 x 35 RCL 1

10 x=0 23 INTG 36 GTO 02

11 GTO 14 24 STO+ 0 37 RCL 1

12 Rv 25 LSTx

13 GTO 02 26 FRAC

My 2nd program works like the first, but skips by month. To use, set the 12C in M.DY mode and input in any 2009 or later 13th (e.g. 3.132009) and press R/S. After discovered you can press R/S again to get the next date.

Clearly skipping by month instead of week *should* be ~4x faster. However, this code is a bit more complicated because there is no easy way to check that each 13th of each month is on a Friday. The constant 12.282008 is a Sunday and is used to calculate day-of-week.

Time to first solution: 2 min 5 sec

Code:

01 STO 1 22 - 43 x 64 0

02 f6 23 1 44 - 65 STO 0

03 1 24 EEX 45 5 66 x<>y

04 2 25 6 46 - 67 1

05 . 26 CHS 47 x=0 68 0

06 2 27 + 48 GTO 51 69 x

07 8 28 GTO 33 49 RCL 1 70 INTG

08 2 29 Rv 50 GTO 14 71 STO+ 0

09 0 30 Rv 51 RCL 1 72 LSTx

10 0 31 1 52 FRAC 73 FRAC

11 8 32 + 53 LSTx 74 x=0

12 STO 2 33 STO 1 54 INTG 75 GTO 77

13 Rv 34 RCL 2 55 EEX 76 GTO 67

14 ENTER 35 RCL 1 56 2 77 RCL 0

15 INTG 36 DELTA DAYS 57 / 78 9

16 1 37 ENTER 58 x<>y 79 -

17 1 38 ENTER 59 . 80 x=0

18 x<>y 39 7 60 1 81 GTO 84

19 x<=y 40 / 61 3 82 RCL 1

20 GTO 29 41 INTG 62 - 83 GTO 14

21 Rv 42 7 63 + 84 RCL 1

My final program takes a 4 digit year as the input and returns a "magic" number that represents all the months with Friday the 13ths. Unfortunately I ran out of steps (and time) and was unable to generalize this to produce exact solutions without a bit of aid.

Magic Number Table:

Magic Number Months with Friday the 13ths

------------ ----------------------------

1 May

2 August

2 February, August (leap year)

3 February, March, November

3 March, November (leap year)

4 June

5 September, December

6 April, July

7 January, October

7 January, April, July (leap year)

E.g. 2011 will return 1, so 05-13-2011 is a Friday the 13th. Do the digit sum manually.

E.g. 2012 will return 6, so 04-13-2012 and 06-13-2012 are both Friday the 13ths. Again do the digit sum manually.

E.g. 2020 will return 3, but 2020 is a leap year, so only 03-13-2020 and 11-13-2020 are Friday the 13ths.

4046 is the largest year supported by the 12C.

Code:

01 STO 1 17 1 33 4 49 0

02 1 18 . 34 / 50 0

03 2 19 0 35 FRAC 51 /

04 . 20 1 36 x=0 52 FRAC

05 2 21 + 37 GTO 39 53 x=0

06 8 22 DELTA DAYS 38 GTO 56 54 GTO 56

07 2 23 ENTER 39 RCL 1 55 GTO 58

08 0 24 ENTER 40 4 56 1

09 0 25 7 41 0 57 STO- 2

10 8 26 / 42 0 58 ENTER

11 STO 0 27 INTG 43 / 59 5

12 RCL 1 28 7 44 FRAC 60 RCL 2

13 1 29 x 45 x=0 61 1

14 EEX 30 - 46 GTO 58 62 -

15 6 31 STO 2 47 RCL 1 63 -

16 / 32 RCL 1 48 1

*Edited: 20 Mar 2009, 12:39 a.m. *