Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / - DBPro Coding Challenges -

Author
Message
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th Jun 2006 01:08 Edited at: 6th Jun 2006 01:11
@Nicholas Thompson

Here's the zip archive for Daemon's challenge. Sorry it's a bit late - had to weed out some files that weren't intended as entries. I've also omitted a few that were just fixing minor bugs (e.g. Sven B) or including accidentally omitted code (e.g. McLaine).

A few entries won't compile with the default DBPro editor unless you change the concatenation symbol (e.g. yours and Ric's I think).

Let me know if I've missed anyone.

[Edit: just noticed the zip file name got corrupted, it originally read "Daemon's Challenge 21 May 06.zip". Perhaps you could change it to something more sensible?]

Attachments

Login to view attachments
Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 6th Jun 2006 03:30
I like the math idea!
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 6th Jun 2006 03:50 Edited at: 6th Jun 2006 03:52
^same. i think ill finally join the competitions
McLaine
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 6th Jun 2006 06:34
Sounds like a winner to me. Be an interesting little challenge.

It's not my fault!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Jun 2006 10:06
Sounds like I won the topic challenge, now if only I could win the actual challenges this easily!

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th Jun 2006 11:14
well it'd be ironic if you dont win a challenge you set And you know how irony rules in IT (computers only crash if you haven't saved for more then 10 minutes/300 words, you only get a virus if you need your computer to be clean, programs dont work in front of you and then work perfectly in front of the IT manager, etc)

[center]
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th Jun 2006 12:16
Quote: "programs dont work in front of you and then work perfectly in front of the IT manager"

Don't even get me started on that one!

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Dave1974
20
Years of Service
User Offline
Joined: 1st Aug 2004
Location:
Posted: 6th Jun 2006 18:45 Edited at: 6th Jun 2006 18:46
Quote: "programs dont work in front of you and then work perfectly in front of the IT manager"


Quote: "Don't even get me started on that one!"

Personally I love it when that happens.

Perhaps it got something to do with being an IT manager.
[Edited for spelling]
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 7th Jun 2006 14:01 Edited at: 7th Jun 2006 14:03
Ok, I agree with the math challenge:

Math Challenge

Create a math parser.
Some idea's that could make it interesting:
- Basic math parsing, if you type 5-(3-5)*6 then that would give 17.
- Draw functions like y = 5x + 2 or y = sqrt(25 - x^2)
- A program that can calculate 1 unknown x (or more but that would make it very hard)
like 2x = 5 would give: x = 2.5
- ...

Deadline: wednesday 21 june(2 weeks)

Everyone ok with it?

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
McLaine
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location:
Posted: 7th Jun 2006 15:38
All cool here.

It's not my fault!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 7th Jun 2006 20:47
Quote: "A program that can calculate 1 unknown x (or more but that would make it very hard)"


just solving for X alone would be tough

so far it only handles addition and subtractino. I think parenthesis could be handled easily with recursion. It's all just a matter of reading ahead for the right sign order.



"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 9th Jun 2006 17:34 Edited at: 9th Jun 2006 17:35
Phaelax
Good so far...

BTW. For all entries:
Calculate always in this order:
1) everything between brackets ()
2) square roots and powers ^ and sqrt()
3) * and /
4) + and -

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 9th Jun 2006 20:35
well hopefully ppl know order of operations before trying such a challenge.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 10th Jun 2006 05:40
Has there really only been one entrant so far? Wow.

Well, my code doesn't handle parenthesis yet, but it does exponents, division, multiplication, subtraction, and addition (in that order!).



Insanity is just a state of mind
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 10th Jun 2006 09:04
I considered a similar method using an array also, but decided to find a way against it.

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Cert
18
Years of Service
User Offline
Joined: 10th Jun 2006
Location:
Posted: 10th Jun 2006 18:31
Hi all,
I am in need of an individual to create a game for me.
The game will use an SQL database to pull data from.

anyone interested please contact me off forum

bruce@bfq.com
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 12th Jun 2006 04:49
Parenthesis work now!!!

I am sure there is a better way, but this is the simplest for my mind to get around.






Insanity is just a state of mind
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Jun 2006 05:35
Hey Cert, does this look like a thread to ask ppl to do work for you? Use some common sense ffs.

Cant check it now as im on the mac, but sounds good daemon. Hope some others give this a shot.
Did anyone ever state a time limit?

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 12th Jun 2006 07:33 Edited at: 12th Jun 2006 19:21
A time limit? Do you mean the deadline for the math competition? If so then yes, Sven B said...

Quote: "Deadline: wednesday 21 june(2 weeks)"


---------------------Added on so that I don't double post-------------

I promise I slept a little bit.

I have updated my code so that it now can handle negative numbers. So if you put 5*-3 it knows that you are not actually subtracting 3.

Also, now if you put 3(5+2) it will understand that this is short hand for 3*(5+2). It can handle (5+2)3 and (5+2)(3+1) as well. (It does not need to be addition inside the parenthesis, I am just giving examples.)

Now I was wandering if I should make my program check for mistakes in the equation such as illegal parenthesis or putting two operations in a row. Should I make the program check for these or assume that the equation is correct?

And here is the code.



Insanity is just a state of mind
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 12th Jun 2006 19:30
@Nicholas Thompson

Did you get the zip archive for Daemon's challenge (posted 5th June)? I see it's not on your site yet. Let me know if there are problems with the files (I've just noticed that the wording of my earlier message was a bit misleading ...)
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 12th Jun 2006 21:42 Edited at: 12th Jun 2006 21:43
@Daemon

Very nice, The steps are nicely given beneath eachother. Though I felt like some steps could be ignored ( 15*(3+2) = 15*(5) = 15*5)

@Phaelax

When is the next update?

I am surprised nobody tried the function plotter yet...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Jun 2006 22:05
gotta parse the equation before we can plot it

"Using Unix is the computing equivalent of listening only to music by David Cassidy" - Rob Pike
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 12th Jun 2006 22:07 Edited at: 12th Jun 2006 22:07
good point...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 13th Jun 2006 00:32
@GG - I did indeed, just didn't get a chance to do it until now. Its done though (cheers for reminding me)

[center]
Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 14th Jun 2006 06:15
Wait a second! This has already been done in *gasp* under 10 lines!

http://forum.thegamecreators.com/?m=forum_view&t=37012&b=11

Sorry about that... I just had to!




Back to buisiness. Version 1 of my program is ready:



Currently handles: +, -, *, /, ^ and brackets.

Coming soon: trig functions, sqrt(), pi etc...

Coming after that: Lets try the plotter!

P.S. An interesting program to study: http://www.graphcalc.com/. It has a 3D graphing component that could be an interesting addition to an entry...
Sven B
19
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 14th Jun 2006 16:11 Edited at: 14th Jun 2006 16:13
@Segan

I have a few points on this one

i typed:
5/0 and the program gave me 0(???)
I don't really mind this one because of the simple reason that there isn't any other value more apropriate to return by the function.

I typed:
15+5*3-8*(3-2) and the program gave me 166
isn't this supposed to be 22?

i'd wait with the "coming soon" and start sorting out priority first...

It's the programmer's life:
Have a problem, solve the problem, and have a new problem to solve.
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 14th Jun 2006 19:19
you're right - that is supposed to be 22

[center]
Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 14th Jun 2006 19:32 Edited at: 14th Jun 2006 20:05
@ Sven

Thanks for your comments. I THOUGHT that I had ironed out all the bugs, but it appears there is still some left...

Edit:

Well, upon further inspection, I managed to find and eliminate the second bug fairly easily (I will post source code later). However, when checking out the "devide by zero" example, I stumbled on what seems to be an odd DBPro bug (or perhaps a feature). Try this



That code spits out the familiar "devide by zero" error. However, when this code is run:



The output is zero... with no error.

Weird.....

Edit2:

Here's the updated code. I hope that all the errors are now dealt with!



Note: The error message that pops up when you attempt to devide by zero is temporary until I get the time to make a better solution.
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 15th Jun 2006 00:34
Good
(9+2)*4=44

Bad
((9+2)*4)=114

Quote: "I hope that all the errors are now dealt with!"

Has coding something ever taken you only two tries? Wow. It never does with me. (Except once, and then I woke up)

Insanity is just a state of mind
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 15th Jun 2006 03:12 Edited at: 15th Jun 2006 04:08
hey. i started on mine. it does ()s, ^, *, /, +, -, and implicit multiplication signs (adds * before ( and after ) if required) (standard stuff)

ill add pi and other stuff later

it was somewhat hard because i havent coded in forever. i forgot hwo damn fun coding is! its 131 lines, here you go

now im allowed to look at other entry codes although looking at others' code always gives me a headache (not that coding my own didnt give me a headache)



im wondering if my code is neat? any suggestions in terms of style?
sixblades
20
Years of Service
User Offline
Joined: 30th Jul 2004
Location:
Posted: 15th Jun 2006 04:22
Wow, you guys have all done an amazing job at this contest (I was working on my own entry a while back, but I had to stop to study for finals ). One thing that I feel I should add: you've all got excellent math parsers, yet not one of them can solve for x in the simplest equation. As I recall,
Quote: "
- A program that can calculate 1 unknown x (or more but that would make it very hard)
like 2x = 5 would give: x = 2.5
"

Anyway, amazing work so far. (sorry if this is a bit critical? finals make me bitter...)
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 15th Jun 2006 18:44 Edited at: 15th Jun 2006 19:33
@qwe
It took me a while to find something my code could do that yours couldn't. In the end I found something. Negative numbers. Your program is helpless against 5*-3.


--------------------------------------------------------------------------------------------------------------------------------------


Put a "p" where ever you want the value of pi. It will assume the multiplication if you want it to.

Also, I made it repeat itself over and over again instead of end, since that seems to be the popular thing



Insanity is just a state of mind
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 15th Jun 2006 22:53 Edited at: 15th Jun 2006 23:42
^woops, forgot about the negative symbol. there, it just took one line of code added. i added stuff yesterday too

[s]in, [c]os, [t]an, sq[r]t, a(b)s, previous [a]nswer

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 16th Jun 2006 01:30
@qwe
Looks like I am going to have to update my code some more.
By the way, I think you should make it so that "5p" is recognized for implied multiplication to make it "5*p".

Insanity is just a state of mind
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 16th Jun 2006 03:32
^koo, i implimented it, as well as showing the user the steps leading to the answer like yours

are you going to add a plotter?
Joe Cooning
21
Years of Service
User Offline
Joined: 29th Mar 2003
Location: United States
Posted: 16th Jun 2006 19:57
I finished the grapher and equation solver, but I can't figure out how to make agood parser that can solve for 'x' (as sixblades mentioned). Has anyone managed to do anything with that one yet?

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 16th Jun 2006 20:23 Edited at: 16th Jun 2006 21:37
@qwe
I'm not going to let my code fall behind yours unless you really do something amazing, so if you add a plotter then I probably will do it too.

I hope you don't mind how similar my new code looks to yours.

Here it is. It does all that qwe's code does except you put a "-" to show it is negative instead of a "`", and it can do the operation "!" now.

If you hit enter then it will redo the equation again. If you put "+5" it will recognize it as "a+5"



Insanity is just a state of mind
Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 16th Jun 2006 20:57
Well, after some consideration, I've decided to rewrite my equation solver. I want to try a completely different method of solving, which unfortunately means an almost complete code rewrite. However, when it's done, it should be way better than before!
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 16th Jun 2006 22:10 Edited at: 16th Jun 2006 23:33
Quote: "if you add a plotter then I probably will do it too."
already did some parts were frustrating
Quote: "I hope you don't mind how similar my new code looks to yours.
"
nope, dont mind

to sustain the arms race, mine now adds an implicit [a] at begining (if equation starts with an operator), pressing enter re-does previous equation, and it can handle the factorial (!) function

i also fixed an error. 1+2-2+2-1 should return 2, but it returned -2, because it did all the addition before subtraction (so it became 3-4-1). i didnt realize that the order of evaluation would matter between additions and subtractions

daemon i believe you forgot sqrt and abs
Joe Cooning
21
Years of Service
User Offline
Joined: 29th Mar 2003
Location: United States
Posted: 16th Jun 2006 23:40 Edited at: 16th Jun 2006 23:47
Here's the code for mine so far.

Edit: It handles ()*/+- and for the grapher, it recognizes things like 2x



Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 17th Jun 2006 00:09 Edited at: 17th Jun 2006 00:25
@qwe
Quote: "daemon i believe you forgot sqrt and abs"


oops. I'll get to that. Your absolute value is not perfect yet though, if I put b(-5) it has an error. Sure I could put b(0-5), but I don't feel like it.

@Joe Cooning

I didn't know that case could be used with strings.


--------------------------------------------------------------------------------------------------------------------------------------

I added what I was missing (except a plotter, that will keep me quite for a while), and I added "E" for scientific notation.



Insanity is just a state of mind
Joe Cooning
21
Years of Service
User Offline
Joined: 29th Mar 2003
Location: United States
Posted: 17th Jun 2006 00:17
@Daemon: What case?

Here's a quick update. You can now view a table(sort of) with the graph. And the equation parser now recognizes 2(2) stuff (that is it would return '15' for '5(3)'). Enjoy!



Note: If you want to change size of graph, then adjust the x and y Min,Max and Step in the grapher function.

qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 17th Jun 2006 00:41 Edited at: 17th Jun 2006 00:51
^nice job. mine is slightly different, it automatically steps each pixel instead of a defined step value

about the case, i think he meant he didnt know you could select case a string



Quote: "oops. I'll get to that. Your absolute value is not perfect yet though, if I put b(-5) it has an error. Sure I could put b(0-5), but I don't feel like it."


the negative symbol is '`'

daemon, he has something we don't... you can backspace on his program :/
Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 17th Jun 2006 01:51 Edited at: 17th Jun 2006 01:58
@qwe
o yea, forgot about your funny negative thing.

your plotter line will keep going up through the little box which looks like it was supposed to stay in.


Quote: "daemon, he has something we don't... you can backspace on his program :/ "

Uhh... I have no idea what this is supposed to mean
--------------------------------------------------------------------------------------------------------------------------------------
I'm still working on my plotter. I have made it so that the program takes up the entire screen again for it. Mine has some funny errors with the plotter right now. Should have been finish half an hour ago, but it doesn't like me.

Edit: Wow, that didn't take long for me to fix. Ok, if you want to change the xmin and max you have to change those variables in the code for now. The y's can't be set yet. Yet that is. I also will get around to adding the table. This is it so far.



Insanity is just a state of mind
Joe Cooning
21
Years of Service
User Offline
Joined: 29th Mar 2003
Location: United States
Posted: 17th Jun 2006 01:56
@qwe: Yeah, I just did connect-the-dots for the graph because I figure it showed you what you wanted, and it goes a lot faster.

qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 17th Jun 2006 03:19 Edited at: 17th Jun 2006 03:48
Quote: "your plotter line will keep going up through the little box which looks like it was supposed to stay in.
"
yeah, that's been fixed
Quote: "Uhh... I have no idea what this is supposed to mean "

if you make an error, you can use the Backspace key while entering the equation. On ours, you're stuck with the error



btw, neither mine, joe's, nor Daemon's code can run x/x^x in the grapher correctly
Joe Cooning
21
Years of Service
User Offline
Joined: 29th Mar 2003
Location: United States
Posted: 17th Jun 2006 05:55 Edited at: 17th Jun 2006 06:24
Here's another update (and probably one of my last). It now handles all it did before plus sin,cos,tan,pi, and e (used as s,c,t,p, and e, respectively). Just trying to add some of the features you other guys have. See what you can throw at it.

Edit: I just changed the code because I realized I made a huge messup in my toString function



By the way...what's wrong with x/x^x on mine? I compared my programs results to my graphing calculators, and they both matched (on my last code snippet, you just have to turn the xStep# up to .01, and on this new one, it's the gStep#).

Daemon
18
Years of Service
User Offline
Joined: 16th Dec 2005
Location: Everywhere
Posted: 17th Jun 2006 06:19 Edited at: 17th Jun 2006 06:58
Updated my code. You can now choose the window and the step, or if you just want to see the graph hit enter to go with the defaults.

Also, the plotter will accept dividing by 0 to make something 0 just so that you can see the rest of the graph. I found it annoying that if one instance for x had it dividing by 0 that you could not see the graph.

And yes, x/x^x looks funny, but then again it looks funny on my graphing calculator. The only difference is that my graphing calculator is not connecting all the points.

Use the up and down keys to scroll through the fancy table with the graph.



Insanity is just a state of mind
qwe
21
Years of Service
User Offline
Joined: 3rd Sep 2003
Location: place
Posted: 17th Jun 2006 07:43
Joe I get an error at line 346 (and 59 but i always just take out the '1' and it works). im using BlueIDE. the program seems to be fine if i just comment out the 'if', 'else', and 'endif' surrounding that line O.o

About x/x^x, on my graphing calculator, there is nothing to the left of the y axis. on our programs (except joe's latest version), there is a bunch of stuff to the left of the y axis going up and down. i am using the same window on the calc as on the programs btw
CPU
21
Years of Service
User Offline
Joined: 4th Jul 2003
Location: Carlsbad, CA
Posted: 17th Jun 2006 16:37
dang.. these are some pretty nice entries... I'll have to see if I can manage an entry, that is if I can finish before I leave for vaction tommorow But good job all of you!

CPU

[center]K-OS Battlefields
IS
///---///---///---UNDER CONSTRUCTION---\\\---\\\---\\\
[center]

Login to post a reply

Server time is: 2024-11-25 02:44:00
Your offset time is: 2024-11-25 02:44:00