 Ulam spiral - Printable Version +- HP Forums (https://www.hpmuseum.org/forum) +-- Forum: HP Software Libraries (/forum-10.html) +--- Forum: HP Prime Software Library (/forum-15.html) +--- Thread: Ulam spiral (/thread-209.html) Ulam spiral - Tugdual - 12-22-2013 09:15 PM Explanation is here http://en.wikipedia.org/wiki/Ulam_spiral The code is nothing special... Code: ``` EXPORT Ulam() BEGIN    local x, y, level, i, n;    x:=320/2;    y:=240/2;    level:=1;    n:=1;    rect_p(0);    // center: initial state, level 1    if isprime(n) then pixon_p(x,y); end;        while x>=0 and x<320 and y>=0 and y<240 do       // end of level -> move right       x:=x+1;       n:=n+1;       level:=level+2;       if isprime(n) then pixon_p(x,y,#FFFFFFh); end;       // move up       for i from 3 to level do          y:=y-1;          n:=n+1;          if isprime(n) then pixon_p(x,y,#FFFFFFh); end;       end;              // move left       for i from 2 to level do          x:=x-1;          n:=n+1;          if isprime(n) then pixon_p(x,y,#FFFFFFh); end;       end;       // move down       for i from 2 to level do          y:=y+1;          n:=n+1;          if isprime(n) then pixon_p(x,y,#FFFFFFh); end;       end;       // move right       for i from 2 to level do          x:=x+1;          n:=n+1;          if isprime(n) then pixon_p(x,y,#FFFFFFh); end;       end;       end; freeze; END;``` And here is the Sacks version (note: why do I have to use approx???) Code: ``` EXPORT Sacks() BEGIN local r, a, n, x, y; rect_p(0); n:=0;    while x>=0 and x<320 and y>=0 and y<240 do       if isprime(n) then          r:=√n;          a:=r*2*π;          x:=approx(r*cos(a)+160);          y:=approx(120-r*sin(a));          pixon_p(x,y,#FFFFFF);       end;       n:=n+1;    end; freeze; END;``` RE: Ulam spiral - Damien - 12-25-2013 07:09 PM Posted by Gilles Carpentier on 22 July 2013, 5:38 p.m. Code: ``` 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 isprime(n) THEN PIXON_P(xy,127);END;     xy:=xy+d(a);     n:=n+1;    END;   END;  END;  FREEZE; END;``` another one ! Regards, Damien. RE: Ulam spiral - logoliv - 08-28-2020 11:09 AM Hi all, Damien's code doesn't work for me in HP Prime Pro app for iOS, nor in HP Prime Virtual Calculator for Windows... I have the last versions in both cases. When I run the app I obtain the same error message : "Error: Bad argument type" on "IF isprime(n) THEN" What am I doing wrong ? Does isprime() function work in emulators programs ? I'm new to HP Prime and it's my first program, thanks in advance for any help. Olivier RE: Ulam spiral - Joe Horn - 08-28-2020 01:14 PM (08-28-2020 11:09 AM)logoliv Wrote:  Hi all, Damien's code doesn't work for me in HP Prime Pro app for iOS, nor in HP Prime Virtual Calculator for Windows... I have the last versions in both cases. When I run the app I obtain the same error message : "Error: Bad argument type" on "IF isprime(n) THEN" What am I doing wrong ? Does isprime() function work in emulators programs ? I'm new to HP Prime and it's my first program, thanks in advance for any help. Olivier Try this: Go into CAS Setup, then make sure that the checkbox at the end of the 3rd line ("Change apparent integers into exact integers") is enabled. No guarantees, but that fixed the problem on my Prime. RE: Ulam spiral - logoliv - 08-28-2020 02:33 PM Thanks for your answer Joe. The checkbox is already enabled, and the listbox for Integers is on "Decimal". I've also tested checking the CAS checkbox in the program creation screen, but it doesn't work either. I liked to program HP48 in sysRPL or Saturn assembly, and wanted to give HP Prime a try so I bought the Pro version on the App Store for my iPad... and the first simple program I test doesn't work and I don't even know why 