Prime program examples « Next Oldest | Next Newest »

 ▼ Gilles Carpentier Senior Member Posts: 468 Threads: 17 Joined: May 2011 07-22-2013, 05:38 PM ```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. ▼ Cristian Arezzini Senior Member Posts: 372 Threads: 42 Joined: Mar 2011 07-22-2013, 06:58 PM 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? ▼ Gilles Carpentier Senior Member Posts: 468 Threads: 17 Joined: May 2011 07-23-2013, 01:59 AM 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. ▼ Cristian Arezzini Senior Member Posts: 372 Threads: 42 Joined: Mar 2011 07-23-2013, 04:18 AM 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. ▼ Gilles Carpentier Senior Member Posts: 468 Threads: 17 Joined: May 2011 07-23-2013, 06:03 PM In old releases 'isprime' was IsPrime or ISPRIME... ▼ Joe Horn Member Posts: 153 Threads: 7 Joined: Jun 2008 07-24-2013, 12:57 AM Quote: In old releases 'isprime' was IsPrime or ISPRIME... and isPrime. ▼ Cristian Arezzini Senior Member Posts: 372 Threads: 42 Joined: Mar 2011 07-24-2013, 04:39 AM 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! :) ▼ fhub Posting Freak Posts: 1,216 Threads: 75 Joined: Jun 2011 07-24-2013, 08:29 AM 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 Gilles Carpentier Senior Member Posts: 468 Threads: 17 Joined: May 2011 07-24-2013, 10:52 AM 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. ▼ Cristian Arezzini Senior Member Posts: 372 Threads: 42 Joined: Mar 2011 07-24-2013, 05:16 PM Thanks Gilles, but... still no luck. White screen. I tried with various values. Maybe I should really just wait for a newer release! :) ▼ Gilles Carpentier Senior Member Posts: 468 Threads: 17 Joined: May 2011 07-24-2013, 05:55 PM 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

 Possibly Related Threads... Thread Author Replies Views Last Post Sending little images to the Prime (...and Program name bug?) Erwin Ried 19 3,500 12-10-2013, 05:35 PM Last Post: Erwin Ried Problem with debug HP prime program, somebody help me? Carlos CM (Mexico) 6 1,720 12-05-2013, 03:07 PM Last Post: Carlos CM (Mexico) HP PRIME: APP program code DISAPPEARS !! Joseph Ec 0 513 11-25-2013, 11:35 AM Last Post: Joseph Ec Prime: Placing more than 1 item on the RPN stack in a single program? John Colvin 4 1,105 11-19-2013, 08:59 AM Last Post: Miguel Toro Prime: Program size limited to 64K? Erwin Ried 4 1,009 11-17-2013, 11:42 PM Last Post: Joseph Ec [HP-Prime] Picking elements from a List in a program Jean-Michel 3 955 11-15-2013, 04:16 AM Last Post: dg1969 HP Prime: Recommendation for future RPN Program Mode BruceTTT 3 957 11-13-2013, 10:03 PM Last Post: BruceTTT HP Prime: run a program in another program Davi Ribeiro de Oliveira 6 1,321 11-11-2013, 08:28 PM Last Post: Davi Ribeiro de Oliveira [prime] Insert a breakpoint in a program for debugging ? Olivier Lecluse 3 889 11-09-2013, 09:41 PM Last Post: Joseph Ec HP PRIME: Hide return value from program and swap Edit with Run vrrr 2 830 11-09-2013, 04:04 PM Last Post: vrrr

Forum Jump: