Posts: 1,956
Threads: 65
Joined: Jun 2003
AGAMEMNUS:
I think you should try to get your method to work. It's the only solution so far that I think is going to work. Nobody is going to implement and test about 700 lines of code to do it the conventional way. That's too much work. Your approach is a shortcut, but can be done. The result is as correct and precise as QB can be.
*****
Posts: 3,343
Threads: 83
Joined: Mar 2003
Hmmm, in relation to this "expression evaluator": StatLib is forcing me to teach the computer to add, subtract all over again... it's a pity Nexinarus didn't suggest a "make a function that adds two strings"...
Posts: 1,956
Threads: 65
Joined: Jun 2003
ORACLE,
In Stalib, you mention having to "teach" it to subtract. What subtract method did you use?
1) the method where if the digit you're subtracting is greater than the one above, you borrow 1 from the top of the next digit position and add 10 to your top digit.
2) the method where if the digit your subtracting is greater than the one above, you add 1 to the bottom of the next digit position, and add 10 to your top digit.
Method 1 is very hard to program because when you go to "borrow" you may have to move over several digit positions to find one that is not zero.
Method 2 is very easy to program.
*****
Posts: 6,419
Threads: 74
Joined: Mar 2002
Quote:Nobody is going to implement and test about 700 lines of code to do it the conventional way. That's too much work.
Of course it is. That's why I implemented this simple evaluator which takes numeric literals and *, /, + and - operations in just 30 lines:
Code:
This was somewhat wrong
EDIT: Check a later post for OK code
Posts: 3,343
Threads: 83
Joined: Mar 2003
Quote:ORACLE,
In Stalib, you mention having to "teach" it to subtract. What subtract method did you use?
1) the method where if the digit you're subtracting is greater than the one above, you borrow 1 from the top of the next digit position and add 10 to your top digit.
2) the method where if the digit your subtracting is greater than the one above, you add 1 to the bottom of the next digit position, and add 10 to your top digit.
Method 1 is very hard to program because when you go to "borrow" you may have to move over several digit positions to find one that is not zero.
Method 2 is very easy to program.
*****
Ahem... I'm adding and subtracting using STRINGS. Each number is stored in a string so numbers in QBasic can be 32,767 digits long. For addition etc I have to extract each individual number and add/subtract them, and then carry. The base routines are actually by Neo for his BIGINT lib (I was gonna use agamemnus's clone but it doesn't work properly), but now I am adding decimal, negative and standard form support (the *hard* part).
Posts: 1,956
Threads: 65
Joined: Jun 2003
ORACLE,
I figured you were adding/subtracting strings.
You didn't answer my question of what method you're using to subtract. Is it that you're using Neo's routines and you don't really care?
*****
Posts: 3,368
Threads: 195
Joined: Jan 2003
Yeah, only the addition works 100% right..
Perhaps the multiplication. Bleh. Evil evil evil.
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest.
Posts: 1,956
Threads: 65
Joined: Jun 2003
1) the method where if the digit you're subtracting is greater than the one above, you borrow 1 from the top of the next digit position and add 10 to your top digit.
2) the method where if the digit your subtracting is greater than the one above, you add 1 to the bottom of the next digit position, and add 10 to your top digit.
-----------------------------------------------------------------------------------
AGAMEMNUS,
Try subtracting 123 from 9999. If this works, try subtracting 999 from 10000. If this in turn doesn't work, then the subtract routine is using method #1 above. Implementing method #1 is not easy, actually it's a mess.
Most Americans who have to implement subtraction will use method #1 because that's what they were taught in school, sad to say. My mother was from Europe, and before I went to school she taught me the method #2 of subtracting. So, when I first implemented a subtract routine, it was easy.
*****
Posts: 6,419
Threads: 74
Joined: Mar 2002
^_^'
Anybody seen/tested my idea?
Posts: 1,956
Threads: 65
Joined: Jun 2003
Nathan,
I think Nexinarus should test and comment on your submitted routine. He's the author of this challenge.
*****