Challenge: Algorithms having only one line of code. yetifoot Senior Member Posts: 484 Threads: 14 Joined: Apr 2005 03-29-2006, 10:19 PM 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. EVEN MEN OF STEEL RUST. Anonymous Unregistered   03-29-2006, 10:24 PM 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` yetifoot Senior Member Posts: 484 Threads: 14 Joined: Apr 2005 03-29-2006, 10:46 PM 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 EVEN MEN OF STEEL RUST. Anonymous Unregistered   03-29-2006, 10:52 PM correct you are. but i mean thats like .0000000000000006 ...so its pretty close to zero, hahahah. all other angles work. neuro Member Posts: 58 Threads: 6 Joined: Feb 2005 03-30-2006, 12:08 AM 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 : 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); ignatures suck Antoni Gual Posting Freak Posts: 1,407 Threads: 117 Joined: Dec 2002 03-30-2006, 12:13 AM 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` Antoni Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 03-30-2006, 01:26 AM 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. ***** relsoft Posting Freak Posts: 3,288 Threads: 167 Joined: Nov 2001 03-30-2006, 07:24 AM Code:`x = y * (((z AND 1) = 1) OR 1)` x = -y or + y depending on z being odd or even y smiley is 24 bit. Genso's Junkyard: http://rel.betterwebber.com/ Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 03-31-2006, 04:52 AM 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? ***** relsoft Posting Freak Posts: 3,288 Threads: 167 Joined: Nov 2001 03-31-2006, 11:09 AM GFX effects. :*) Mostly plasmas and sinewave displacement. y smiley is 24 bit. Genso's Junkyard: http://rel.betterwebber.com/ « Next Oldest | Next Newest »