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.

The 20 Line Challenge / Quick Community Challenges

Author
Message
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 2nd Feb 2010 07:50 Edited at: 3rd Feb 2010 00:01
There are community-set challenges on the DBC and DBPro board but these are time consuming mini-projects. I want to start a thread of community challenges (open to DBC and DBP users) that can be completed quickly. Short challenges are a fun test of your knowledge.
There wont be any judging, just code sharing. Feel free to set your own challenges but please place a before the challenge so people looking for challenges can find them easily.
All entries must adhere to the rules of this board and be no more than twenty lines long.


I will start us off...

String Reverse Challenge
Reverse the order of the words in a string, i.e.
"I hate book! Book is stupid!!!"
becomes
"stupid!!! is Book book! hate I"

here's my solution:-


Good luck,

OBese

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
the super24
10
Years of Service
User Offline
Joined: 7th Feb 2008
Location:
Posted: 2nd Feb 2010 18:03
Nice work but the results that I get from running your code is:

"plain.the on mainly falls spain in rain the"
surely it should read this:
".plain the on mainly falls spain in rain the"

and you also forgot the "Wait Key" command at the end.

But anyway, I tried to make an entry but just couldn't figure out the way to do it.....
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 3rd Feb 2010 00:00
I originally tried to do it using only one string, but I'm pretty sure that's impossible without using other variables.

Quote: "surely it should read this..."

You could do it like that but I treated the punctuation as part of the word.

Quote: "and you also forgot the "Wait Key" command at the end."

I am using DBC so there was no need, you can still read the lines over the CLI. Does DBP display the CLI on the bottom of the screen or does it just exit the program? I will add a WAIT KEY, it is the proper way to finish it
Thanks

Here's another mini-challenge that we tried on the DBC board (should be easy for everyone )

Variable Swap Challenge
Swap the value of two variables without using a third variable or data store of any kind. i.e. A becomes B and B becomes A.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
the super24
10
Years of Service
User Offline
Joined: 7th Feb 2008
Location:
Posted: 3rd Feb 2010 17:09
Quote: "I am using DBC so there was no need, you can still read the lines over the CLI. Does DBP display the CLI on the bottom of the screen or does it just exit the program?"

DBpro just exits the program for me hehe....

Anyway, here is my entry for the second "competition" (It's rather crude but it gets the job done), because I can't do the first one at all.



Jukuma
15
Years of Service
User Offline
Joined: 18th Nov 2003
Location: Germany
Posted: 4th Feb 2010 01:04 Edited at: 4th Feb 2010 11:15
Quote: "
COMPARE CASE$ : Return Integer=COMPARE CASE$(string A, string B)
FIND FIRST CHAR$ : Return Integer=FIND FIRST CHAR$(source, char)
FIND LAST CHAR$ : Return Integer=FIND LAST CHAR$(source, char)
FIND SUB STRING$ : Return Integer=FIND SUB STRING$(source, string)
FIRST TOKEN$ : Return String=FIRST TOKEN$(source, delim)
NEXT TOKEN$ : Return String=NEXT TOKEN$(delim)
REVERSE$ : REVERSE$ string
"


wath can you do?

- reverse the string
- get the first token with space
- reverse togater
- loop next token and reverse it else

Jukuma
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 4th Feb 2010 06:38 Edited at: 4th Feb 2010 07:45
@Super
That doesn't swap the values, the variables are either their initial values or the same as each other.

[edit]
Using integer variables is much easier but I've tested it and it is possible with strings too.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 6th Feb 2010 15:55
Here's my solution for string swapping


Surely you can all swap two integer variables?

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
feiting shadow
12
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 9th Feb 2010 08:41
OBese, you use a similar algorithm for swapping two integers.

A= A+B
B= A-B
A= A-B

Signed
------
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 9th Feb 2010 14:08 Edited at: 9th Feb 2010 14:09
@feiting shadow
yes, I would hope everyone on the forum could do that but you are the only one to post.

I just made up another challenge...

Replicated Random Numbers
Print two identical lists of ten numbers generated randomly.
You must print the first list entirely before printing the second.
You may use only one variable (not counting for loop counters).
The list generated must be different every time the program is executed.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Digger412
11
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 10th Feb 2010 18:05 Edited at: 10th Feb 2010 18:54
Here's my string reversal solution:


The random numbers one is easy:
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 11th Feb 2010 16:09 Edited at: 11th Feb 2010 16:10
@Dig
Your string reversal is better than mine
The random numbers is easy but I've noticed that some people use RANDOMIZE TIMER() without realising that RANDOMIZE is a command on its own.

Okay I will step the challenges up a gear

Rainbow Challenge
Draw a gradient across the screen that starts at red, fades through green and into blue.
Preferably all the colours of the rainbow should be visible.

Opaque Triangle
Draw an opaque triangle. If DBP has this as a command you aren't allowed to use it, and you are lucky sods.
[edit] Oh yeah, it's free now so I guess I'm a lucky sod too

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Digger412
11
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 13th Feb 2010 18:57 Edited at: 14th Feb 2010 04:58
Rainbow Challenge:
Uncompressed:

compressed:


I'll start working on the opaque triangle one...that's more difficult I think, never done that before.

EDIT: Okay, I know how to do the triangle, now I just need to be able to draw it..
EDIT2: Okay, I got half of the triangle drawn, but I have to go to work. I'll try it again when I get back later, shouldn't be long. My triangle draws upside down -.-

EDIT3: Okay, my triangle still isn't where I want it, but it IS transparent:

TRANSPARENT Triangle:
Uncompressed:


Compressed:


EDIT4: I have no clue why I was thinking about making it transparent, it needs to be opaque...I went the opposite direction LOL.

OPAQUE Triangle:
Uncompressed:


Compressed:


Transparent Triangle
Draw a transparent triangle of any size. Also create a background, which doesn't count towards the 20-line total, to see the transparency through. The transparency can be of any opacity level or color, but preferably about 50% grayscale (rgb 128,128,128).
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 14th Feb 2010 10:47 Edited at: 14th Feb 2010 11:09
@Digger
Your rainbow didn't work for me, I'm using DBC.
I edited it so it works. I hope I haven't changed it too much.


Edit:
I like your rainbow and the triangle is quite clever.
The problem is they are very rigid. The rainbow is drawn in two halves and the triangle can only be drawn in a corner.
Can you write these as functions so you could give a parameter and get a colour or give co-ordinates and draw any triangle?

The triangle is especially hard. I wrote a function a while ago but looking through it I'm struggling to understand what I did. Luckily I commented the code

I'll have a go at the transparent triangle when I get the time.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Digger412
11
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 14th Feb 2010 18:27 Edited at: 14th Feb 2010 21:32
Okay, I made the filled triangle function. It was a pain to get all of the x#'s and y#'s right o.O

Compressed:


Now I'll have to write another one to work with dots instead, because I need a pixel-by-pixel progression of color >.<

Here's the Rainbow Challenge entry, functionized this time. You can choose you're starting color, and it makes it all in one go =D

It's cool to look at if you change a starting color to 128.0, or if you change two of them to 128.0 (or any other color), you get a few new colors.
Uncompressed:


Here's an extension I made to the rainbow function, now it cycles!


EDIT: I have this so far, it makes two legs correctly. However, it wont make the third leg, since it's between the highest and lowest y's and leftest and rightest x's...



My head hurts, too, I'm going to go and take a break..
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 15th Feb 2010 04:54
Here's your rainbow for DBC


Here's your triangle for DBC.

It doesn't seem to work properly. I had to convert some of the floats to integers so I might have lost something in your calculations.
You have slope1 and slope3, what happened to slope2?

The way I did it was to cut the triangle in half and draw each half as a separate right-angled triangle.

I sorted the coordinates too but I used the variable swap thing.


Here's my full code:


(compressed)

It doesn't feel like 3 months since I wrote that

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Digger412
11
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 16th Feb 2010 04:51
My dot-by-dot triangle doesn't work atm. I wanted it to find the x-coordinate given the y-coordinate on two legs then draw dots in between the x's of those two legs. However, I do know why it doesn't work. It can successfully make two legs, but it won't make the third correctly. I know how to fix it, though. I had just posted what I had at the moment, with the knowledge that it didn't fully work yet. Tomorrow if I have the time I'll finish it. Well, I atleast hope that what I'm thinking of will work...
Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 17th Feb 2010 07:29
@Dig
I had the same problem, that's why I decided to cut it into two triangles.
Will be interesting to see what you do as it is slightly different to mine.

"With games, we create these elaborate worlds in our minds, and the computer is there to do the bookkeeping." - Will Wright
Digger412
11
Years of Service
User Offline
Joined: 12th Jun 2007
Location:
Posted: 7th Mar 2010 04:45
@Obese - I haven't been able to get a work around without doing a lot of extra and unnecessary coding. I know what needs to be done, but I just don't think I'll be able to do it my way in 20 lines.
Monk
10
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 7th Apr 2010 18:57
would using memblock commands to create a 3 vertices thus forming a triangle (opaque or transparent) be cheating?

Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Apr 2010 04:59
@Monk
No, as long as you can draw it and give any co-ordinates.

Dark Dragon
11
Years of Service
User Offline
Joined: 22nd Jun 2007
Location: In the ring, Kickin\' *donkeybutt*.
Posted: 10th Apr 2010 05:18
The triangle Progs are cool.

Monk
10
Years of Service
User Offline
Joined: 25th Sep 2008
Location: Standing in the snow =D
Posted: 10th Apr 2010 13:16


One spinnable memblock triangle. And since it's an object, its easy to make it transparent.

Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 3rd Aug 2010 23:16
Oh a 3D triangle, well that isn't what I thought you meant but it's still good.

Challenge: Make a platform game in 20 lines
It doesn't have to be a full game, just having platforms you can jump about is enough. The bigger the level the better.

IBOL
Moderator
14
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 10th Aug 2010 02:38
now that's a challenge!

IBOL
Moderator
14
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 10th Aug 2010 09:34 Edited at: 10th Aug 2010 21:53
here you go (better commented now) :


arrowkeys to move, space to jump

compressed:


feel free to build off of this model. make it better!

t10dimensional
9
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 11th Aug 2010 07:09 Edited at: 29th Aug 2010 05:06
Here is my 19 liner to the platfomer.

Controls:
Left and Right keys to move
Up to jump
Left click make block
Right click delete block

Space to reset

Compressed:



Uncompressed(Plus feet on your character):


Rich Dersheimer
AGK Developer
Silver Codemaster
9
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 16th Aug 2010 22:56 Edited at: 16th Aug 2010 23:39
...lasrever gnirts eht no ekat ym s'ereh tub ,ytrap eht ot etal m'I ezilaer I



Libervurto
12
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 19th Aug 2010 14:49 Edited at: 19th Aug 2010 14:53
@Rich
!nuf si siht ekil gnipyT .evitceffe tey elpmis yreV

!EGNELLAHC WEN
*ehem*
NEW CHALLENGE!
I am the code Pharaoh, build me a pyramid!
You can use 2D or 3D but each block in the pyramid must be separate and you will have to work out how to position them correctly in the pyramid.
Extra points if you can build any size pyramid (number of blocks in base).
Extra points if you can write a formula that will tell how many blocks are used in any sized pyramid.
Extra points if you can figure out how to make finishing stones that turn the sides of the pyramid into flat surfaces.

Rich Dersheimer
AGK Developer
Silver Codemaster
9
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 20th Aug 2010 02:09 Edited at: 20th Aug 2010 02:09
Here's a 2D pyramid maker... in one line:



and here it is uncompressed, still under 20 lines:



and a screenie:



Attachments

Login to view attachments
IBOL
Moderator
14
Years of Service
User Offline
Joined: 30th Mar 2004
Location: @IBOL17
Posted: 23rd Aug 2010 23:27
@razerx ,
i never commented on your platformer, but i've been very impressed with it.

i tried writing my own using what i think is your thinking and i can't get it. (tried for only 30 minutes, but still...)

good job

t10dimensional
9
Years of Service
User Offline
Joined: 22nd Mar 2009
Location: Code Cave, USA
Posted: 29th Aug 2010 04:47 Edited at: 29th Aug 2010 05:05
@IBOL:
Thanks ,
I was surprised myself that i made it lol. I must tell you that it is no perfect tile collision code. If i hired the max speed any x or y it would mess up. The way i did it was just check for collision in 4 parts of the square:



and whichever side collided first it would move the square to the end of the block in the corresponding direction.

The problem with this method is that when you are going faster than 1/2 the square's width you have two collision spots. Which sometimes causes it to jump to the wrong side of the block. And there is no corner collision.

It works, but could someone explain a better method if they can

EDIT:

I also commented the parts of importance

Teh Stone
9
Years of Service
User Offline
Joined: 12th Dec 2009
Location:
Posted: 29th Oct 2010 12:24
This thread is pretty intresting any one else goin to set a challenge cus it's been 2 months now
Rapidrory
9
Years of Service
User Offline
Joined: 21st Aug 2009
Location:
Posted: 31st Oct 2010 14:31 Edited at: 31st Oct 2010 14:38
Well, going back to the platform game challenge, here is a full platform game i wrote in 8 lines.

Controls are:
Left and Right to move
Up to jump
Space and Up for Hyperjump

The Aim: Avoid the riseing lava

If you jump off the side of the screen, you appear the other side, which means you can get to many more platforms then you otherwise could.



I find it looks best Windowed 640x480

The game gets harder the higher you go, but there does become a point where it is impossible to get anywhere without the hyperjump.

If you find it a little easy, change the variable 'snum' in the first line from 150 to 5, makes it more intresting.

There is no such thing as "Too Fast!"
29 games
13
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 4th Nov 2010 01:24 Edited at: 4th Nov 2010 01:27
That's a pretty cool.

The only thing I would change is to have a different key for the restart and hyper jump. If the lava gets you when you're trying to hyper jump then the game restarts straight away, meaning you don't get to see your score.

What's a decent score? It took a half a dozen goes to get over 700.

Oh, and changing snum does make it more interesting.
Dr Tank
9
Years of Service
User Offline
Joined: 1st Apr 2009
Location: Southampton, UK
Posted: 8th Nov 2010 05:59
The platform games are really neat!
Rapidrory
9
Years of Service
User Offline
Joined: 21st Aug 2009
Location:
Posted: 12th Nov 2010 23:43 Edited at: 12th Nov 2010 23:43
Ok, since no one else seems to be setting any challenges:

Challenge: Make a spinning cube program using no 3D commands

You get extra points if you can get the perspective right
You get extra points if you can shade the sides correctly
You get extra points if you can rotate the cube in any direction

Here's a very basic example just to help if you get stuck:



Good luck!

There is no such thing as "Too Fast!"
thenerd
9
Years of Service
User Offline
Joined: 9th Mar 2009
Location: Boston, USA
Posted: 1st Dec 2010 21:02 Edited at: 2nd Dec 2010 01:25
Oooh, working on that right now!

[EDIT] This is my five-minute attempt... I somehow totally messed up the perspective code, but here it is anyway...Exactly 20 lines too!



Rapidrory
9
Years of Service
User Offline
Joined: 21st Aug 2009
Location:
Posted: 2nd Dec 2010 18:16
Not bad, not bad. Anyone else?

There is no such thing as "Too Fast!"

Login to post a reply

Server time is: 2018-12-18 19:14:30
Your offset time is: 2018-12-18 19:14:30