@WickedX - Your solution doesn't function the same as your sample. I adjusted your sample to function the same as the solution:
x = 0 //main variable
a = rightkey() //input a
b = leftkey() //input b
s = 2 //speed
max = 20 //maximum
min = -20 //minimum
//using if
if a and x < max then inc x, s
if b and x > min then dec x, s
//without if
inc x, (a*(x<max) - b*(x>min)) * s
Mathematical logic is certainly interesting and can be very useful, but I don't particularly like this example as it doesn't improve the code.
@thenerd - Here's my solution:
lim = 100
dim p(lim)
for n = 2 to lim : p(n)=1 : next n //start with all numbers >1 on the primes list
rem -- main ----------------------------------
for i = 2 to lim
if p(i)
for j = 2 to i
if p(j)
k = 1
while i * j^k <= lim
p(i * j^k) = 0
inc k
endwhile
endif
next j
endif
next i
I don't have DB installed so I had to dry run the code to check it. I sort of had to develop my own notation in the process so I hope it is easy to follow, maybe useful:
lim = 100
dim p(lim)
for n = 2 to lim : p(n)=1 : next n //start with all numbers >1 on the primes list
rem -- dry run ----------------------------------
for i = 2 to lim → i=2 → TRUE
if p(i) → if p(2)=1 → TRUE
for j = 2 to i → j=2 → TRUE
if p(j) → if p(2)=1 → TRUE
k = 1
while i * j^k <= lim → 2·2¹… → 4 <= 100 → TRUE
p(i * j^k) = 0 → p(4)=0
inc k → k=2
→ while i * j^k <= lim → 2·2²… → 8 <= 100 → TRUE
p(i * j^k) = 0 → p(8)=0
inc k → k=3
… → k=5
→ while i * j^k <= lim → 2·2⁵… → 64 <= 100 → TRUE
p(i * j^k) = 0 → p(64)=0
inc k → k=6
→ while i * j^k <= lim → 2·2⁶… → 128 <= 100 → FALSE
→ endif
→ j=3 → FALSE
→ endif
→ i=3 → TRUE
if p(i) → if p(3)=1 → TRUE
for j = 2 to i → j=2 → TRUE
if p(j) → if p(2)=1 → TRUE
k = 1
while i * j^k <= lim → 3·2¹… → 6 <= 100 → TRUE
p(i * j^k) = 0 → p(6)=0
inc k → k=2
→ while i * j^k <= lim → 3·2²… → 12 <= 100 → TRUE
p(i * j^k) = 0 → p(12)=0
inc k → k=3
… → k=5
→ while i * j^k <= lim → 3·2⁵… → 96 <= 100 → TRUE
p(i * j^k) = 0 → p(96)=0
inc k → k=6
→ while i * j^k <= lim → 3·2⁶… → 192 <= 100 → FALSE
→ endif
→ j=3 → TRUE
if p(j) → if p(3)=1 → TRUE
k = 1
while i * j^k <= lim → 3·3¹… → 9 <= 100 → TRUE
p(i * j^k) = 0 → p(9)=0
inc k → k=2
… → k=3
→ while i * j^k <= lim → 3·3³… → 81 <= 100 → TRUE
p(i * j^k) = 0 → p(81)=0
inc k → k=4
→ while i * j^k <= lim → 3·3⁴… → 243 <= 100 → FALSE
→ endif
→ j=4 → FALSE
→ endif
→ i=4 → TRUE
if p(i) → if p(4)=1 → FALSE
→ i=5 → TRUE
if p(i) → if p(5)=1 → FALSE
for j = 2 to i → j=2 → TRUE
if p(j) → if p(2)=1 → TRUE
k = 1
while i * j^k <= lim → 5·2¹… → 10 <= 100 → TRUE
p(i * j^k) = 0 → p(10)=0
inc k → k=2
… → k=4
→ while i * j^k <= lim → 5·2⁴… → 80 <= 100 → TRUE
p(i * j^k) = 0 → p(80)=0
inc k → k=5
→ while i * j^k <= lim → 5·2⁵… → 160 <= 100 → FALSE
→ endif
→ j=3 → TRUE
if p(j) → if p(3)=1 → TRUE
k = 1
while i * j^k <= lim → 5·3¹… → 15 <= 100 → TRUE
p(i * j^k) = 0 → p(15)=0
inc k → k=2
→ while i * j^k <= lim → 5·3²… → 45 <= 100 → TRUE
p(i * j^k) = 0 → p(45)=0
inc k → k=3
→ while i * j^k <= lim → 5·3³… → 135 <= 100 → FALSE
→ endif
→ j=4 → TRUE
if p(j) → if p(4)=1 → FALSE
→ j=5 → TRUE
if p(j) → if p(5)=1 → TRUE
k = 1
while i * j^k <= lim → 5·5¹… → 25 <= 100 → TRUE
p(i * j^k) = 0 → p(25)=0
inc k → k=2
→ while i * j^k <= lim → 5·5²… → 125 <= 100 → FALSE
→ endif
→ j=6 → FALSE
→ endif
… → i=101 → FALSE