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.