Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Algorithm to determine if a number A is a power of B.
#31
So, What's wrong with mine?
i]"But...it was so beautifully done"[/i]
Reply
#32
MIT,
The following was my previous evaluation of your solution.
Maybe you would like to submit a corrected version.
*****

Quote:
Mitth'raw'nuruodo Wrote:
Code:
CLEAR
CLS
INPUT "Number: ", A
INPUT "Base: ", B
Value = 0
IsIt = 0
index = -1
DO
IF Value > A THEN EXIT DO
index = index + 1
Value = B ^ index
IF Value = A THEN IsIt = 1: EXIT DO
LOOP
Message$ = "No, it is not a power of" + STR$(B)
IF IsIt = 1 THEN Message$ = "Yes, it is a power of" + STR$(B)
PRINT Message$
END
Your solution is actually a program or a routine, not an algorithm, because it has a loop.
However, it does work, with one exception. If you enter a number greater than 1 as the A number and then a 1 for the B or base value, it goes into an endless loop.

Nice work, anyway.
*****
Reply
#33
Oh, ok, I didn't see that post...sorry :oops: , I guess that is what is wrong...

Well what is an algo anyways and why can't it have a loop? :???:
i]"But...it was so beautifully done"[/i]
Reply
#34
Mit,

Regarding the algorithm having a loop, it looks like the majority here feel that it can have a loop. So, ignore my comment, although I still have the same opinion.

In my programming experience, an algorithm is like a formula, usually one or a few lines of straight-line code to obtain a specific result. If it has a loop, or even an IF or GOTO then in my opinion this code is a routine, a function, a subroutine, or a program.

You can look on the Web for definitions of algorithms, and you will find many sample solutions to problems which are being called algorithms, but which are in fact routines or programs.
*****
Reply
#35
Heh...I thought a subroutine and an algo were the same....

Tomatoe, Tomatoe <--well If you heard me pronounce it the meaning would be more clear....How about this A raisin is a raisin is a raisin....or is that the opposite of my point....well I'm confused so disregard.... :lol:

Ok, so mine is out, good job neo.
i]"But...it was so beautifully done"[/i]
Reply
#36
erm, 'tomato'...

IMHO, an algorithm is just a set of steps which one can follow in order to achieve a desired output from a specific input which works identically each time. It doesn't really have anything to do with computer programming specifically. But to each his own...
Reply
#37
heh...ok tomato....But you get my point right?

This is how you change data:

-------Input as data Algo Output as data
The Algo could be as simple as Y=X+1. X is input, Y is output, and Y=X+1 is the algo.

You could also have is as Find_Simple_Radical(X, A, B).
That would require loops + Ifs + Arrays. But still X is input, it does a specific task, which is to find the lowest rad, and will output the same thing for each identical input to A and B. (B Radical A).

To my understanding, If my solution is not an algo then Neo's isn't either. Log is just a function in QB. It has to do some internal calcs in order to do it.

But oh well.

Sorry but I'm feeling like this today. so don't take too seriously.
i]"But...it was so beautifully done"[/i]
Reply
#38
A subroutine, function or procedure are all specific to programming. Algorithms are not necessarily related to programming. There is nothing that says an algorithm can only be implemented on a computer. It is perfectly fine to have a loop inside an algorithm. There aren't any strict rules saying an algorithm cannot contain a loop or anything to that effect.

Besides, a formula is a 'function' in mathematical terms; this means that your argument that a formula is an algorithm, but not a function, contradicts itself.

Loops and conditional statements are essential parts of basic logic. You can't ignore them for writing algorithms...

-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
Reply
#39
Thank you shift, that was exactly what I was trying to say in not so many words. How do you do that? lol

f(x) = x + 1 is a funtion. y = x + 1 is an equation. They are both algos.
i]"But...it was so beautifully done"[/i]
Reply
#40
Quote:Heh...I thought a subroutine and an algo were the same....

Tomatoe, Tomatoe <--well If you heard me pronounce it the meaning would be more clear....How about this A raisin is a raisin is a raisin....or is that the opposite of my point....well I'm confused so disregard.... :lol:

Ok, so mine is out, good job neo.
MIT,
I didn't say your solution was out, only that it had a minor bug. So fix the bug and we'll try it again. Also, it's not out because of the loop in the algorithm issue. The general opinion is that that's ok, so I'll have to go by that.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)