Qbasicnews.com

Full Version: Challenge: Algorithms having only one line of code.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10
if you use mod then it reverts to integer, so i prefer the other way to keep the double precision. It only needs the +360 when it returns a value from -180 To 0 which is why i used the < 0 compare. Your version is a true one liner though which is cool.

Anonymous

yeah... well coderJeff showed us both up with this one:

Code:
angle = 180 - Atan2 ( v.x - u.x, v.y - u.y ) * 180 / PI

haha, that guys a ninja


edit upon testing, that didn't work! so i borrowed a bit from dr_d, that is, making radian transform a literal. here ya go:

Code:
angle =  180 - ATan2 ( v.x - u.x, v.y - u.y ) * 57.29577951308232
Quote:angle = 180 - ATan2 ( v.x - u.x, v.y - u.y ) * 57.29577951308232

this one gives me the wrong answer when angle = 0, it returns -6.24.....e015 or something

Anonymous

correct you are. but i mean thats like

.0000000000000006


...so its pretty close to zero, hahahah. all other angles work.
Here's my one-liner:

Draw a circle, without using the CIRCLE command:

Code:
SCREEN 12: h = 200: k = 200: r = 100: c = 13: FOR x = 0 TO INT(r / SQR(2)) + 1: y = SQR(r ^ 2 - x ^ 2): FOR a = -1 TO 1 STEP 2: FOR b = -1 TO 1 STEP 2: PSET (h + x * a, k + y * b), c: PSET (h + y * a, k + x * b), c: NEXT: NEXT: NEXT

draws a circle with center at (h, k), radius r and color c without using the CIRCLE command, or SIN or COS, and just two PSET commands.

It may seems like a long line but it fits inside a QBASIC IDE line of code. ;)

- neuro


[edit]: I see one of the rules is, no compounded lines (with colons)...

Here's another of my favorite algorithms:

purpose: hang the computer uninterruptibly (written in C):

for ( ; ; fork() ) ;

or this one, which goes on and on 4ever... (or just uses up all stack space):

int func(int x) return func(x+1);
Old thread, I don't know if i have posted this before:
Insert this in a line printing loop to print page by page
Code:
if lcnt=maxlines then print "Press a key";: x$=input$(1):lcnt=0:cls else lcnt=lcnt+1
Quote:Old thread, I don't know if i have posted this before:
Insert this in a line printing loop to print page by page
Code:
if lcnt=maxlines then print "Press a key";: x$=input$(1):lcnt=0:cls else lcnt=lcnt+1
Nice bit of code, Antoni, but it's not one line of code by the established rules.
*****
Code:
x = y * (((z AND 1) = 1) OR 1)

x = -y or + y depending on z being odd or even
Quote:
Code:
x = y * (((z AND 1) = 1) OR 1)

x = -y or + y depending on z being odd or even
Ok, but what would I use this algorithm for?
*****
GFX effects. :*)

Mostly plasmas and sinewave displacement.
Pages: 1 2 3 4 5 6 7 8 9 10