Shop OBEX P1 Docs P2 Docs Learn Events
Coding competitions — Parallax Forums

Coding competitions

AImanAIman Posts: 531
edited 2011-11-29 04:48 in General Discussion
I was just thinking that it would be fun to have a competition to see who can do a project in the shortest amount of code. Obviously it would have to be broken out by age or skill level, but still, the projects could be different for the different languages.

For example, the shortest code for running a servo with a sonar attached, or the shortest code for GPS or tempature sensing.

In short (bad pun) take the top 10 or 20 most commonly used items and show the shortest code.

BUT HERE'S THE CATCH - the contestants have to post their code so others can use it AND it has to have comments for each line of code so others can follow it.

The theory is we could learn a lot from each other while still having fun.

Thoughts?

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2011-11-02 10:42
    Things like this (coding golf -- or whatever) pop up every once in a while, but it's usually for a simple process. Usually not more than a few lines.
    The problem with more complicated things is you easily run into rewarding shorter code, regardless of the quality of execution, as long as it meets the bare minimum requirements.

    I don't think it is a bad idea, but the requirements for each set of code need to be well specified if we are to make it a competition. Do you allow any pre-existing objects, just ones that are "well accepted", anything in the OBEX, or none at all?
  • BitsBits Posts: 414
    edited 2011-11-02 10:49
    I like the idea but you should make it so that the code can be written by everyone, perhaps no hardware needed.
  • AImanAIman Posts: 531
    edited 2011-11-03 07:20
    Do you allow any pre-existing objects, just ones that are "well accepted", anything in the OBEX, or none at all?[/QUOTE]

    My main intent is to get people thinking about the most commonly used things and ways to make the code shorter. A lot of times people code longer because they don't know how to code in shorter ways or haven't ever been shown how to code in shorter ways.

    To use a VBA example the following two pieces of code do the same thing in Excel - get the value from cell A1 using a variable called test.

    i=1
    test = ThisWorkbook.Worksheets("Sheets1").Range("A" & i).Value
    or
    Test = ThisWorkbook.Worksheets("Sheets1").Range("A1").Value

    Verses

    Sheets("Sheet1").select
    Range("A1").select
    test = Range("A1").value)

    They do the same thing except that the very first one allows for a dynamic range while the others are static.

    To put this in terms of robotics, coding a servo with sonar by sonar pulses being sent in between the servo pulses allows for a servo to go back and forth while running a sonar. The coding is much shorter than running two loops and trying to get them to match.
  • potatoheadpotatohead Posts: 10,261
    edited 2011-11-03 08:54
    Maybe we could place a resource limit on these. Say the binary image cannot exceed 1K, or 2K, etc... That helps to answer the many, "well can I use X?" questions. Use whatever you like, but make it fit.
  • AImanAIman Posts: 531
    edited 2011-11-27 20:38
    I like where both of you are going with this. The entire intent is to have people learn how to code efficently and the only way to do that is to stretch yourself. Its much more efficent both in space and in compute speed to tell a computer what to do with less code.
  • wiretripperwiretripper Posts: 7
    edited 2011-11-28 08:44
    I'm interested. Do you already have something in mind for how you would like to proceed?
  • ercoerco Posts: 20,259
    edited 2011-11-28 09:08
    Good on ya. There's lots of bloated code these days since memory is cheap and plentiful. Writing efficiently cruched code is almost a lost art now. But back in the days of the BS1, when there was only 256 bytes of code memory (about 80 instructions), you really had to conserve and re-use. The minimalist in me likes to get the most of any hardware I use, which includes using the smallest processor for the job. Not everything needs a Propeller! That inspired me to issue my own robotic challenge this weekend:
    http://forums.parallax.com/showthread.php?136008-Black-Friday-Deals&p=1054736&viewfull=1#post1054736
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-11-28 13:01
    Hey that's a neat idea! I love it. I used to pay a lot of attention to code size and execution times back in the day. Like Erco said, it's a lost art now with cheap and abundant resources.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2011-11-29 04:48
    Actually, the Propellor has a 512-16 for an actual 496 word limit in Assembly code on each Cog. So this might provide a magic number for setting a limit to your solutions.
Sign In or Register to comment.