none
The 50 Line Challange

    Question

  • Set the wayback machine to three years ago. Working on developing projects for my Intro to Programming class, I reminded myself of an article I read back in the early days of the PC. The article was in one of the first PC only magazines, and it was publishing the results of a contest the magazine sponsored. Preliminaries complete, here is what they did:

    They challenged their readers to come up with the most useful BASIC programs they could using only a single line of code in the BASIC interpreter. With the colon instruction separator you could easily get twenty commands on a single line. And the winning submissions were brilliant. One was a screen saver-esk art program, a second was a working word processor, and the third was a full sub chase game. I wish I could share the article and results with this group, but my net search for mention of the article turned up nothing.

    So, in the spirit of the early days of PC programming, here is my proposal to all of you:

    The 50 Line Small Basic Challenge!

    I proposed this challenge about three years ago as the "25 Line Challenge", and it was such a success that it spawned a competition to see who could squeeze the most complex code into the smallest space. The results were brilliant. It was quickly discovered that you could use the String and Stack based nature of the arrays to produce some startlingly compact, obfuscated and unreadable code. I think the best example was Rock-Paper Scissors reduced to three lines (importCode: CTB433-2)

    This time, to keep it from spiraling out of control and losing its impact on learning, I am going to suggest we keep it simple: One command or assignment per line, and no crazy use of arrays or other structures simple to squeeze into the limit.

    So… Give us your clever, entertaining, most creative best, just keep it readable, and keep it under fifty lines.


    Tuesday, October 02, 2012 6:02 PM
    Answerer

Answers

All replies

  • Nice to see this idea back again - I agree that clear readable code should be a one of the conditions.  You don't have to use all 50 lines, just no more.
    Tuesday, October 02, 2012 6:27 PM
    Moderator
  • To get the ball rolling I offer up a version of space invaders.

    SBace Invaders - Import code: MRP297

    A version of this was originally submitted by Davey Wavey for the 25 line challenge. Cleaned up it comes in just under the 50 line mark (not include the excellent comments).

    Enjoy!

    Tuesday, October 02, 2012 7:32 PM
    Answerer
  •  Coming in at 48 lines of code, my encrypter! Try decrypting "Xli ettvs :mqexi wtiih sj pmklx mw 5<4444 qmpiw tiv wigsrh"!

    Well, here it is! DJL447

    Tuesday, October 02, 2012 11:04 PM
  • Vigenere Cipher :KWH475-0

    Analogical Clock : NRZ926

    i code this program when my teacher gave me homework to find out perfect square root of number 2500, 196, 256 using the subtraction method ...

    Perfect Square Root 42 lines : KMC968

    Reduced downed to 22 lines

    Perfect Square Root 22 lines : BKV253

    the core of a much nicer graphical version of the above program.

    Perfect Square Root Graphical : NMH078


    They say working hard is good but i say working smart is best...


    • Edited by 4mir '- Wednesday, October 03, 2012 4:29 PM
    Wednesday, October 03, 2012 4:26 PM
  • I wrote a program that will find Small Basic programs which have less equal than 50 lines.

    Try BRQ733!


    Nonki Takahashi

    Thursday, October 04, 2012 7:16 AM
    Moderator
  • I wrote a small calculator- in 49 lines, so I had one line for a comment left. It just calcs addition, subtraction, multiplication and division of 2 positive integer numbers

    with two parameters and operator given by the user in 1 line like this: 

    please enter what to calculate or 'exit' to end
    10123+456 <Enter>
    
    Result:  10579
    please enter what to calculate or 'exit' to end
    exit_

    TLT468

    (uncommented- old version due I didnt know that there can be a statement followed by a comment in one line)

    TLT468-0

    (commented)


    • Edited by Rene_Miner Tuesday, October 09, 2012 10:49 PM
    Tuesday, October 09, 2012 4:15 PM
  • I wrote a program that could caluclate an accurate answer to Life, the Universe and Everything:

    42

    Many thanks to Douglas Adams for the idea ;)

    OMG42



    • Edited by WoodyWoodpeckerChopsWood Tuesday, October 09, 2012 9:56 PM Spelling Mistake
    • Proposed as answer by Rene_Miner Wednesday, October 10, 2012 2:15 AM
    • Unproposed as answer by Rene_Miner Wednesday, October 10, 2012 2:15 AM
    Tuesday, October 09, 2012 9:54 PM
  • I think you typed your import code wrong, WoodyWoodpeckerChopsWood. Either that or you don't have a program at all.

    I am a 10 year old that loves math, games, and computers. "Everyone is potentially great, you just have to turn it into kinetic greatness."

    Tuesday, October 09, 2012 10:01 PM
  • I dont have any code to do this - I figured a single line of code stating 'Print the number 42' would be the second thought that came to peoples minds, and the first being the book hitchhiker's guide to the galaxy.   I look forward to seeing what people can come up with also.
    Wednesday, October 10, 2012 2:05 AM
  • Another game in 50 lines. This one I callFrantic Clicks. The object is to click the box before it moves to a new location. After each click the game speeds up. Miss the box 10 times in row and the game is over. A good example of Events and Conditional Operations (If's).

    Import Code: BKG332

    Monday, October 15, 2012 9:12 PM
    Answerer
  • I've coded a program to create music.

    It was one of my favourite programs and as I saw this challange I thaught I could write it smaller althout the origanal version had 130 lines.

    It's not so comfortabel like the first version now,but it has just 50 lines(original version is in showcase your programms here).

    I hope you enjoy.

    GraphicsWindow.BackgroundColor="yellow"
    Controls.ButtonClicked=Knopf
    a[1]="C"
    a[2]="D"
    a[3]="E"
    a[4]="F"
    a[5]="G"
    a[6]="A"
    a[7]="B"
    aktteil=1
    start=Controls.AddButton("Start!",10,354)
    For i= 1 To 9
      ton[i]=Controls.AddButton(a[i],-40+(Math.Remainder(i,8)*Math.Remainder(i,9)/i)*50,30)
      teilt[i]=""
      part[i]=Controls.AddButton(i,0+i*50,240)
    EndFor
    GraphicsWindow.DrawText(10,245,"Part:")
    GraphicsWindow.DrawText(350,35,"Oktave:")
    O=Controls.AddTextBox(400,30)
    m=Controls.AddmultilineTextBox(10,100)
    Controls.SetSize(m,580,100)
    letzten=Controls.AddTextBox(310,354)
    GraphicsWindow.DrawBoundText(10,285,1000,"Order of parts:")
    ablauf=controls.AddTextBox(100,280)
    Controls.SetTextBoxText(ablauf,"1")
    box=Controls.AddButton("Just play box",80,354)
    sple=controls.AddButton("Play last notes:",200,354)
    Sub Knopf
      teilt[aktteil]=Controls.GetTextBoxText(m)
      If Controls.LastClickedButton=box Then
        Sound.PlayMusic(Controls.GetTextBoxText(m))
      ElseIf Controls.LastClickedButton=start Then
        stück=""
        For i=1 To Text.GetLength(Controls.GetTextBoxText(ablauf))
          stück=stück+teilt[Text.GetSubText(Controls.GetTextBoxText(ablauf),i,1)]
        EndFor
        Sound.PlayMusic(stück)
      ElseIf Controls.LastClickedButton=sple Then
        Sound.PlayMusic(text.GetSubTextToEnd(controls.GetTextBoxText(m),Text.GetLength(Controls.GetTextBoxText(m))-3*Controls.GetTextBoxText(letzten)+1))
      EndIf
      For i=1 To 9
        If Controls.LastClickedButton=part[i] Then
          aktteil=i
          Controls.SetTextBoxText(m,teilt[i])
        ElseIf ton[i]=Controls.LastClickedButton Then
          Sound.PlayMusic("O"+Controls.GetTextBoxText(O)+" "+a[i]+"4")
          lt=i
        EndIf
      EndFor
    EndSub

    Thursday, October 18, 2012 5:31 PM
  • 43 lines makes my "Eyeballs!"

    GraphicsWindow.BackgroundColor = "Wheat"
    eyeball_num = 2
    For i = 1 To eyeball_num
    rad[i] = Math.GetRandomNumber(150)+50
    pupilrad[i] = rad[i]/5
    irisrad[i] = pupilrad[i]*1.5
    eyecolor[i] = GraphicsWindow.GetRandomColor()
    GraphicsWindow.BrushColor = "White"
    eyeball[i] = Shapes.AddEllipse(rad[i],rad[i])
    GraphicsWindow.BrushColor = eyecolor[i]
    iris[i] = Shapes.AddEllipse(irisrad[i],irisrad[i])
    GraphicsWindow.BrushColor = "Black"
    pupil[i] = Shapes.AddEllipse(pupilrad[i],pupilrad[i])
    posX[i] = Math.GetRandomNumber(GraphicsWindow.Width-rad[i])
    posY[i] = Math.GetRandomNumber(GraphicsWindow.Height-rad[i])
    Shapes.Move(pupil[i],posX[i]-pupilrad[i]/2,posY[i]-pupilrad[i]/2)
    Shapes.Move(eyeball[i],posX[i]-rad[i]/2,posY[i]-rad[i]/2)
    Shapes.Move(iris[i],posX[i]-irisrad[i]/2,posY[i]-irisrad[i]/2)
    EndFor
    While ("True")
      For g = 1 To eyeball_num
      getAngle()
      distfromcenter[g] = Math.SquareRoot(Math.Abs(dx[g]*dx[g]+dy[g]*dy[g]))
      yOnEyeball[g] = Math.Sin(angle[g])*Math.Min(rad[g]/2-irisrad[g]/2,distfromcenter[g]/3)
      xOnEyeball[g] = Math.Cos(angle[g])*Math.Min(rad[g]/2-irisrad[g]/2,distfromcenter[g]/3)
      Shapes.Move(pupil[g],posX[g]+xOnEyeball[g]-pupilrad[g]/2,posY[g]+yOnEyeball[g]-pupilrad[g]/2)
      Shapes.Move(iris[g],posX[g]+xOnEyeball[g]-irisrad[g]/2,posY[g]+yOnEyeball[g]-irisrad[g]/2)
      EndFor
      Program.Delay(10)
    EndWhile
     
    Sub getAngle
      dx[g] = GraphicsWindow.MouseX - posX[g]
      dy[g] = GraphicsWindow.MouseY - posY[g]
      If (dx[g] = 0) Then
        angle[g] = Math.Pi/2
        If (dy[g] < 0) Then
          angle[g] = -angle[g]
        EndIf
      Else
        angle[g] = Math.ArcTan(dy[g]/dx[g])
      EndIf
      If (dx[g] < 0) Then
        angle[g] = angle[g]+Math.Pi
      EndIf
    EndSub

    You move your mouse and it looks at you. Originally when you clicked it would have bigger pupils, but I needed to get rid of that to make it shorter.

    'eyeball_num' is changeable so change it to your preferences! Feel free to modify the entire program to your preferences!


    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'



    • Edited by Math Man Thursday, November 01, 2012 11:29 PM
    Thursday, October 18, 2012 5:47 PM
  • GraphicsWindow.MouseDown = MouseDown
    GraphicsWindow.MouseUp = MouseUp

    Math Man

    They are unnecessary.   (If exist, error occurs)


    Friday, October 19, 2012 6:12 AM
    Answerer
  •     Like "Taiko No Tatsujin"  game.    LNP892-2   Push space key  

    * version Up LNP892-2

    Friday, October 19, 2012 12:54 PM
    Answerer
  • Thanks for reminding me. I just forgot to remove that part.

    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Friday, October 19, 2012 5:38 PM
  • Three Brilliant additions. I particularly love the eyes.

    NaochanON - all you need for a great game is to increase the speed of the dots and anounce game over when to many have passed the gate.

    Saturday, October 20, 2012 9:15 PM
    Answerer
  • A drawing program: FDM232

    Link: FDM232

    You can change the initial angle of each arm, length of each arm, rate at which each arm is turning, and amount of arms by editing the arrays 'Angle,'

    'Dist,' and 'Rate.'

    An example drawn by this program:


    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Saturday, October 20, 2012 11:08 PM
  • NaochanON - all you need for a great game is to increase the speed of the dots and anounce game over when to many have passed the gate.

      OK  Speed up and game over code added.   LNP892-4    enjoy!
    Sunday, October 21, 2012 2:52 AM
    Answerer
  • Love your program. I went a little nuts with it, and put randomizers for all the starting conditions, and have it automatically reset every 15 seconds (or when the space bar is pressed. AND, I managed to fit it into the needed 50 lines.

    Import Code: FDM232-0

    Monday, October 22, 2012 9:05 PM
    Answerer
  • I love what you've done with my program! It's awesome! I love how it resets every 15 seconds!

    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Tuesday, October 23, 2012 1:10 AM
  • Coding Cat, there are some awesome games here!

    Thank you for your great contributions! Can you email me? It's edprice at Microsoft.

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Tuesday, October 23, 2012 8:10 AM
    Owner
  • A very simple maze game

    Import Code: CWC005

    Thursday, October 25, 2012 1:26 AM
  • Great idea of separating X and Y in an array by using colons! I hadn't thought of that! Do you mind if I use that in future programs?

    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Thursday, October 25, 2012 1:48 AM
  • Sure. You can reverse it like this:

      colonPosition = Text.GetIndexOf( location, ":" )
      splitX = Text.GetSubText( location, 1, colonPosition - 1 )
      splitY = Text.GetSubTextToEnd( location, colonPosition + 1 )
    



    Thursday, October 25, 2012 2:07 AM
  • Yes Nik, that was a brilliant bit of logic. It gave me an idea I will have to work on asap.

    In the mean time I cleaned up your code a bit -- sorry, I couldn't help myself, it's a side effect of being a teacher. I replaced your use of the location string (brilliant though that may be) with standard array notation. This pushed the length past fifty lines, so I also took advantage of the increase and added a count down timer. This makes for a more exciting game. I hope you don't mind.

    ImportCode: CWC005-0

    Thursday, October 25, 2012 9:35 PM
    Answerer
  • No, of course I don't mind. 

    Although I just put that trick in there to save a bit of code, it turns out that for some reason it's actually faster than using a multidimensional array - when I was expanding the code for the 8-bit version I did the same as you and replaced it with standard notation - and as soon as I did the redraw speed dropped noticeably, which is why I've kept the colon separated string in the new version.

    I really like what you did with it - turns it into an actual game. I wanted some kind of mechanic but just couldn't get it into 50 lines :)

    Sunday, October 28, 2012 9:38 PM
  •   Maze game  2 patterns . (both all shapes)

      1.....HZG550  (player moves)

      2.....QDF403  ( 1 background  shape moves)   


    Monday, October 29, 2012 11:46 AM
    Answerer
  • Nice take on the idea NaochanON, Both limiting the maze and adding the goal were very sweet.

    And to comment on your curiosity Nik:

    Arrays in most languages are highly optimized to work with a predefined block of memory and function at top speed. This is why you have to set the size of an array and stick to a data type (like strings or integers) with arrays in other languages like Java.

    Smallbasic builds arrays on top of the "Map" object. When you use code like "b[10][25] = 5" SmallBasic is actually generating several lines of code to interact with a hidden "Map" structure where keys such as "10;25" are associated with values such as "5". No indexing is actually done. This makes for a very flexible array system in SmallBasic where you can work code like pets["Cat"]="fluffy", but the trade off is that it is slow.

    Using your string index design played into how the behind the curtains "Map" structure works; making your program run little faster.

    Thursday, November 01, 2012 4:02 PM
    Answerer
  • A very simple maze game

    Import Code: CWC005

    Nike, that's a fun game! I added it as "Smiley Maze Game" in the Program Gallery on the blog here: http://blogs.msdn.com/b/smallbasic/archive/2012/10/06/small-basic-program-gallery.aspx

    If you're up for a challenge (or someone else), here are other things you could add:

    • Time Limit
    • You get 5 seconds with each star you grab
    • When the time runs out, you see your score and can press a button to restart and try again (to beat your score)
    • Intermediate Challenge: Add enemies or other obstacles that make your smiley freeze for a few seconds when he touches them (losing time)

    Of course, that would be way too challenging in 50 lines.

    Anyway, great job!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Saturday, November 03, 2012 6:37 AM
    Owner
  •   Maze game  2 patterns . (both all shapes)

      1.....HZG550  (player moves)

      2.....QDF403  ( 1 background  shape moves)   



    NaochanOn, I added your "HZG550" game as "Star Catcher" in the program gallery: http://blogs.msdn.com/b/smallbasic/archive/2012/10/06/small-basic-program-gallery.aspx

    Fun game! The time limit works great so that you are frantically trying to catch the stars as quickly as possible. =^)

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Saturday, November 03, 2012 6:48 AM
    Owner
  • DueDeLue, DueDeLue

    Show FMJ959


    Best Regards Martin

    Saturday, November 10, 2012 7:56 PM
  • Coding Cat,

    Do you mind if I put your modified version of my drawing program on the list of Small Basic programs on the blog? (giving credit to you, of course)


    I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

    Thursday, November 15, 2012 11:51 PM
  • Please do.  :-)

    Friday, November 16, 2012 8:07 PM
    Answerer
  • Is it okay if we "un-sticky" this at the end of November? That would have given it a good 2 months.

    Thanks!


    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Saturday, November 24, 2012 5:38 AM
    Owner
  • Clearing the sticky note for this challenge. Thanks Coding Cat!

    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Twitter, Wiki)

    Tuesday, December 04, 2012 3:27 AM
    Owner