Post Reply 
Program crashes G2
09-25-2019, 10:33 PM
Post: #1
Program crashes G2
I wrote the following program for the HHC programming contest. I didn't submit it because it frequently (but not always) crashed my Prime G2. I just verified that it crashes the virtual calculator also.

If I debug the program, press STEP a few times and CONT, it will run until the last statement (RETURN L1Wink and pause there. Pressing STEP causes it to crash.

Both the physical and virtual calcs are running the 20181016 version. I tried reformatting the C drive on the physical calculator but that didn't help. Any thoughts?

The program finds 3-digit numbers that are equal to the sum of the cubes of their digits.

Thanks,
Dave

Code:
EXPORT CUBES()
BEGIN
LOCAL S1:=0,S2:=0,S3:=0; // PARTIAL SUMS
LOCAL N1:=0,N2:=0,N3:=0,C:=0;  // THE NUM
LOCAL L1 := {};
LOCAL X,Y,Z;
FOR X FROM 1 TO 9 DO
  S1 := X*X*X;
  N1 := 100*X;
  FOR Y FROM 0 TO 9 DO
    S2 := S1 + Y*Y*Y;
    N2 := N1 + 10*Y;
    FOR Z FROM 0 TO 9 DO
      S3 := S2 + Z*Z*Z;
      N3 := N2 + Z;
      IF S3 > N2+9 THEN
//  PRINT("LEAVING W"+N3);
        BREAK;
      END;
C:=C+1;
      IF N3 = S3 THEN
        L1 := CONCAT(L1,N3);
      END;
    END;
  END;
END;
// PRINT(C);
RETURN L1;
END;
Find all posts by this user
Quote this message in a reply
09-25-2019, 11:15 PM
Post: #2
RE: Program crashes G2
(09-25-2019 10:33 PM)David Hayden Wrote:  I wrote the following program for the HHC programming contest. I didn't submit it because it frequently (but not always) crashed my Prime G2. I just verified that it crashes the virtual calculator also.

Tried it on XCas. It crashes too.

My guess the problem is this line
Code:
LOCAL L1 := {};

On XCas, it seems impossible to create an empty list.
So, I go around the bug, and set L1 = [0]

XCas> CUBES()     → [0,153,370,371,407]
Find all posts by this user
Quote this message in a reply
09-26-2019, 02:18 AM (This post was last modified: 09-26-2019 02:21 AM by Gene222.)
Post: #3
RE: Program crashes G2
(09-25-2019 11:15 PM)Albert Chan Wrote:  My guess the problem is this line
Code:
LOCAL L1 := {};

On XCas, it seems impossible to create an empty list.
So, I go around the bug, and set L1 = [0]

XCas> CUBES()     → [0,153,370,371,407]

The program works on my Prime version A in both Home and CAS. Haden might want to step through the program with debug and watch variables L1, X, Y, and Z to confirm L1 is not being defined on the G2. Maybe it is related to the problems with BREAK.
Find all posts by this user
Quote this message in a reply
09-26-2019, 07:00 AM (This post was last modified: 09-27-2019 04:40 AM by toml_12953.)
Post: #4
RE: Program crashes G2
(09-25-2019 10:33 PM)David Hayden Wrote:  If I debug the program, press STEP a few times and CONT, it will run until the last statement (RETURN L1Wink and pause there. Pressing STEP causes it to crash.
Thanks,
Dave

I press STEP a few times then CONT and my G2 doesn't halt on the RETURN L1. It just displays the list and ends.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
09-26-2019, 11:36 AM
Post: #5
RE: Program crashes G2
Albert Chan Wrote:My guess the problem is this line
Code:
LOCAL L1 := {};
Thanks Albert. WHen I change {} to {0} it runs fine. Curiously, if I change it back to {} and then back to {0} again, it crashes. Perhaps running it with {} corrupts something.

But then again, it was crashing in earlier versions that PRINTed the results to the terminal instead of putting them in a list.

Gene222 Wrote:Maybe it is related to the problems with BREAK
I wasn't aware of BREAK problems. Stranger and stranger!
Find all posts by this user
Quote this message in a reply
09-26-2019, 01:18 PM
Post: #6
RE: Program crashes G2
(09-26-2019 11:36 AM)David Hayden Wrote:  I wasn't aware of BREAK problems. Stranger and stranger!

There was a thread about it a while back:

https://hpmuseum.org/forum/thread-13566.html

There are only 10 types of people in this world. Those who understand binary and those who don't.
Find all posts by this user
Quote this message in a reply
Post Reply 




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