0 Members and 2 Guests are viewing this topic.
function isPrime(n) --[[Check if an integer n is a prime or not--]] if n==1 then return false end --1 is not a prime for i = 2, math.sqrt(n) do if n % i == 0 then return false end end return trueend
function isPrime(n) return math.eval("isprime("..n..")")end
Code: [Select]function isPrime(n) --[[Check if an integer n is a prime or not--]] if n==1 then return false end --1 is not a prime for i = 2, math.sqrt(n) do if n % i == 0 then return false end end return trueend
I am a proud cynic.
function drawTriangle(gc,x,y,l) gc:drawLine(x,y,x+l,y) gc:drawLine(x, y, x+(l/2), y-(l*0.5)) gc:drawLine(x+(l/2), y-(l*0.5), x+l, y)end
WaitMS = function(milliseconds) while (stime = math.abs(timer.GetMilliSecCounter()+milliseconds))< math.abs(timer.getMilliSecCounter()) do end return trueend
Draw a triangleInput: Graphics Context, x, y, length of sideResult: Draws a triangle at (x,y) in the screen with each side having length of lCode: [Select]function drawTriangle(gc,x,y,l) gc:drawLine(x,y,x+l,y) gc:drawLine(x, y, x+(l/2), y-(l*0.5)) gc:drawLine(x+(l/2), y-(l*0.5), x+l, y)endAll the sides of the triangle are of equal length and the (x,y) coordinates are of the left point of the triangle.Now, I know this is not very hard math (simple trigonometry) but I think it might be useful for someone Any optimizations?Here's how it works:
Pause for an exact amount of time, in millisecondsCode: [Select]WaitMS = function(milliseconds) while (stime = math.abs(timer.GetMilliSecCounter()+milliseconds))< math.abs(timer.getMilliSecCounter()) do end return trueend