Post Reply 
Why does this Friday 13th program fail?
10-16-2017, 02:02 PM (This post was last modified: 10-16-2017 02:02 PM by Joe Horn.)
Post: #1
Why does this Friday 13th program fail?
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?

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
10-16-2017, 02:04 PM
Post: #2
RE: Why does this Friday 13th program fail?
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;

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
10-16-2017, 03:05 PM
Post: #3
RE: Why does this Friday 13th program fail?
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?

Jose Mesquita
RadioMuseum.org member

Find all posts by this user
Quote this message in a reply
10-16-2017, 06:40 PM (This post was last modified: 10-16-2017 07:09 PM by ggauny@live.fr.)
Post: #4
RE: Why does this Friday 13th program fail?
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 !).

Gérard.
Find all posts by this user
Quote this message in a reply
10-16-2017, 08:09 PM (This post was last modified: 10-16-2017 08:11 PM by toml_12953.)
Post: #5
RE: Why does this Friday 13th program fail?
(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.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
10-17-2017, 04:03 AM
Post: #6
RE: Why does this Friday 13th program fail?
(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!

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
10-17-2017, 05:09 AM
Post: #7
RE: Why does this Friday 13th program fail?
Hello Joe,
Any particular reason for preferring CONCAT command instead of a L9(0):=j command?

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
10-17-2017, 12:17 PM
Post: #8
RE: Why does this Friday 13th program fail?
(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!

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
10-17-2017, 08:42 PM
Post: #9
RE: Why does this Friday 13th program fail?
In one line:
Code:
EXPORT FRI13(Y)
BEGIN
 DIFFERENCE(MAKELIST((DAYOFWEEK(J)==5)*J,J,Y+.0113,Y+.13,.01),0);
END;
Find all posts by this user
Quote this message in a reply
10-17-2017, 09:15 PM (This post was last modified: 10-17-2017 09:19 PM by DrD.)
Post: #10
RE: Why does this Friday 13th program fail?
Amazing!

How about creating a drop-in, full featured, bug free, replacement CAS system in the next day or so? Smile
Find all posts by this user
Quote this message in a reply
10-18-2017, 04:22 AM (This post was last modified: 10-18-2017 04:23 AM by Tyann.)
Post: #11
RE: Why does this Friday 13th program fail?
(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 ?

Sorry for my english
Find all posts by this user
Quote this message in a reply
10-18-2017, 10:22 AM (This post was last modified: 10-18-2017 10:33 AM by DrD.)
Post: #12
RE: Why does this Friday 13th program fail?
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]
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)