06-30-2003, 01:01 AM
to have a sine that uses degrees, you must convert the degrees to radians at some point if you wish to use the internal SIN function, and to do this, you need to know the value of Pi...
Challenge: Algorithms having only one line of code.
|
06-30-2003, 01:01 AM
to have a sine that uses degrees, you must convert the degrees to radians at some point if you wish to use the internal SIN function, and to do this, you need to know the value of Pi...
06-30-2003, 03:39 AM
I took out the degrees sign (º), and tried it in QuickBasic, like so:
Pi = n * Sin(180/n) Pi is defined as double, and n as integer. Using n=4, it gives an answer of 3.4036----- Using n=256, it gives.............. 165.5307----- Something is not right. *****
06-30-2003, 04:07 AM
See ak00ma's post above... you must use a sine function that takes degrees as an argument, and you can't really write one without either making a lookup table, or using the builtin SIN function, using PI so you can convert degrees to radians... so whip out your old algebra book and start typing...
06-30-2003, 04:53 AM
That's the trouble isn't it... to convert from degrees to radians you have to have pi, and you are trying to calculate pi anyway, so how can you get the answer anyway, when the answer is part of the question?
Also, the random function is not really random, we had this discussion a little while ago somewhere (me, Hex, Glenn, Aga), all the random function does is go through 16 million numbers and repeat. RANDOMIZE TIMER just chooses a different starting point...
06-30-2003, 07:35 AM
Ok, let's get back to the topic. We haven't had a one-line algorithm since Oracle's calculation for PI.
A few days ago I posted the following: Code: Given a positive integer number N, compute the next multiple of X: Code: M = int((N+X-1)/X)*X
06-30-2003, 09:42 AM
I already made a function to do that for statlib... pity I'll have to rewrite it because I'm using strings now...
Functions for finding roots of quadratic equations. Two needed: one for each root. Code: a = 1
06-30-2003, 08:35 PM
I only need a sine algorithm that uses degrees and not radians...then I'll code it
B 4 EVER
07-01-2003, 09:33 AM
Quote:I already made a function to do that for statlib... pity I'll have to rewrite it because I'm using strings now...That only finds the real roots... I suppose we'll let you get away with it this time...
07-01-2003, 11:30 AM
I know that... *shoots DrV*. How d'you expect me to find complex roots, or even represent them in QB? I suppose it could be done using the symmetrical property of the roots and polar form, but then it wouldn't be one line.
07-02-2003, 02:42 AM
Here's a rather complex one-liner to determine if a given number N is a power of 2.
Code: defLNG a-z Note: My original code did not add the .5 to round the result. However, further testing showed that for certain values of N, like 128, the arithmetic failed. Can anyone tell me why 128 fails without the rounding? ***** |
« Next Oldest | Next Newest »
|