Symmetryc, on 08 October 2013 - 05:40 PM, said:

Button API Submission:

Edit: Snipped, Just noticed Agent's post :/.

Edit2: Alright, I compacted it down a bit

Char Count: 164

T = term
function b(t,x,y,c,g,p)
return function(X,Y)
T.setCursorPos(x,y)
T.setTextColor(c)
T.setBackgroundColor(g)
return X and X >= x and Y == y and X <= x + 2 * #p + #t or write(p..t..p)
end
end

Challenge: Write a function that returns the greatest prime number equal to or below

*n* (must be calculated, can't use a list of pre-made primes)

First, your button code fails my tests. Also, you made me realize that I can shave off 2 chars for

**169** chars:

T = term
function b(t,x,y,c,g)
return function(X,Y)
if X then
return X >= x and Y == y and X <= x + 2 + #t
else
T.setCursorPos(x,y)
T.setTextColor(c)
T.setBackgroundColor(g)
write(" "..t.." ")
end
end
end

I also don't really know which one's more convenient, but this returns 2 functions instead of one:

Second, challenge accepted! Primes submission (trial division):

function l(u)
for n = u,2,-1 do
for d = 2,n-1 do
if n % d == 0 then
f = 1
end
end
if f then f = nil else return n end
end
end

**90** chars.

Yes, I know there are optimizations I left out, but it's the smallest correct code I could think of. Note: I did implement a short Sieve of Eratosthenes, but it's larger, even with everything unnecessary removed and the whole thing condensed as much as possible.