none
Challenge of the Month - October 2013

    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.4

    1. Play 'Jingle Bells' with the Sound object (Sound object)
    2. Read and Save a set of musical notes to a file that can be played (Program and File objects).
    3. Save the notes in a format of your choice that can be modified outside Small Basic (Text object).  The program must be able to read this format and convert to variables that can be played using the Sound object.

    Maths Challenges

    1. (Easier) Write a program to calculate the mean, mode and median of a set of integers.  Try to make it as efficient as possible.
    2. (Harder) I have 12 steps, and I can go down them in steps of 1 or 2.  How many different ways could I go down the steps.  For example I could take 12 single steps (1-1-1-1-1-1-1-1-1-1-1-1) , 6 double steps (2-2-2-2-2-2), 1-2-2-1-2-1-1-2 or any other combination.

    Graphics Challenges

    1. Draw a pizza with lots of toppings - you could let the user select and add their choice of topping.
    2. Make a fancy graphical 'progress bar' that updates using the Timer.

    Text Challenges

    1. (Easier) Write a program to read the day, month and year from a user and write it out to the TextWindow, formatted in nice colours.
    2. (Harder) Write an email verification program.

    The email address must:

    • Start with a string of alphanumeric characters
    • followed by the @ symbol
    • another string of alphanumeric characters
    • followed by a “ . ”
    • then a string of alphanumeric characters.

    a@b.c and ab23@f45.d3 are both valid
    but @bc.d and 123.c@cvb are not valid

    Physics Challenge

    Write a program that realistically floats a cube on some water if the user enters the density of the cube.  Assume the water has density 1000 kg/m3.  If you want it harder, do it also for a sphere (Hint).

    Game Challenges

    1. (Easier) Write a 'estimate the time interval' game.  When the user presses a START button the program will display a time in seconds (5 to 15 seconds).  The user then must estimate when the time is up and press a STOP button.  If they are within 1 second they get a point.
    2. (Harder) Make a 'Puzzle Bobble' game.

    Community Suggestions (by Papa Lapup)

    Some tougher challenges for you to work on - perhaps contribute discussions on these challenges to help each other.

    For TextWIndow (TW)

    1. Show a simple graph for a simple function (with value table) in TW with eg. '*' or '.' Regular coord system can be 90° rotated. (perhaps more easy). Ymin and Ymax should fit in width of TW then (within choosable limits Xmin and Xmax). eg TWGraph.exe "f(x)" Xmin Xmax

    2. Write a simple Month Calendar in TW (Sample Img in vbs but should also be possible in SB)

    TWCalendar

    For GraphicsWindow (GW)

    1. Once saw a fascinating and surprising animation of an 'useless mechanical chain reaction' in a kind of alchemy laboratory or witch kitchen background, which should be possible in SB (for advanced users) I think with simpler objects (domino, seesaw, coil spring, inclined plane, pendulum, free fall, etc). Why do something the simple way if it's also possible complicated and tedious?

    Rube Goldberg machine (Rube Goldberg machine or Rube Goldberg)

    2. Write a flat-directory viewer for selectable folder (e.g. Subs in IE-Cache in LocAppData\Microsoft\Windows\Temporary Internet Files\Content.IE5) and show only 'SubDirName\File.ext' in MultiLineTextBox line by line. Unfortunately no Ext allowed, but can later be replaced with eg. LDListBox to select file and perform action on it.

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


    Thursday, September 26, 2013 5:32 PM
    Moderator

All replies

  • I have already written a calendar program.  I uploaded it for community suggestion TW-2: MTW971.


    Nonki Takahashi


    Friday, September 27, 2013 8:05 AM
    Moderator
  • Hi Nonki,

    You already done it in 2010. I'm just trying to follow your code to highlight the current day, which i could'nt in vbs. If you are interested, here is the sample Calender.VBS (!!!) in engl. VRZ516-0

    Please dont try to start in SB-IDE. Its in .VBS !! To run in Console mode with cscript host like:

     cscript.exe calender.vbs



    • Edited by Pappa LapubEditor Friday, September 27, 2013 6:41 PM host mentioned. But enough, here's SB
    Friday, September 27, 2013 5:42 PM
    Answerer
  • Community Suggestions   

    Write a simple Month Calendar in TW    QSD290-1

    * Year must be   Y>=1583.  (Gregorian calendar  ....   Start date = 1582/10/15  Friday)
    • Edited by NaochanONEditor Saturday, September 28, 2013 11:40 AM add comment
    Saturday, September 28, 2013 11:38 AM
    Answerer
  • Hello everyone,

    Here is my solution to the progress bar challenge:

    You can make the progression speed faster or slower, if needed.

    Timer.Tick = OnTimerTick
    Timer.Interval=500
    
    'Size and location of the progress bar:
    width = 100
    height = 50
    x=0
    y=0
    
    'Colors used:
    NormalColor = "White"
    ProgressColor = "Blue"
    GraphicsWindow.BrushColor = NormalColor
    
    'The rectangle that shows the progress bar:
    MyProgressBarRect = Shapes.AddRectangle(width,height)
    Shapes.Move(MyProgressBarRect,x,y)
    counter = 0 'counter
    Steps=2 'progression speed
    
    Sub OnTimerTick
      
      If counter < width then
      GraphicsWindow.BrushColor = ProgressColor
      shapes.Move(Shapes.AddRectangle((width/10)+counter,height),x,y)
      counter=counter+Steps
     EndIf 
      
    EndSub


    Sunday, September 29, 2013 6:46 PM
  • Pappa Lapub,

    I could run your VB script with changing from 'D&"."&Mo&"."&Yr' to 'Yr&"/"&Mo&"/"&D' in my Japanese Windows system.

    I also ported your VB script to Small Basic program as MBL596.

    Please save this program as "Cal.sb".  And from command prompt, you can give arguments to this program.

    By the way, something is wrong in VB script, eg. 1 1900. 


    Nonki Takahashi



    Monday, September 30, 2013 5:10 AM
    Moderator
  • Graphics Challenges   

      Make a fancy graphical 'progress bar' that updates using the Timer.  
      QRH345

    Monday, September 30, 2013 6:33 AM
    Answerer
  • Nonki,

    for me "1 1900" worked without changes (it was indeed a Mo) . Suppose 'Local date&time settings'.

    That was the time i dropped out (sb code). This man is a genius and i've to raise my hat.

    Monday, September 30, 2013 12:02 PM
    Answerer
  • This is my maths challenge 2: ZZL953.

    Screen shot of a maths program Step 12

    But this program doesn't have any calculation about this challenge...


    Nonki Takahashi

    Monday, September 30, 2013 12:42 PM
    Moderator
  • This is my graphics challenge 2: MBB966.

    Screen shot of a program Progress Bar 0.4


    Nonki Takahashi

    Monday, September 30, 2013 3:18 PM
    Moderator
  • Leap year detection code  is something wrong.  2000 is leap year!! 

    Tuesday, October 01, 2013 3:18 AM
    Answerer
  • NaochanON, thank you for your bug report.  I fixed it as MBL596-0.

    Nonki Takahashi


    Tuesday, October 01, 2013 10:21 AM
    Moderator
  • For GraphicsWindow (GW) 

    2. Write a flat-directory viewer for selectable folder BJD645  

    * select drive/subdirectory and click it.
    • Edited by NaochanONEditor Saturday, October 12, 2013 10:30 AM add comment
    Saturday, October 12, 2013 10:25 AM
    Answerer
  • For GraphicsWindow (GW)  2. Write a flat-directory viewer for selectable folder LNV488 (noirEd)

    PS: On eg. Win7 you can have a 'flattened folder view' when entering * or *.* in the (upper right) explorer searchbox.

    Monday, October 14, 2013 5:47 PM
    Answerer
  • I have a suggestion.

    It is super easy, probably great for brand-new programmers.

    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. 

    Wednesday, October 23, 2013 3:40 AM
  • From Wikipedia, a pseudo-code for "leap year":

    Since 2000 is divisible by 400 it's always a leap year; even though it's also divisible by 100!   @_@

    if year is divisible by 400 then
       is_leap_year
    else if year is divisible by 100 then
       not_leap_year
    else if year is divisible by 4 then
       is_leap_year
    else
       not_leap_year

    Click on "Propose As Answer" if some post solves your problem or "Vote As Helpful" if some post has been useful to you! (^_^)

    Wednesday, October 23, 2013 4:35 AM
    Answerer
  • Text Challenges

    Write an email verification program.  PNM585-2

    Thursday, October 24, 2013 2:17 AM
    Answerer
  • I have ideas for future challenges.

    (1) Write truth tables about Not, And, Or, and Xor.

    (2) Draw a picture of the Olympic flag.

    (3) Simulate a kaleidoscope.


    Nonki Takahashi


    Thursday, October 24, 2013 4:59 AM
    Moderator
  • Maths Challenges
    (Harder) I have 12 steps, and I can go down them in steps of 1 or 2.  How many different ways could I go down the steps.  For example I could take 12 single steps (1-1-1-1-1-1-1-1-1-1-1-1) , 6 double steps (2-2-2-2-2-2), 1-2-2-1-2-1-1-2 or any other combination.

    My Answer....  233  patterns.    GDS044

    my logic is as below.



    • Edited by NaochanONEditor Wednesday, October 30, 2013 12:27 AM add comment and photo
    Tuesday, October 29, 2013 6:21 AM
    Answerer
  • Oh!  In one or two steps!  My answer ZZL953 includes from one to twelve steps...  I should correct my program.

    Nonki Takahashi

    Tuesday, October 29, 2013 1:47 PM
    Moderator
  • This is my corrected version of maths challenge 2: ZZL953-0.

    Screen shot of a maths program


    Nonki Takahashi

    Wednesday, October 30, 2013 12:43 AM
    Moderator
  • Maths Challenges 

    12 steps problem.   Graphic version    TWF419  



    • Edited by NaochanONEditor Wednesday, October 30, 2013 12:32 PM change code and photo
    Wednesday, October 30, 2013 12:27 PM
    Answerer
  • About Community Suggestion for TextWindow (TW) 1: Show a simple graph...

    It seems, that this challenge is unsolveable in SB without extension. Except anyone would know a solution to change a textstring term like in

    FuncX = "4*0.17-3"

    to a numeric value (FuncX = -2.32 in this case)!? Tried so much different ways but always failed without an Eval function.

    Wednesday, October 30, 2013 9:21 PM
    Answerer
  • a solution to change a textstring term like in   FuncX = "4*0.17-3" to a numeric value (FuncX = -2.32 in this case)!?

      I made a program to calculate text type formula.  Try   PCK089  


    Thursday, October 31, 2013 2:28 PM
    Answerer
  • Hi NaochanON,

    thanks a lot. I had not thought it possible and looks quite impressive and complicated. I'm just going through your code in order to understand the process. It seems, like often i've same old problem with german localisation settings again (. vs ,).

    Running your original sample:

    with 1st Term from PCK089 :
    Calc = 123.55/7654-87.12-1082/762*12.12 =
    0,016141886595244316697151816-87.12-17,209763779527559055118110237 = -87,120,016141886595244316697151816

     with 2nd Term from PCK089 :
    Calc = -4*0.17-3*8+6*3/2*9+9-15/5+11.55 =
    -0,68-24+81+9-3+11.55 = 74,55

    2nd term on CmdLine:
    ----------------------------

    1.)

    math.exe 4*0.17-3*8+6*3/2*9+9-15/5+11.55
    73.87

    2.)

    '--- Code start---

    Option Explicit
    Dim Func, Ans
    Func = WScript.Arguments(0)
    Ans = Eval(Func)
    WScript.Echo Ans

    '--- Code end ---

    .. saved as Eval.vbs and ran eg.:

    cscript //NoLogo Eval.vbs -4*0.17-3*8+6*3/2*9+9-15/5+11.55
    73,87

    I guess you had the CORRECT output as mentioned in PCK089    ('    answer = 73.87) !?

    Edit: Oh, sorry. Its all clear. Just looked at the console image right now...

    Thursday, October 31, 2013 9:00 PM
    Answerer
  • Hi NaochanON,

    thanks a lot. I had not thought it possible and looks quite impressive and complicated. I'm just going through your code in order to understand the process.

    My method is as follows.
    for example...
    cal="-4*0.17 - 3*8 +6*3/2*9 + 9 -15/5+ 11.55"

    1st step:  make letters to a value and make an array (Val[])
               Val="1=4; 2=0.17; 3=3; 4=8; 5=6; 6=3; ..............; 12=11.55"
               make an  array for Functions (*/+-)   (Function[])
               Function="1=-; 2=* ;3=-; ......... 11=+"
    2nd step:  calculate  * or / .  results are put like below
               res=val[1]*val[2]  →  Val[1]="",  Val[2]=res  (in this case =0.68)
               in this case "*"  → Function[2]
               erase function "*"  ,   Function[2]=""

    3rd step:  make new formula ,   NewCal has Functions "+" or "-"

               NewCal="-0.68-24+81+9-3+11.55"

    4th step:  make letters to a value and make an array (NewVal[])
               make an  array for Functions (+-)   (NewFunction[])
               calculate  + or - .
    Last step  show result

    * This is graphic version .  LCX215



    • Edited by NaochanONEditor Friday, November 01, 2013 4:27 AM added graphic version
    Friday, November 01, 2013 12:19 AM
    Answerer