HP Forums

Full Version: Why does this Friday 13th program fail?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Perusing old postings I ran across several "Friday The 13th" programs, and whipped up this obvious-ware for the HP Prime. Looks to me like it should work. But it doesn't.

Code:
EXPORT FRI13(Y)
BEGIN
LOCAL j;
L9:={};
FOR j FROM Y+.0113 TO Y+.1213 STEP .01 DO
IF DAYOFWEEK(j)==5 THEN L9:=CONCAT(L9,j);
END;
RETURN L9;
END;
END;

An input of 2017 should return {2017.0113, 2017.1013}, but it only returns {2017.0113}.

An input of 2026 should return a list containing 3 dates, but only an empty list is returned.

What am I doing wrong?
SORRY... please ignore previous posting. My ENDs were in the wrong place. This works:

Code:
EXPORT FRI13(Y)
BEGIN
LOCAL j;
L9:={};
FOR j FROM Y+.0113 TO Y+.1213 STEP .01 DO
IF DAYOFWEEK(j)==5 THEN L9:=CONCAT(L9,j) END;
END;
RETURN L9;
END;
Thank you for sharing this neat program, Joe.

I quit programming long time ago (because I don't need it for my work anymore), so when I looked to the first program listing I couldn't immediately see anything wrong, but the two consecutive END statements following a RETURN did call my attention to check the begin-end code blocks in more detail.

I didn't try the program myself, but my understanding is that the Prime interpreter will not detect any anomalies in the first code listing, meaning that from the point of syntax correctness the Prime will find no errors.

It seems that in the first posted algorithm, the FOR loop was interrupted due to an early exit imposed by the RETURN statement, right?
Hi,

From "One-Minute Marvel", from a program of Joe K Horn and one other, I have ported this for HP Prime :

Code:

EXPORT V13(Année)
BEGIN
PRINT();
A:=Année+.0113;
FOR I FROM −5 TO 6 DO
IF (DDAYS(3000.0404,A) MOD 7)==0
THEN PRINT(A)
END;
A:=A+.01;
END;
END;

Have a good night (or day !).
(10-16-2017 02:02 PM)Joe Horn Wrote: [ -> ]Perusing old postings I ran across several "Friday The 13th" programs, and whipped up this obvious-ware for the HP Prime. Looks to me like it should work. But it doesn't.

Code:
EXPORT FRI13(Y)
BEGIN
   LOCAL j;
   L9:={};
   FOR j FROM Y+.0113 TO Y+.1213 STEP .01 DO
      IF DAYOFWEEK(j)==5 THEN L9:=CONCAT(L9,j);
   END;
   RETURN L9;
   END;  // What does this close?
END;

An input of 2017 should return {2017.0113, 2017.1013}, but it only returns {2017.0113}.

An input of 2026 should return a list containing 3 dates, but only an empty list is returned.

What am I doing wrong?

You already found the problem so I won't elaborate but I do find it helpful to indent structures like FOR, BEGIN, and IF. This lets me see problems with nesting immediately.
(10-16-2017 08:09 PM)toml_12953 Wrote: [ -> ]You already found the problem so I won't elaborate but I do find it helpful to indent structures like FOR, BEGIN, and IF. This lets me see problems with nesting immediately.

Good advice!
Hello Joe,
Any particular reason for preferring CONCAT command instead of a L9(0):=j command?

Thanks

Giancarlo
(10-17-2017 05:09 AM)Giancarlo Wrote: [ -> ]Any particular reason for preferring CONCAT command instead of a L9(0):=j command?

Yes: I didn't know about L9(0):=j before. Very cool! Thank you!
In one line:
Code:
EXPORT FRI13(Y)
BEGIN
 DIFFERENCE(MAKELIST((DAYOFWEEK(J)==5)*J,J,Y+.0113,Y+.13,.01),0);
END;
Amazing!

How about creating a drop-in, full featured, bug free, replacement CAS system in the next day or so? Smile
(10-17-2017 08:42 PM)Didier Lachieze Wrote: [ -> ]In one line:
Code:
EXPORT FRI13(Y)
BEGIN
 DIFFERENCE(MAKELIST((DAYOFWEEK(J)==5)*J,J,Y+.0113,Y+.13,.01),0);
END;

Bonjour
Je voulais émettre une critique sur ce code, pensant que vous utilisez une variable globale 'J'
Je viens de me rendre compte que la variable utilisée par MAKELIST semble maintenant être une variable locale.
Est-ce vrai ?


Hello
I wanted to comment on this code, thinking that you are using a global variable 'J'
I have just realized that the variable used by MAKELIST now seems to be a local variable.
Is it true ?
You can use any variable, local, global, reserved, etc., within the MAKELIST() command. It you want to save the output of the MAKELIST() command, it would need to be in a variable of a legal type, (no RESERVED variables except L0-L9, or M0-M9.

[attachment=5269] [attachment=5270]
Reference URL's