The Museum of HP Calculators

HP Forum Archive 21

 Prime program examplesMessage #1 Posted by Gilles Carpentier on 22 July 2013, 5:38 p.m. ```EXPORT Ulam BEGIN LOCAL a,b,xy:={160,120}, n:=1, m:=.9, d:={{1,0}, {0,1}, {-1,0}, {0,-1}}; RECT(); WHILE n<100000 DO FOR a FROM 1 TO 4 DO m:=m+.5; FOR b FROM 1 TO m DO IF CAS.isprime(n) THEN PIXON_P(xy,127);END; xy:=xy+d(a); n:=n+1; END; END; END; FREEZE; END; //------------- EXPORT Box(n) BEGIN FOR A:=1 TO n DO RECT_P(FLOOR(RANDOM(320)),FLOOR(RANDOM(260)),FLOOR(RANDOM(320)),FLOOR(RANDOM(260)),0,FLOOR(RANDOM(16581375))); END; FREEZE; END //------------------------- LPiece:={100,50,20,10,5,2,1} ; EXPORT Monnaie(Reste, NPiece) BEGIN IF Reste==0 THEN RETURN 1; END; IF Reste<0 OR NPiece==0 THEN RETURN 0; END; RETURN Monnaie(Reste-LPiece(NPiece),NPiece)+Monnaie(Reste,NPiece-1); END; ``` 'Ulam' draws the Ulam spiral http://en.wikipedia.org/wiki/Ulam_spiral 'Box(x)' draws x colored box on the screen 'Monnaie' returns the number of ways to get a total. For example Monnaie(100,7) return 4563 : That means there is 4563 ways to get 1 euro (100 cents) with the 7 coins describe in the global variable LPiece Edited: 22 July 2013, 6:00 p.m.

 Re: Prime program examplesMessage #2 Posted by Cristian Arezzini on 22 July 2013, 6:58 p.m.,in response to message #1 by Gilles Carpentier The program Ulam checks fine, but when I try to run it it says "Ulam Unknowntype"... Do I need to run it in a special way?

 Re: Prime program examplesMessage #3 Posted by Gilles Carpentier on 23 July 2013, 1:59 a.m.,in response to message #2 by Cristian Arezzini Works fine for me... What happens if you debug ? You must create a file with the name you want, then copy/paste the code. Then call Ulam from Home view Edited: 23 July 2013, 2:01 a.m.

 Re: Prime program examplesMessage #4 Posted by Cristian Arezzini on 23 July 2013, 4:18 a.m.,in response to message #3 by Gilles Carpentier That's exactly how I entered it, by copying/pasting from the above post. By the way, this worked fine with Tim's Mandelbrot program. When I debug, I can step until the IF instruction, then at the next STEP it gives the error message. then: The Box program instead works fine.

 Re: Prime program examplesMessage #5 Posted by Gilles Carpentier on 23 July 2013, 6:03 p.m.,in response to message #4 by Cristian Arezzini In old releases 'isprime' was IsPrime or ISPRIME...

 Re: Prime program examplesMessage #6 Posted by Joe Horn on 24 July 2013, 12:57 a.m.,in response to message #5 by Gilles Carpentier Quote: In old releases 'isprime' was IsPrime or ISPRIME... and isPrime.

 Re: Prime program examplesMessage #7 Posted by Cristian Arezzini on 24 July 2013, 4:39 a.m.,in response to message #6 by Joe Horn OK, now it doesn't give any error, but it doesn't draw anything - I get a white screen, and after a while, the box of "program finished". Is there some other command that has changed? On a related note: will we be allowed to check more recent versions of the ROM, with the emulator? It's a little frustrating to find bugs or problems that have been long since solved! :)

 Re: Prime program examplesMessage #8 Posted by fhub on 24 July 2013, 8:29 a.m.,in response to message #7 by Cristian Arezzini Quote: On a related note: will we be allowed to check more recent versions of the ROM, with the emulator? It's a little frustrating to find bugs or problems that have been long since solved! :) I agree, it doesn't make much sense to make bugreports for a completely outdated version - that's why I already stopped testing this old HP-Prime 'Prerelease 1'. :-( Franz

 Re: Prime program examplesMessage #9 Posted by Gilles Carpentier on 24 July 2013, 10:52 a.m.,in response to message #7 by Cristian Arezzini Quote: Is there some other command that has changed? Color code... PIXON_P(xy,127) try another color code than 127 (0 for example) Edited: 24 July 2013, 10:54 a.m.

 Re: Prime program examplesMessage #10 Posted by Cristian Arezzini on 24 July 2013, 5:16 p.m.,in response to message #9 by Gilles Carpentier Thanks Gilles, but... still no luck. White screen. I tried with various values. Maybe I should really just wait for a newer release! :)

 Re: Prime program examplesMessage #11 Posted by Gilles Carpentier on 24 July 2013, 5:55 p.m.,in response to message #10 by Cristian Arezzini I think it's the best ... I believe it's about the isprime syntax. isprime(n) may return 1 if true, 0 if false. it seems it always returns 0 in your program with this release

Go back to the main exhibit hall