locked
Challenge of the Month - November 2013 RRS feed

  • General discussion

  • These challenges are intended for people who are learning to program for the first time or for those returning to programming who want to start using SmallBasic.  Some will be easy, some will be hard - but they will all make you think, and more importantly be GREAT FUN!

    Please post your solutions / partial solutions / questions / feedback etc. into this thread that will remain 'sticky' for the month.  The only rule is that your solution must use standard SmallBasic methods (no extensions).

    It would be good if people could post their problems with these challenges so that a discussion can start so that everyone can learn from each other.

    Also post feedback on the kind of challenges that you want to see more of in the future.

    Curriculum Challenges 2.5

    1. Use the Clock to time user response times when a box is flashed up on the GraphicsWindow.
    2. Use the Clock properties say good morning, afternoon, even or night in the TextWindow
    3. Use the Dictionary to say if a user entered word can be used as a noun, verb, adverb, adjective etc.

    Maths Challenges

    1. Write a program to rationalize any fraction, for example 35/70 is 7/10.

    Graphics Challenges

    1. Write a graphical program to count your calories by selecting foods and portion sizes.
    2. Write a program to show a face that can be modified by selecting properties and styles (a bit like a Wii Mii).

    Text Challenges

    1. Reverse the characters in a text string.
    2. Change the first letter of each word in a string to a capital letter.
    3. Validate a password has at least 6 characters, has upper and lower case letters and at least one number

    Physics Challenges

    1. Write a program to simulate a ball rolling on a table that can be tilted by the user.

    Game Challenges

    1. Write a clone of the Connect 4 game for 2 players (or harder using AI to play against the PC).

    Community Suggestions (by Nonki)

    1. Write truth tables about Not, And, Or, and Xor.
    2. Draw a picture of the Olympic flag.
    3. Simulate a kaleidoscope.

    Community Suggestions (by 8Bit Pony)

    1. Make a program that counts how many times a button on the Graphics window has been clicked.  For an extra challenge, make the program count how many times the button was clicked in One minute.

    Do you have an idea for a future challenge? Please post it here!


    • Edited by litdev Friday, November 1, 2013 7:20 PM Additional commulity challenge added
    Friday, November 1, 2013 6:34 PM

All replies

  • My partial solution to Curriculum Challenges 2.5

    1.Use the Clock to time user response times when a box is flashed up on the GraphicsWindow

    SMJ627

    I've done it by adding only 1 shape, then hiding, zooming and repositioning.

    What I haven't worked out yet is why do I have to run the ShowBox() routine 1st at the setup to get the ShowBox() and HideBox() subroutines working properly for the main loop?


    • Edited by Jibba j Sunday, November 3, 2013 6:59 AM
    Sunday, November 3, 2013 6:58 AM
  • LitDev~

    Would it be okay if I copy/link these challenges to my Fb page each month?

    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Tuesday, November 5, 2013 4:21 AM
  • @ Joman - Sure
    Tuesday, November 5, 2013 8:00 PM
  • Hello,

    Here is my solution to the first Text Challenge (reverse the characters in a string):

    'Program to reverse the characters in a string
    'November 2013 Text Challenge
    
    StringToReverse = "I like Small Basic"
    ReversedString = ""
    StringLength = Text.GetLength(StringToReverse)
    
    For i = StringLength To 1 Step -1
      ReverseString = ReverseString + Text.GetSubText(StringToReverse,i,1)
    EndFor
    
    TextWindow.WriteLine(StringToReverse)
    TextWindow.WriteLine(ReverseString)

    Wednesday, November 6, 2013 4:17 PM
  • Hi, again,

    I have an idea for a future challenge (in keeping with current events in the news lately): implement the ROT-13 substitution cypher using Small Basic. For those who are interested, check out the Wikipedia page for ROT-13 which gives lots of details for how it works.

    Wednesday, November 6, 2013 4:21 PM
  • Nice use of the reserve loop.

    ROT-13 looks interesting.

    Wednesday, November 6, 2013 6:03 PM
  • Hello Anthony~

    Is it okay for me to alter your code (but keeping some variables and strings of code/logic) and expanded it a bit?


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?


    • Edited by Joman Mied Thursday, November 7, 2013 3:29 AM
    Thursday, November 7, 2013 3:29 AM
  • I started game challenge: LSM678.

    Screen shot of a program Connect Four 0.1a


    Nonki Takahashi

    Thursday, November 7, 2013 12:45 PM
  • Sure. No prob. I look forward to seeing your enhancement :-)
    Thursday, November 7, 2013 7:25 PM
  • Thanks bro!

    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Thursday, November 7, 2013 8:12 PM
  • As well as "enhancing" Anthony's Text Challenge logic, I'm also tackling the Curriculum Challenge 1: Time user responses to a box being flashed on the graphics window.

    I am making CC1 a 5 level game, 5 being the craziest, and the idea is that you react to different colour boxes with different "trigger keys." First, it'll start slow with one colour, but then I want it to be mayhem in level 5: rapid flashes and four colours to keep track of.

    But may I please use Timer for this instead of Clock? I know it defeats the purpose of the challenge, but I think Timer might be better in my circumstance.


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Saturday, November 9, 2013 6:12 PM
  • @ Joman, of course - the challenges are just ideas to play with.
    Saturday, November 9, 2013 6:55 PM
  • I like using these challenges to try out different things. Especially adding extra features to them.

    I've used both Timer and Clock for time keeping and have drawn my own conclusion to which is best.

    I'm currently working on the "See how fast you can click on a box" challenge. Having a ball with this one.

    Saturday, November 9, 2013 8:44 PM
  • This is still demo version of game challenge: LSM678-0.

    I made a png file with GIMP 2 from screen shot of previous version of this program.

    Screen shot of a program Connect Four 0.2a


    Nonki Takahashi


    • Edited by Nonki Takahashi Sunday, November 10, 2013 12:23 PM additional information
    Sunday, November 10, 2013 12:18 PM
  • I also added check routine for four connected same color disks straightly: LSM678-1.

    But you can not play Connect Four with this program yet...

    Screen shot of a program Connect Four 0.3a


    Nonki Takahashi

    Monday, November 11, 2013 6:13 AM
  • Nonki, it's really helpful to see how you build this.

    Monday, November 11, 2013 8:10 AM
  • This version is for 2 human players: LSM678-2.

    Click anywhere in the column to drop new disk.

    Screen shot of a program Connect Four 0.4b


    Nonki Takahashi

    Monday, November 11, 2013 9:17 AM
  • Very nice! It's been AGES since I've even seen Connect Four :-)
    Monday, November 11, 2013 9:39 PM
  • This is a sample for community suggestions (by Nonki) 1: LVG886.

    Screen shot of a program Truth Table 0.1


    Nonki Takahashi

    Tuesday, November 12, 2013 3:37 AM
  • This is a sample for community suggestion (by Nonki) 2: FCF037.

    Screen shot of a progam Olympic Flag


    Nonki Takahashi

    Tuesday, November 12, 2013 2:40 PM
  • I rewrote Connect Four for AI (very weak) vs human: LSM678-3.

    Screen shot of a program Connect Four 0.5b

    I wrote a logic for draw but there is a bug...


    Nonki Takahashi


    • Edited by Nonki Takahashi Thursday, November 14, 2013 1:17 AM weak comment
    Thursday, November 14, 2013 1:16 AM
  • Wow! Very nice!

    No movï es da casti. Movï es da movïo.

    Thursday, November 14, 2013 1:17 AM
  • Although it always adds an extra space to the end of the string of text, it works very well.

    My enhanced version of Anthony's Text String Reverse program.

    It can take text from the clipboard- no switch if text isn't found though; it takes for granted there is -or text right from the TextWindow (by using ".Read()") and will reverse it before your very eyes.

    Import code: DTH104   (May need Osariok's Data extension... Not sure what else, but I can't remember what commands each extension provides...)

    >>Also, I would like to eventually make this a graphic program... Use Shapes.Animate for each letter or something :)<<

    Enjoy!

    -JOman


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?




    • Edited by Joman Mied Thursday, November 14, 2013 8:14 PM
    Thursday, November 14, 2013 5:29 AM
  • But may I please use Timer for this instead of Clock? I know it defeats the purpose of the challenge, but I think Timer might be better in my circumstance.

    >>I will actually use Clock... Upon reflection, Clock would be a better time-keeping device.<<

    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Thursday, November 14, 2013 5:33 AM
  • Thank you, Micheal Zhong ChinaSoft (MSFT CSG) for verifying my account.

    Thank you, FLB993 Fire Flames, Fibonacci Spiral, KKQ196 Koch, NNM734 Lissajous & RZJ747 Newton Raphson.



    Friday, November 15, 2013 5:39 PM
  • Enough is enough. I started doing cc2.5 and then started adding/trying out more features that I didn't plan for from the outset. My planning skills aren't that good because I don't have that much hindsight to benefit from, but i'm getting some, and I don't making big mistakes for the purpose of learning.

    Here's some of the things I learnt from this:

    1. I learnt heaps about the game loop by not using one when I should've.
    2. ...from this, never get in a situation where anything could be used at the same time,
    3. .... and update the screen at a regular rate with any changes.
    4. by not using the right structure the logic rapidly became convoluted. Time to stop. Futile to continue.
    5. an Event Driven Program with a gui needs an event loop if it's going to pack some features

    1. picked up some good build skills, mainly code something and know exactly what it does and how it does it. As opposed to fixing something and figuring that it should be ok without fully understanding how it works.
    2. unit test and end to end test.
    3. learnt some more multi thread stuff by going nuts with the timer. And found a bug with Shapes.Zoom

    I'm definitely going to code an extensible drop down menu system for my future sb programs.

    To see some dodgy unfinishable code: THQ411 LMM385

    Saturday, November 16, 2013 8:54 PM
  • "I'm definitely going to code an extensible drop down menu system for my future sb programs."

    I am making a spin-off of the Windows desktop and I know the pain with menus. If you happen to make the "drop down menu system," may I get it from you please?


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Saturday, November 16, 2013 9:16 PM
  • Of course Joman and thanks for asking.

    My thoughts on the drop down menu thing for me are it shouldn't be too hard to do and use once I'm more solid with some basic structure stuff. My build stuff just got a bit better so that should help because features like this make more lines of code in just one editor screen.

    I'm about pick a simple EDP to do and code it using the format/style litdev uses in his latest article.

    Small
    Basic: Dynamic Graphics

    re that click the box program. I just used 1 shape and reshowed it using the timer. I put the Clock calcs in the a separate thread, I should not have done that.

    Saturday, November 16, 2013 9:54 PM
  • Actually I retract my comment: "I put the Clock calcs in the a separate thread, I should not have done that."

    It just infinitely loops away in the background off just 1 tick, so it doesn't hog the timer. It can interact with the main loop, you just need to make sure nothing is used at the same time.

    So I can't see a problem with it but I can't really see a need for it (yet) either.

    Saturday, November 16, 2013 11:38 PM
  • Hey Joman

    Here's the drop down menu sample WTM170

    You might be able to do it with less code if you put the menu focus feature, i.e. the Highlight..() subroutines into one sub that loops through them and finds which one has the focus.

    http://en.wikipedia.org/wiki/Focus_(computing)

    Also I sometimes do my flags as:  flag = "Open Sub Menu",  probably better to do as: openSubMenu = 1.

    Don't know why I do that.. :)

    btw i'm finishing that program and the menu is working well. It just takes a lot more code to collect and dispatch all the extra input coming in. Bit by bit on this one for me.




    • Edited by Jibba j Sunday, November 17, 2013 11:23 AM
    Sunday, November 17, 2013 11:01 AM
  • So I tried to make the user response time challenge a game... Having some trouble. I decided to come up with this for the time-being, except that I am getting this message a lot, but not all the time, after clicking my start button (PS: Doesn't look good in SilverLight):

    

    Also, my GraphicsWindow isn't clearing as fast as I thought it might...


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?


    • Edited by Joman Mied Monday, November 18, 2013 10:28 PM
    Monday, November 18, 2013 10:27 PM
  • Hi Joman,

    The crash report says maxValue must be greater than zero and the second line is about Math.GetRandomNumber, so a test case:

    x = Math.GetRandomNumber(-1)

    This causes the same crash, so somewhere  you must be using a negative number for this.

    Your code:

      Width = Math.GetRandomNumber(400)
      Height = Math.GetRandomNumber(Width/3)
      Program.Delay(Math.GetRandomNumber(3000))
      GraphicsWindow.FillRectangle(Math.GetRandomNumber(Width-20), Math.GetRandomNumber(Height-20), Width, Height)
    

    Width can be anything from 1 to 400

    If it is less than 20, then Math.GetRandomNumber(Width-20) will cause the crash.  Also for Height (can be less than 20).

    Check this line, is it right?

    Response = ElapsedTime/100

    Nice work on the challenge.  If I click outside the rectangle I also win!


    Monday, November 18, 2013 10:57 PM

  • Width can be anything from 1 to 400

    If it is less than 20, then Math.GetRandomNumber(Width-20) will cause the crash.  Also for Height (can be less than 20).

     Right, that makes sense to me now! I can't believe I missed that when I was writing the code (-_-) *facepalm*


    As for the "If I click outside the rectangle I also win!" I was going for that so the user didn't have to chase the rectangle around the GW :P

    But, yeah, I do wonder why, at least for me, the GW doesn't clear that quickly after the "Start" button is clicked... By the order I have the program run, I don't see why there would be any issues with other lines of code... I think that may be what it is at least.

    Also, the line Response = ElapsedTime/100 is correct as I wanted to display the response time in terms of seconds. I know that 1/1000 of a sec is a millisecond but I don't know what the proper term for 1/100 of a sec would be... The smallest value that Timer can tick with is 10, not 1, indicating it can go as low as 1/100 of a sec. That's why I chose seconds :)


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Tuesday, November 19, 2013 2:45 AM
  • Every 10 ms in the timer you add 10 to ElapsedTime so the ElapsedTime is in ms not 1/100s. This is why the time reported in secs looks wrong.  I only checked this because the timer reported seem much too long (say 12 sec, when I knew I had only taken about 1 sec).

    So either divide by 1000, or add 1 not 10 in the timer.

    Tuesday, November 19, 2013 10:13 AM
  • This is a sample for community suggestion (by Nonki) 3: GTB559-3.

    Screen shot of a program Kaleidoscope 0.1


    Nonki Takahashi


    • Edited by Nonki Takahashi Wednesday, November 20, 2013 9:18 AM bug fixed for Silverlight
    Tuesday, November 19, 2013 4:56 PM
  • Right, thanks! I thought it looked right but now I see what you mean.

    Sorry about that litdev! :S


    I can write 1000 lines of code in roughly 10 seconds. Here's how:
    i = 1

    For i = 1 to 1000
    TextWindow.WriteLine(i+ ". Code")
    Program.Delay(10)
    EndFor

    Make Sense?

    Wednesday, November 20, 2013 9:40 PM
  • My solution to

    Curriculum Challenges 2.5

    1. Use the Clock to time user response times when a box is flashed up on the GraphicsWindow.

    MXM676

    I didn't do the event loop properly - my goal for next challenge.

    Tried out some stuff with the timer and built a drop down menu bar.

    Saturday, November 23, 2013 8:18 PM
  • These are my ideas for a future challenge:

    1. Calculate the frequency of other pitches while pitch A is 440.00Hz.
    2. Create a control called "Radio Button".
    3. Develop an operation between colors.

    Nonki Takahashi


    • Edited by Nonki Takahashi Thursday, November 28, 2013 1:47 AM changed from 440 to 440.00
    Thursday, November 28, 2013 1:43 AM
  • This is my challenge for math challenge: TQX303.

    Fraction (ex. 4/6) ? 35/70
    = 1/2
    Fraction (ex. 4/6) ? 49/70
    = 7/10
    Fraction (ex. 4/6) ?


    Nonki Takahashi



    • Edited by Nonki Takahashi Thursday, November 28, 2013 3:32 AM changed font etc.
    Thursday, November 28, 2013 3:09 AM
  • Maths Challenges    fraction, for example 35/70 is 7/10

    My easy way.

    TextWindow.WriteLine("Fraction  input as.. 40/95")
    a= TextWindow.Read()
    p= Text.GetIndexOf(a,"/")
    b= Text.GetSubText(a,1,p-1)/Text.GetSubTextToEnd(a,p+1)
    Maxvalue=10000000000
    For i=1 To Maxvalue
      c=b*i
      If (c- Math.Floor(c))<=0.00000000001 Then
        baseI=i
        i=Maxvalue
      EndIf
    EndFor
    TextWindow.WriteLine(a+" = "+math.Floor(c)+"/"+baseI)
    Thursday, November 28, 2013 4:01 AM
    Answerer
  • My further challenge for connect four: LSM678-5.

    Screen shot of a program Connect Four 0.7

    But stil not so strong...  There may be some bugs.


    Nonki Takahashi

    Thursday, November 28, 2013 12:31 PM
  • Wow, how short!

    Nonki Takahashi

    Thursday, November 28, 2013 12:33 PM
  • Suggestion for December Challenge:

    • Build an extensible drop-down menu

    Sunday, December 1, 2013 5:44 AM
  • Amazing Math solution NaochanON
    Sunday, December 1, 2013 6:10 AM
  • This is my last challenge for Connect Four: LSM678-6.

    Screen shot of a program Connect Four 0.8


    Nonki Takahashi

    Sunday, December 1, 2013 12:55 PM
  • LDS920-3

    My revised solution to the Math Challenge.

    I tested it for large fractions already in their simplest form and found it took around 10s. No good.

    So I ditched some unnecessary looping / calculation and tripled its speed.

    Case: 75031 / 5641222 now takes < 3s.

    Could further optimise by filtering input, so 1/100 = 1/100, 100/100 = 100/100, etc without need for factoring.

    I used prime number factors. I noticed programs on the net can return large fraction answers almost instantly.

    Sunday, December 1, 2013 8:52 PM
  • Nonki,

    Awesome solution. Super fast calculations.

    Sunday, December 1, 2013 8:59 PM
  • Nonki's solution, for the Math Challenge, is amazing.

    Returns answer instantly.

    Sunday, December 1, 2013 9:01 PM
  • A Kaleidoskop Simulation found: VML310 or VML310-1


    Best Regards Martin

    Wednesday, December 18, 2013 5:17 PM
  • VML310-1, beautiful!  I like this program.

    Nonki Takahashi

    Wednesday, September 10, 2014 9:57 AM