Challenge of the Month - June 2013 RRS feed

  • General discussion

  • Welcome to the monthly SmallBasic Challenge! 

    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 Challenge 1.5

    (1) Write a program that asks the user for 2 numbers and what calculation to perform (+, -, / or *), then uses a different subroutine to do the required calculation.

    (2) Get the user to enter a word and use the Dictionary method to get its definition.  Create a subroutine to check if it can be used as a noun, and if it is, use a second subroutine to get and print the first noun definition.

    Small Challenge 1

    Write a program that outputs a multiplication table, using an input multiplier and maximum to multiply it by.

    For example multiplier 7 and maximum 12.

    1 x 7 = 7

    2 x 7 = 14


    11 x 7 = 77

    12 * 7 = 84

    Small Challenge 2

    It is useful to be able quickly do approximate maths in your head.  To help, write a program that shows approximate (to the nearest integer) divisors of 100.

    For example:

    100/7 ~ 14

    100/17 ~ 6

    Maths Challenge

    Write a program to calculate the area of regular polygons (equal side lengths and equal internal angles).  The first is an equilateral triangle, the second a square, etc.  The user enters the number of sides and their length.

    For large number of sides, the area should approximate that of a circle.

    Game Challenge

    Write a repro of the Tron game, Google for it, here is a simple scratch version.

    Physics Challenge

    Calculate the time for a satellite to orbit the Earth at different altitudes.  What altitude is a geostationary orbit (orbits in 24 hours).

    G*M*m/r/r = m*v*v/r

    G is gravitational constant  6.67384 E-11 m3 kg-1 s-2

    M is the Earth mass 5.972 E24 kg

    m is the satellite mass (orbit doesn't depend on this)

    v is the satellite velocity (m/s)

    r is the satellite distance from the Earth center

    The Earth radius is 6371 km

    Community Challenge 1 (By Nonki)

    (1) Write ASCII code table.

    (2) Make any kind of roulette (wheel).

    Community Challenge 2 (By Jibba Jabba)

    When people register on a theatre website, the email address is used as the login name and the user is requested to enter a password to use with the account.

    A user’s details include: email address, password, first name, surname and address.
    These are stored in a csv file.

    When a user logs in, they enter their email address and must enter their password before accessing their account details.

    code a program which:
    • asks for an email address and password
    • searches the file for the email address
    • if the password is correct it displays the customer details
    • it displays a suitable error message if the password is incorrect.

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

    • Edited by litdevModerator Sunday, June 2, 2013 1:23 PM Earth radius corrected
    Saturday, June 1, 2013 9:18 PM

All replies

  • litdev~

    I see you edited the post because of a typo :P  Maybe you should leave one on purpose next time XD

    I think I will attempt Community Challenge 2 because I still have that piece of code that, I think it was, NaochanON gave me for my faux log-in program which makes the password display as dots on-screen; plus I can manipulate my current code for this challenge with ease. 

    Wish me luck!

    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")

    Make Sense?

    Sunday, June 2, 2013 5:57 AM
  • I had a couple of typos since I wrote it quickly.  The first one I wrote crashed on publish so I had to do it all again - must remember to take a copy of long posts before publishing.

    Anyway good luck with the challenges.

    Sunday, June 2, 2013 10:17 AM
  • Is this also a typo:

    The Earth radius is 6371 m

    or is the earth realy so small?

    Jan [ WhTurner ] The Netherlands

    Sunday, June 2, 2013 12:42 PM
  • Well done this should be km!  Updated.
    Sunday, June 2, 2013 1:23 PM
  • I have an idea for a future challenge.

    How about a smart program. For example the user can add a task and tell the program what to do if he tell the program to use this task. Here a small example code:

    'This example isn't complete. That is only a simple idea.
    i = 1
    TextWindow.WriteLine("Welcome. Please enter a new task.")
    name[i] = TextWindow.Read()
    task[i] = TextWindow.Read()
    TextWindow.WriteLine("You successfully created a new task.")
    i = i + 1

    Greetings Timo

    Monday, June 3, 2013 12:46 AM
  • This is my alpha version program for game challenge: LZN025.

    At this point, I have no idea about this game AI.

    Nonki Takahashi

    Monday, June 3, 2013 2:20 PM
  • Nonki - great start - you could make it a 2 player game and forget the AI.
    Monday, June 3, 2013 6:12 PM
  • Hi Litdev, pls excuse as my Math is really rusty.

    When I substitute some arbitrary values into the equation "G*M*m/r/r = m*v*v/r" it doesn't balance for me. Am I looking at this the wrong way?

    You have to have a dream so you can get up in the morning. - Billy Wilder

    Monday, June 3, 2013 8:47 PM
  • Fist you must have units correct, so use kg, m and s (kilogram, meter and second) everywhere consistently.

    The left side of the equation is the gravity force (down towards the Earth) which for an orbit exactly equals the centripetal (or centrifugal force like the one that tries to throw you off a fast turning roundabout).  This is why someone in orbit feels no force (weightless) - the forces balance.  Gravity is much the same in low orbit as it is on earth, the difference in orbit is that you are also being 'flung out' by flying round the earth in a circular orbit.

    So we want to find r so that the period of rotation is 1 day.  For a radius r, the length of a circular orbit is 2.pi.r, and if this is done in 1 day = (60*60*24s)

    Therefore the velocity v is 2.pi.r/(60*60*24) in m/s.

    Now try solving the equation - write both sides down and see what cancels - like m/r on both sides

    G*M/r = v*v


    r = G*M/v/v


    v = SQRT(G*M/r)

    Now perhaps put in the expression above for v and solve for r, or just put some r in and find v.

    v*v = v^2 = [2.pi.r/(60*60*24)]^2 = G*M/r

    so r^3 = G*M/[2.pi/(60*60*24)]^2

    Monday, June 3, 2013 9:43 PM
  • Thanks

    You have to have a dream so you can get up in the morning. - Billy Wilder

    Monday, June 3, 2013 9:54 PM
  •  My entry for Curriculum Challenge (1). JTK500
    I will be doing (2) also. :3

    I am a 12 year old learning how to code using small basic.

    Wednesday, June 5, 2013 11:27 PM
  • Entry for Physics Challenge : Import Code - FGG850

    Please let me know if i have done something wrong...


    Merry Xmas!

    • Edited by 4mir '- Friday, June 7, 2013 2:09 AM updated the program id
    Thursday, June 6, 2013 12:34 PM
  • 4mir, did you upload the right file or post the wrong ID?
    Thursday, June 6, 2013 7:45 PM
  • My bad, i was in hurry.

    here is the correct code : FGG850

    Merry Xmas!

    Friday, June 7, 2013 2:09 AM
  • My bad, i was in hurry.

    here is the correct code : FGG850

    Merry Xmas!

    4mir,  very nice! 

    What altitude is a geostationary orbit (orbits in 24 hours)?

    You'd better add a code to show "Bingo ! "(or other word ), if it's a geostationary orbit .

    Friday, June 7, 2013 5:51 AM
  • Second entry for Physics Challenge

    Import : XWM381

    save this picture in the program directory.

    Merry Xmas!

    Friday, June 7, 2013 6:42 PM
  • 4mir, at 24 hours you have very close to the answer of 35,786km.

    Kepler observed that any orbit sweeps equal area in equal time, so any elliptical orbit with the same area as the circular orbit takes the same time to orbit.

    As a follow up, if the sun is 150 000 000 km away from the earth, what is the mass of the sun? 

    When we know the mass of the sun we can calculate the distance to any planet from the sun from the time it takes to go round the sun (its year).

    Friday, June 7, 2013 7:03 PM
  •  Can someone help me with my problem? I am working on curriculum Challenge 1.5 (2), and it reads "2) Get the user to enter a word and use the Dictionary method to get its definition.  Create a subroutine to check if it can be used as a noun, and if it is, use a second subroutine to get and print the first noun definition."

    all i really want to know, is how can i only print out the first definition of the noun if it is? If you need more clarification, just say so. i'll edit this post for that.


    I am a 12 year old learning how to code using small basic.

    • Edited by 8Bit Pony Saturday, June 8, 2013 6:37 AM
    Saturday, June 8, 2013 6:32 AM
  • When you get the definition back (e.g. for the word "car") you have to search through it to see if contains the phrase "car (noun)". If it does, then find the next occurrence of "1." and print this line.

    You can find new lines by checking for the ascii character 13 or 10.

    The following may help to work on this.

    definition = Dictionary.GetDefinition("car")
    For i = 1 To Text.GetLength(definition)
      char = Text.GetSubText(definition,i,1)
      charcode = Text.GetCharacterCode(char)
      TextWindow.WriteLine(charcode+" "+char)
      If (charcode = 10) Then

    Saturday, June 8, 2013 9:03 AM
  • My solution to Physics Challenge in the textW.  JSV465

    I'll do it in the graphicsW next.

    Sunday, June 9, 2013 1:13 PM
  • Hi litdev and all.

    Thanks for the physics challenge, very interesting stuff. Do the above results look reasonable?

    I commented degrees of significance and uncertainty in my code. I could reference the ELEO and GEO results and confirm their accuracy, but found no references on the EHEO orbit results.

    NB: I used L1 as an arbitrary "distance" only for a EHEO being aware that this point doesn't lie on the E plane (earths axis tilt) and is used as point of origin for a Halo orbit. I could've just put 1.5M km but thought it interesting to use L1 as distance ref and not a point in space. Perhaps it could be relevant as a manoeuvre radius to force the sat into a halo orbit. Lay mans physics.

    It's amazing how much stuff is drifting around in space.

    Sunday, June 9, 2013 10:16 PM
  • @Jibba Jabba, this all looks good - I'm always surprised by just how ENORMOUSLY BIG space is.
    Monday, June 10, 2013 5:07 PM
  • My entries for June Curriculum 1.5 (1) and (2).


    Also, my entries for the June Small Challenges 1 & 2:




    Tuesday, June 11, 2013 4:54 AM
  • This is a sample for community challenge 1 (1).

    TextWindow.WriteLine("ASCII CODE TABLE")
    TextWindow.WriteLine(" + 0 1 2 3 4 5 6 7 8 9 A B C D E F")
    For code = 0 To 127
      rem = Math.Remainder(code, 16)
      div = Math.Floor(code / 16)
      If rem = 0 Then
        TextWindow.Write(Text.Append(div, "0 "))
      If (code < 7) Or ((10 < code) And (code <> 13)) Then
        TextWindow.Write(Text.GetCharacter(code) + " ")
        TextWindow.Write("  ")
      If rem = 15 Then
    TextWindow.Write("07=BEL ")
    TextWindow.Write("08=BS ")
    TextWindow.Write("09=TAB ")
    TextWindow.Write("0A=LF ")

    Screen shot of a program ASCII CODE TABLE

    Nonki Takahashi

    Tuesday, June 11, 2013 10:24 AM
  • Thanks for posting this Nonki.

    You write really good code for others to learn from. And suggest some great challenges.

    Oh and so I don't forget a challenge for next month:

    Build a basic stopwatch program that allows to start/stop timer, reset timer and split lap timings. In text and graphic window.              

    Tuesday, June 11, 2013 10:41 AM
  • I rewrote my program as LZN025-0.

    Screen shot of a program TRON 0.2

    Nonki Takahashi

    Tuesday, June 11, 2013 12:16 PM
  • This is the first step for community challenge 1 (2): LNM164.

    I'm going to make a bitmap from the output of this program and use it as an image for a new roulette program.

    Screen shot of a program Roulette 0.1a

    Nonki Takahashi

    Tuesday, June 11, 2013 3:51 PM
  • My alpha solution to Physics Challenge:

    Duration and Altitude results match Wikipedia, speed is out by < 1%. Code and calcs need revising.

    All to scale, except satellite sizes of course. Time scale is to program run time.

    FB: Thanks litdev for this challenge, my 2nd physics chall. Good refresher for trig and algebra rules for me. And learnt some new programming methods. Enjoyed.

    Saturday, June 15, 2013 1:12 PM
  • Hi Timo

    Do you mean like coding straight into an exe, a bit like a macro. So write a program that allows the user to record macros.

    This could be possible. This could be the most original challenge suggestion I've seen yet.

    Saturday, June 15, 2013 8:57 PM
  • Yeah, that is what I mean.

    For example the user creates a new macro called "task1".

    Than he tells the program what to do if the user uses this macro.

    For example, it has to open the file which the user writes behind the macro.

    'User Input
    task1 C:\test.txt
    'Now the program opens the file and writes the contents into a textwindow.

    Mit freundlichen Grüßen Timo Greetings Timo

    Saturday, June 15, 2013 9:53 PM
  • This is my beta for community challenge 1 (2): LNM164-0.

    Screen shot of a program Roulette 0.2b

    Nonki Takahashi

    Tuesday, June 18, 2013 7:02 AM
  • @Timo

    Please give a few more details on this idea - thanks.

    Tuesday, June 18, 2013 8:46 PM
  • My solution to Maths Challenge: ZGF831

    Wednesday, June 19, 2013 7:08 PM
  • Re the above solution to math chall. Here's the button events - straight forward and clear, however....

    Sub ButtonClicked
      button = Controls.GetButtonCaption(Controls.LastClickedButton)
      If button = "Calculate" Then
      ElseIf button = "Exit" Then
      ElseIf button = "Back" Then

    I wonder what approaches would be clearer to setup each gui?

    1. gw, add shapes/controls, size & position fixed shapes/controls, then pick & choose which ones to hide/show, then set captions. OR
    2. add everything then hide everything. Then --> setGW, show, position, and then hide everything.

    I used 1. but i'm thinking 2. would be more definite, but require a lot more code...

    Wednesday, June 19, 2013 7:56 PM
  • Either way is good.

    Often a page will have separate subroutines to:

    1. Display/Hide content depending on some flag status
    2. Read content from user (e.g. textboxes)
    3. Update content (e.g. textbox results or graphics or whatever)

    Also it will have events that are triggered by button (or maybe something else).

    These will then call the subs above as required, so for example:

    • OK button will read all content (2) and close the current window.
    • A next button will read all content (2), change a flag for where we are, update display(1) and content (3)
    Wednesday, June 19, 2013 8:14 PM
  • This is my maths challenge: PCS454.

    Screen shot of a program Area of Regular Polygon

    Nonki Takahashi

    Thursday, June 20, 2013 2:48 AM
  • Curriculum Challenge 1.5

    1.) Show program PVM077 V 0.9. I wrote it for a GraphicsWinsow. I need the extention from LitDev to set the focus to the input-fields.

    Best Regards Martin

    • Edited by martmen Thursday, June 20, 2013 11:14 AM mini-calc
    Thursday, June 20, 2013 7:29 AM
  • Nice. Your graphics code is amazing.

    I found a really neat solution to this challenge on the web. It uses a mouse move animated graphic to show area. What do you think?

    Thursday, June 20, 2013 5:13 PM
  • @Timo

    Please give a few more details on this idea - thanks.

    Now I have two ways.

    1. The user enters some input into a textwindow. After the user agreed the program creates a new sb file and edit it. Then it uses SB to create a new .exe file.

    2. The user enters some commands like:

    file C:\test.txt open

    After the user agreed, the program analyze the input. It checks if there are specified keywords.

    In this example it would know the commands "file" and "open". So it opens the specified file in a textwindow or copy the text into a textbox.

    The user could create and save new macros. So if the user creates a macro called "A" it could do the following:

    file C:\test.txt delete
    I hope that my idea is now more clear. I will cerate an example if needed.

    Mit freundlichen Grüßen Timo Greetings Timo

    Friday, June 21, 2013 1:41 AM
  • I've written a plan (not quite pseudo code?) for Community Chal 2. Haven't done this before so any tips or fb would be welcome.

    I'll follow it to code the program and see how it goes.

    ' asks for an email address and password
    ' searches the file for the email address
    ' if the password is correct it displays the customer details
    ' it displays a suitable error message if the password is incorrect.
    'def  GUI 1
    'def  GUI 2, (hide/replace GUI 1 shapes & controls)
    '   def  correct content
    '   def error content
    'def Read content (txtBox, File)
    '   test Read content And flag error
    'GUI 1 ()
    'If  click = submit
    '   GUI 2
    '   Read, Test
    '      If  Flag = error
    '          show error content
    '       Else 
    '            show correct content
    'ElseIf  click = cancel
    '   Program.End
    'ElseIf  click  =  back
    '    If  Flag = error
    '          hide error content
    '       Else 
    '            hide correct content
    '    GUI 1
    '    hide/replace GUI 2 shapes & controls

    Friday, June 21, 2013 12:10 PM
  • It turned out this program didn't need a flag and the coding evolved a bit off plan. But I'm pretty sure it helped speed up the coding and prevented me from designing all over the place.

    Here's the solution: PDV657 , it's for Community Challenge 2. (to run uncomment the commented code...)

    Conclusion: the next program I attempt, i'm definitely going to resist the temptation of just coding without spending a bit of time working out a simple plan first. It's worth the effort.

    Friday, June 21, 2013 3:09 PM
  • These are my ideas for a future challenge:

    (1) Make a head (or tail) command which the UNIX system has.

    (2) Draw (or fill) a round-rectangle with parameters x, y, width, height and border-radius.

    Nonki Takahashi

    Tuesday, June 25, 2013 10:56 PM
  • Hi Nonki,

    Do you fancy doing July's challenges? - as usual a good mix of easy and harder.  If so post them sometime around the start of July and I will make them sticky.

    Wednesday, June 26, 2013 4:50 PM
  • Hey, nice job Nonki. I have an Idea for AI. You could just do a simple "while" command and in that process, have the computer check the AI's coordinates and see if they match the player's coordinates. If they don't, move the Ai toward the player.


    While aix<>plx and aiy<>ply

    If aix<plx Then

    aix=aix+10 (or whatever)


    If aiy<ply Then

    aiy=aiy+10 (or whatever)




    ardiezc_quazhulu was here.

    Sunday, June 30, 2013 4:30 PM
  • Hi Nonki, I think I see why you took a bit map of this.

    I haven't had a chance to finish but I started out doing was:

    --> draw the wheel 37 numbers, centred each number in a small rectangle around the origin

            e.g. shape.Move(num[i], X - (rectWid - fontSize)/2), ...) positioned evenly round the origin

    this all worked well, (although centrering the shape.addText(num) in the small rect wasn't a little out.

    When I tried to move all those shapes for the wheel spin, I think it was too much using this method.

    Can't post sample cause I deleted it. Maybe you could consider posting this challenge for July?

    Sunday, June 30, 2013 7:43 PM
  • Question -

    When I run this code, I don't get the same results. Mine appears to be unicode. I am running 64 byte VISTA. I am interested in using some of the "old DOS ASCII" codes. Any explanations? Suggestions?

    Thursday, November 28, 2013 3:04 PM
  • I get a different result as well.

    My system is Windows 7 32bit and I get this. My system is set to English. The difference maybe language settings

    Thursday, November 28, 2013 8:48 PM
  • It might be language.

    I know if you hold down the ALT key and type number 177 on the numeric pad , it will show an extended ASCII character ( ▒). Hopefully that will show up. Another example is ALT + 185 (╣). I have tried to emulate this in a Small Basic program without success. I think the ALT Key numeric code is 83 and is known as "System"? Any ideas? Would like it to be in the Graphics Window. 

    Friday, December 6, 2013 1:25 AM
  • Hi jswlhw

    If you could post this question as a new question in a new post, it would be heaps better, I reckon.

    Not everyone would get a chance to see your question here.

    It's a good question you ask and you'd probably get some helpful tips. That way you and many more could learn something about this topic.

    Friday, December 6, 2013 7:37 AM
  • I get a different result as well.

    My system is Windows 7 32bit and I get this. My system is set to English. The difference maybe language settings

    I got same result as you with Windows 8.1 English version.  I think this is because the code page is 850 for English version of Windows but 932 for Japanese version.  In command prompt, you can change the code page with chcp command.  But for Small Basic TextWindow, there is no way to change the code page, I think.

    Nonki Takahashi

    Friday, March 7, 2014 4:03 PM