Posts: 1,774
Threads: 62
Joined: Aug 2003
Just to clear things up...
Quote:al·go·rithm Audio pronunciation of "algorithm" ( P ) Pronunciation Key (lg-rthm)
n.
A step-by-step problem-solving procedure, especially an established, recursive computational procedure for solving a problem in a finite number of steps.
Posts: 503
Threads: 31
Joined: Feb 2005
Mabey you didn't understand me. I ment I was out, as in out of this compition, as in I'm done, as in I'm not going to work on it, as in good job neo. I can't belive I let that LOG thing get by me....heh
So good bye, me no more reply unless there is another issue with algo.
i]"But...it was so beautifully done"[/i]
Posts: 108
Threads: 40
Joined: Aug 2001
Is this what you were asking?
Code:
input "a = ", a
input "b = ", b
n = a
while ((n / b) = (n \ b))
n = n / b
if n = 1 then
print a; " is a power of"; b
sleep
end
end if
wend
print a; " is NOT a power of"; b
sleep
...only works with integers >= 1...
COUNT HACKED BY RAZVEEE
RAZVEE IS A SCRIPT KIDDIE- hacker9
Posts: 17
Threads: 0
Joined: May 2005
Code:
DEFLNG A-Z
C = 1
INPUT "Input small number, big number"; A, B
WHILE C < B
I = I + 1
C = C * A
IF C = B THEN PRINT A; "^"; I; "="; B: END
WEND
PRINT B; "is not a power of "; A
Posts: 1,956
Threads: 65
Joined: Jun 2003
Quib,
Compiled and tested your solution. It works. Nice job!
However, I would suggest you add some validation of the input values. Garbage input will cause errors in your program. Take a look at input validation in Neo's solution.
*****
Posts: 320
Threads: 9
Joined: Dec 2004
Stop making horrible iterative procedures to acheive this; it's silly. The whole point of a logarithmic function is to acheive what you're trying to do.
Given the number X, LN(X) / LN(B) is an integer if X is a power of B.
It's that simple.
That's what my solution did, but never mind. Neo did the same.
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Posts: 1,956
Threads: 65
Joined: Jun 2003
Quote:Stop making horrible iterative procedures to acheive this; it's silly. The whole point of a logarithmic function is to acheive what you're trying to do.
Given the number X, LN(X) / LN(B) is an integer if X is a power of B.
It's that simple. That's what my solution did, but never mind. Neo did the same.
Your right, shiftlynx, but I got bashed earlier in this thread for not allowing iterative procedures. So I was forced to allow them.
*****
Posts: 108
Threads: 40
Joined: Aug 2001
Quote:Stop making horrible iterative procedures to acheive this; it's silly. The whole point of a logarithmic function is to acheive what you're trying to do.
Given the number X, LN(X) / LN(B) is an integer if X is a power of B
I did a little research, and some testing. My iterative solution is faster than the logarithmic one, but it only works for integers... However, if I changed it to handle floating point numbers, it would be slower, if X is very small and B is very large. The logarithmic function seems to calculate at a constant speed no matter what. I looked up natural lograthims on the internet, the equation to solve them seems to be iterative... does this mean that the natural log function is built into most FPU's?
COUNT HACKED BY RAZVEEE
RAZVEE IS A SCRIPT KIDDIE- hacker9
Posts: 1,956
Threads: 65
Joined: Jun 2003
Lithium,
I tested the solution above that you submitted May 31. Congratulations, it works fine.
*****