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
coolgames
19
Years of Service
User Offline
Joined: 26th Sep 2005
Location: Oregon, USA
Posted: 5th May 2006 06:18
That doesn't count. Your program has to calculate the answer.

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 5th May 2006 06:33 Edited at: 5th May 2006 06:34
Here's Spooky's code optimized to 8 lines, über fast:



Again, that's Spooky's code, not mine!

I'm willing to bet that no one can do this in less than 8 lines.


Darth Vader
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 5th May 2006 08:02
Quote: "That doesn't count. Your program has to calculate the answer."

I know lol


When in Trouble with anything visit here your number one stop for help
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th May 2006 10:02 Edited at: 5th May 2006 20:18
7 lines!


ah crap, Milky already posted a similar solution.


Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th May 2006 11:00 Edited at: 5th May 2006 11:36
My version with 8 lines:



Fewer lines, more code, slower to run.

[Edit: just seen Phaelax's post about val() - I forgot about using the collating sequence which simplifies the code a lot]

It would be nice to get rid of the inner loop somehow ...

[Edit2: Here we go, 6 lines!



By an extension of the same idea we can get it down to 3 lines ...]
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 5th May 2006 12:27
I think Green Gandalf is gonna win. You can even shorten that small code by another line;



@Phaelex - if you read higher up than your post I already posted a recursive function that was reused by Milk

I'm surprised that DBPro lets you do

IF condition THEN truecommand ELSE falsecommand

That shouldn't be allowed really. It should either be;

IF condition THEN truecommand1 : truecommand2 : truecommand3

or

IF condition
truecommand1
truecommand2
ELSE
falsecommand1
falsecommand2
ENDIF

Boo!
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th May 2006 12:50
Spooky - why do you find that surprising? That works fine if you only have one command per state.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th May 2006 13:05
Quote: "You can even shorten that small code by another line;"


I resisted the temptation to do that.

@Spooky

Is it possible to get your version down to 5 lines using a similar idea as follows? Outline:



Removing the end gives a "dirty" finish to the program - but at least you get the answer (if you fill in the gaps).
Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 5th May 2006 13:08
Maybe this challenge could be extended to be a "cool use of recursion" which could include some usefull function for recursion, an example of fractals or a graphical effect?

Neofish
20
Years of Service
User Offline
Joined: 7th Apr 2004
Location: A swimming pool of coke
Posted: 5th May 2006 19:21 Edited at: 5th May 2006 19:24
Phaleax, it would be 5005, if I had read the q..

its 0 to 999999 inclusive, i did 0 to 1000000 inclusive

although that would still be 5004 :/ maybe you lot aren't counting 0, and i am

New site!
spooky
22
Years of Service
User Offline
Joined: 30th Aug 2002
Location: United Kingdom
Posted: 5th May 2006 19:43
correct, he stated that under 1000 would be 219 numbers, but if we counted 0 then answer would be 220.

Looks like Ric got his inspiration from this site;

http://mathschallenge.net/index.php?section=problems&show=true&titleid=never_decreasing_digits&full=true

Can anyone fathom out all that stuff about binary numbers?

Boo!
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th May 2006 20:22 Edited at: 5th May 2006 20:24
I think I understand the binary method.

Oh ok, that method explains how to "produce" increasing numbers given a binary string.


Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th May 2006 21:40 Edited at: 5th May 2006 22:24
I'm sure there's a simple one line mathematical formula which gives the right answer to Ric' challenge. Looking for thinking cap now ...

And here it is:



This might work for a 12 digit number as well. Anyone want to check it?
Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 5th May 2006 21:58 Edited at: 5th May 2006 21:59
This could be ended already So many entrys

Theme park simulator wip boards

Segan
19
Years of Service
User Offline
Joined: 28th Aug 2005
Location: Canada
Posted: 5th May 2006 21:59 Edited at: 5th May 2006 22:22
I have spent a couple of hours thinking that as well, but this looks a bit more complex than previously thought.....

Here's what I have come up with so far:

If we had been using binary, the number of increasing numbers would be: n where n is the number of digits in the number.

For trinary (is that even a word? ), the number of increasing numbers would be: (n+1)(1+n/2)-1 or n + (n^2+n)/2

For quatronary (cause I'm weird) though, I haven't been able to get a sequence yet...
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th May 2006 22:33
Quote: "For quatronary (cause I'm weird) though, I haven't been able to get a sequence yet... "


See my previous post. I could make it one line of code if I didn't bother with listing the results for 10, 100, 1000, etc.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th May 2006 22:41 Edited at: 5th May 2006 22:46
The speed of progress on this challenge has astounded me! 5004 is the correct answer, but that wasn't the difficult part - getting it down to 5 lines already though is impressive - Green Gandalf and Spooky both doing some serious optimising. I'm reasonably confident that it can go down to 4 lines though .... infact, I'm sure it does, although there is a big speed sacrifice. Whether you could get it to less than 4 though - I'm not so sure.

As for the deadline, I may bring the judging forward, although I'll wait to be certain that everyone has done before I do so.

@Spooky: Good to see you getting involved in this one - I've admired your code since I stumbled across your Mandlebrot set code when I first started using DBPro a couple of years ago. And yes, you found me out - that was the website I 'sourced' this challenge from!

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 5th May 2006 22:45 Edited at: 5th May 2006 23:41
Two lines are sufficient - I'll post the code after I've had supper ...

And here it is (and it should be obvious what to do if you want the number if the limit is 10 million, etc):



Of course you eventually hit the limit for integers in the numerator, but that's another challenge ...
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th May 2006 22:47
Seriously? Ok, get that supper down quick!

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 5th May 2006 22:57
Dont halt the competition yet I'm so close to coming up with a formula to use on 1 line I can taste it.

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th May 2006 23:05
Ok - this is getting tense!

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 5th May 2006 23:15
Right - I have just got it to 3 lines, so I know that is possible. Looking forward to seeing it done in less than that, though.

Chris Franklin
19
Years of Service
User Offline
Joined: 2nd Aug 2005
Location: UK
Posted: 5th May 2006 23:20
Ric you really should get msn i could learn a lot of dbp if you showed me how
(Sorry to go offtopic)

Theme park simulator wip boards

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 5th May 2006 23:25 Edited at: 5th May 2006 23:33
Wow, getting crazy mad head aches lol , I have it all layed out, I can see the pattern, I just gotta turn this into a damn formula.

*RUCCUS prays for a Eureka moment*

<EDIT>

Ah well Im going rock climbing, gotta clear my mind a bit. If the contest is still on when I get back tonight Ill work some more on it, if not Ill share my findings, maybe someone else'll be able to figure out the formula.

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th May 2006 00:24
@Sunrise - you dont have to use MSN to learn DBP
@Ruccus - Are you sure you can represent this with a non-recursive formula?

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 6th May 2006 00:42
I've got a table layed out with various random numbers, their answers, and a bunch of other findings I've... found , I can connect each number to another number, it's just making the last connection that's getting me stumped.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2006 00:49
I've already done it - look at the edit to my previous post ...
The end is near
19
Years of Service
User Offline
Joined: 19th Jun 2005
Location: USA
Posted: 6th May 2006 01:04
and thats a wrap, the winner...

nxt challenge plz!!!

stargate sg-1 the one show that never gets old

Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 6th May 2006 01:05 Edited at: 6th May 2006 01:06
Excellent work GG! You've got it to 2 lines,



.... however ..... I 've just done it in 1 line. The contest remains open.

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 6th May 2006 01:07 Edited at: 6th May 2006 01:08
Nice work there Gandolf, I couldn't have gotten that far.

For the next challenge I suggest that we do something similar to this, but with prime numbers. You could be judged by the length of your code, as well as the speed/efficiency of it...


The end is near
19
Years of Service
User Offline
Joined: 19th Jun 2005
Location: USA
Posted: 6th May 2006 01:15
how do you do it in 1 line if you have to print and wait in 2 lines!?!

stargate sg-1 the one show that never gets old

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 6th May 2006 01:16
I think it was sarcasm...


RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 6th May 2006 01:18
Well for starters, nobody said it had to wait. But you can always do this;



Goodjob on getting it Gandalf, though that method seems like it wouldnt work for any number, could you explain it a bit?

Nicholas Thompson
20
Years of Service
User Offline
Joined: 6th Sep 2004
Location: Bognor Regis, UK
Posted: 6th May 2006 01:29
Ruccus - one of the rules was no ":"

NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 6th May 2006 01:34
One line.




At least farting ferrets are better than stinky stoats.
The end is near
19
Years of Service
User Offline
Joined: 19th Jun 2005
Location: USA
Posted: 6th May 2006 01:39
thats how you do it!!!
new winner!!!!

stargate sg-1 the one show that never gets old

NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 6th May 2006 01:44
Owned.


At least farting ferrets are better than stinky stoats.
The end is near
19
Years of Service
User Offline
Joined: 19th Jun 2005
Location: USA
Posted: 6th May 2006 01:54
pwnage!!!

stargate sg-1 the one show that never gets old

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2006 01:55
Quote: "could you explain it a bit?"


Now that IS a challenge ...

I suspect a formal proof would require the mathematician's idea of "induction". Anyway, I spotted a pattern and it works up to 7 digit numbers (and I'm sure it's true for all powers of 10). One of my earlier posts gave the general formula which I expect to work up to DBP's limitations on integer arithmetic.

The pattern starts easily enough: up to 10 there are obviously 10-1 (=9) possibilities, i.e. excluding zero. Up to 100 there are the original 10-1 plus 9 two digit numbers starting with 1, plus 8 two digit numbers starting with 2, and so on down to 1 two digit number starting with 9 (i.e. just 99). This makes a total of 55-1, i.e. 54 different numbers. This can be expressed as 10*11/(1*2)-1. Next, consider numbers up to 1000 which Ric gave us, i.e. 219. Cutting a long story short, this is 220-1, i.e. 10*11*12/(1*2*3)-1. The pattern extends to 10000, 100000, etc.

I confess an element of inspired guesswork crept into the solution - but also Spooky's original for-loop solution made me suspect what sort of mathematical formula might be relevant.

Now comes the difficult bit - thinking up the next challenge. I'm tempted by Nicholas Thompson's suggestion about recursive functions. I'm also tempted by a random terrain/random texture/random sky challenge. I like the idea of preparing interesting scenes totally in code without media. I'm also open to persuasion - Ric, is there a time limit on my decision?
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2006 02:01
Quote: "One line."


Yup, looks like a new winner to me since we haven't reached the original deadline yet. Phew! Thought I was going to have to think of a challenge for a while there.

Can anyone get it down to half a line?
NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 6th May 2006 02:05
That would be possible in DBC only, where there is a limit of 255 chars/line. However, I believe the shortest version already outdoes 128 chars.


At least farting ferrets are better than stinky stoats.
Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2006 02:15
Quote: "However, I believe the shortest version already outdoes 128 chars."


True - I concede.
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 6th May 2006 02:31
Well done Nex, you read my mind.

However, I'm going to go with what I think is the most sporting decision, and award the price to Green Gadalf, who actually spotted the mathematical pattern and coded it in one line. As Ruccus mentioned, the 'wait key' command wasn't actually needed anyway - I only stated that the code had to calculate the answer, and that it did, regardless of whether you had time to read it or not!

So - after what has to be the shortest, yet fastest moving challenge ever, I officially declare that Green Gandalf is the winner, and the new challenge setter. Congratulations!

Generally, the new challenge should be set within about 24 hours of winning - should give you enough time, and keep the challenge thread moving. I like the random texture/sky idea, although a couple of the other suggestions have already been done, namely, terrain generation and prime number finding. Recursive functions would be interesting to play with, although I prefer challenges with more specific outcomes, rather than specific methods - as it allows for people to tackle the same challenge in a range of different coding styles. Nick also made a couple of good suggestions a page or two back - wave effects, and gui elements like menu systems, buttons etc.

Coding Fodder
21
Years of Service
User Offline
Joined: 25th Sep 2003
Location: Somewhere in my cerebralcortex
Posted: 6th May 2006 02:39
Wow you folks are good!! I did not even have time to check what the challenge was and it is down to 1 Line!!! I don't think I can do better than that. But I did like how there was a flurry of posts and people feeding off each others methods rather than the usual wait 1.5 weeks and then see 3 people square off with only a few updates and no real code swapping. Great for guys like me who have short attention spans. I will just have to wake up in the middle of the night to beat you UK folk to the punch.

Is it safe to say Nex is Next? This one does not really require judging. Go you Ferrety ferret you.

Something really catchy that makes people stop and think about the meaning of life and say to themselves "My but thats clever"
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 6th May 2006 02:50 Edited at: 6th May 2006 02:55
No - if you read my previous post, Green Gandalf is the winner, as he did it in 1 line also. I ignored the 'wait key' command as it was only added for the convenience of seeing the result, and was not needed to do the actual calculation. Nex's small adaptation was a clever trick, but the rules state that 'you can only use someone elses code if you improve upon it in a substantial way and give appropriate credit', which I didn't feel was the case, as GG did the most substantial part of the work.

Green Gandalf
VIP Member
19
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 6th May 2006 03:40 Edited at: 6th May 2006 03:45
OK. Here's a first stab at the next challenge. Should be something for everyone here.

1. Make a random island terrain, textured with a random texture, set in an ocean textured with another random texture and a randomly textured sky above.

2. Make the ocean have waves (Nick Thompson is halfway there already).

3. Optional extra: show how recursive functions can help create a random texture.

The idea (as usual) is that everything is done in code, should be fast to set up, smooth and easy to explore and is visually interesting. Code should be short (but more than one line is probably necessary!). [External media are only allowed if (a) they are created and re-used by the program, and (b) they are essential for the relevant DBP commands (such as "set terrain heightmap").]

To give everyone a chance here's a special starting bonus: Green Gandalf's random fractal magic cloud texture generator. Feel free to use, modify or ignore it. A simple way of getting different textures is to modify the final colour components of the final bitmaps produced by my program.



I'm open to suggestions for changes (within Ric's 24 hr deadline) but expect this to be close enough unless it's too close to previous challenges (feel free to use code from those if you think it helps).

Two week deadline, say 10am UK time 20 May, sound reasonable?
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 6th May 2006 04:07
I would much like to do another short challenge such as the one we just did. Like CF said, it was fun with all the quick updates and exchange of code...


The end is near
19
Years of Service
User Offline
Joined: 19th Jun 2005
Location: USA
Posted: 6th May 2006 04:22
so that is the next challenge, or maybe?

stargate sg-1 the one show that never gets old

Darth Vader
19
Years of Service
User Offline
Joined: 10th May 2005
Location: Adelaide SA, I am the only DB user here!
Posted: 6th May 2006 08:48
Quote: "[External media are only allowed if (a) they are created and re-used by the program, and (b) they are essential for the relevant DBP commands (such as "set terrain heightmap").]"

Ric says in his rules no external media allowed!
Congrats GG, while you were winning this I was still figuring out how the maths problem is supposed to work out! (Me and maths, are slow!)

When in Trouble with anything visit here your number one stop for help
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 6th May 2006 08:59
I think we should change the rule slightly, in that the user can select what the maximum number is. Cause a lot of these seem to be hard-coded for exactly 1 million.

Quote: "input str$((10*11*12*13*14*15)/(1*2*3*4*5*6)-1),nothing$ "


say i want to only calculate for 1000 digits, i'd have to rewrite the equation rather than simply state n=1000.


Login to post a reply

Server time is: 2024-11-24 22:47:44
Your offset time is: 2024-11-24 22:47:44