# Challenge of the Month - September 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 Challenge 2.3

1. Draw a face using ellipses.
2. Animate the face to move on the screen.
3. Make a collage picture using all of the shapes (line, rectangle, ellipse, image, text and triangle) added at random positions, with random opacity, color, rotation and zoom.  Consider using the Timer to create the shapes.
4. Use the pen width and colour to create a gray car wheel with a black tire.
5. Make an animated scrolling text program.  If you want a harder challenge, move the text in a curve.

Basic Challenges

1. Write a program to calculate triangular numbers (1,3,6,10...)
2. Write a program to read data in from the GraphicsWindow.  You should have a TextBox and Button to get the entry.  Save the entered data in an array which you can save to a file or output to a multi-line textbox.
3. Write a program to read some text and replace all capital letters with a * character.
4. Write a program to convert currencies, graphical or text based.  Perhaps use a file to store current exchange rates.

Physics Challenge

Make a pendulum that swings as accurately as possible.

Game Challenge

Write a Atari missile command game.

Stack Challenge

Write a simple TextWindow based calculator using the stack using the ideas below.

Add (push) input to a stack.

If the stack has 3 entries then

1. Get (pop) the 3 entries.
2. Assume the 1st and 3rd are numbers and the 2nd is an operator (+ - * /).
3. Do the sum and write some output.
4. Put the result on the stack (push) and wait for more entry.
You could add some error checking for step 2.

Community Suggestion 1 (8 Bit Pony & Jibba Jabba)

Create a basic webpage with the shapes commands.

1.     Create a form that allows users to post feedback on the website.
2.     Create a log of hits on the site and log what they clicked on, then generate a summary of activity
3.     Create an online database of member details, a mini address book. (arrays practice)
4.     Create an online mini diary/journal that signed up visitors can use (secure w/password)
5.     Write the diary entries to file and maybe create a lookup form

Community Suggestion 2 (By Nonki)

1. Make a subroutine to write text with format such as "#,##0.0".  This subroutine has two parameters a format (i.e. "##" ) and a number (i.e. 9).  And it write a formatted number (i.e. " 9") to TextWindow screen.
2. Make a GUI for a cue of billiard.  You may use mouse click, mouse drag or something else.

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

Sunday, September 01, 2013 10:23 AM

### All replies

• Thanks litdev. Another month of amazing challenges.
Sunday, September 01, 2013 12:58 PM
• My solution to CC 2.3 (1. & 2.)  http://smallbasic.com/program/?WHQ660

My problem with this is can I / how do I do it without getting the screen flicker in the top left of screen?    This issue only occurs when running locally.

Monday, September 02, 2013 10:31 PM
• Nice graphics.

The flicker is caused by adding new shapes - they are added in the corner before being moved and can show as flicker.

Best approach is to create all the shapes you will need at the start, then Move, Show and Hide then as required.  Since the eyes and pupils depend on dy and dh, perhaps create a circle and the use Zoom to create the correct size ellipses based on dy and dh.

Tuesday, September 03, 2013 5:53 PM
• Cool alien Jibba Jabba.

I can't wait to play someone's missile command!

• Edited by Wednesday, September 04, 2013 5:04 AM
Wednesday, September 04, 2013 5:02 AM
• Thanks Litdev and bigdaddyo for the tip and fb.

I fixed the screen flicker and added a timer for blinking and a window size toggle button.

Runs in the browser.   http://smallbasic.com/program/?JRP437

Thursday, September 05, 2013 12:08 PM
• My solution to Stack Challenge:  XJT537

Don't use the Stack much. I reckon it could be good to clone the Memory Buttons on a calculator.

Sunday, September 08, 2013 6:14 AM
• Atari missile command game   SKL606

Download sounds ( missile ,alarm , bomb explosion ) from here . And save them in your "Program.directory".

Thursday, September 12, 2013 1:47 PM
• Another excellent game from NaochanON, with cool sound effects too.
Thursday, September 12, 2013 7:11 PM
• Great Game NaochanON. Great sound effects. I played it on my laptop using touchpad. No problem. Very playable. Good gun turret too. Nice.
Thursday, September 12, 2013 7:42 PM
• Physics Challenge

Make a pendulum that swings as accurately as possible  FWR293-1   (Locally runs well)

By mouse ,   click yellow circle, move it, release it.   * Acceleration arrow image is added.

• Edited by Saturday, September 14, 2013 9:12 AM ProgramID changed
Friday, September 13, 2013 1:19 PM
• My "not so good solution" to the physics challenge.

First sample has a bounce at the equilibrium point WBV826

2nd sample has no acceleration and the rod & bob don't line up XVR144

In the first sample I used the simplest formula for acceleration because my equation solving skills aren't very strong. I'll have to work through NaochanON's sample and use the period I think.

Friday, September 13, 2013 7:10 PM
• Community Suggestion 2 (By Nonki)  september 2013
Make a subroutine to write text with format such as "#,##0.0".

Some time ago I started to make a formatting subroutine using the format of the printf of the C-language.
I had made part of the program for numerical format %....d, but it was not ready yet.
For this challenge I tried to add the stringformat %...s to it, but the determination of the difference
between the "s" and the "d" cost a lot of If .... Then's.
As there is not much difference between the realisation of the two, I merged them into one %...# forrmat.
The difference is a decimal dot in numerical formats and no dot in string formats.
The subroutine is more than a hondred lines long and is published as ZXQ262.
All variable names in the subroutine start with a _ (underscore) so they will not interfere with the calling
program (if all names there start with a letter). All interaction is through the array FO[].

explanation of the format:
'''  Give the formatstring in FO[0] , all parameters in FO[1].....  ;  output is put in FO[99]
'  stringformat  %[.-][L]N#
'                        ^^     one optional fill character [NOT 123456789L# ] { default = space }
'                            ^^        optional left adjustment ["L"]
'                                 ^^        N= fieldlength (string is truncated)
'  numberformat  %[.\$0]N.M#    first=fillchar    N=fieldlength  M=fractionchars
'                           ^^^               optional fill character {default = space}
'                                 ^^^      N=fieldlength  M(optional) number of decimals
'   all other characters in the formatstring are included in the output
'   to output a % : put 2 % characters in string:    %%

The following test program shows a typical use  and the output of the program.

```'Format  130917  WhTurner

FO[0]="File %04# : %-L15# | %_15.4#%%  #     end"      ''format definition
FO=FO+"2=abcdefghj;3=123.765432"       ''testvalues
''     rulerline:
TextWindow.WriteLine("123456789a123456789b123456789c123456789d123456789e123456789f")
For i=1 to 12
FO[1]=i
form()    '' output in FO(99)
TextWindow.WriteLine(FO[99])
'' FILE=Program.Directory+"\form.out"
'' File.AppendContents(FILE,FO[99])
FO[3]=500+95*i +Math.GetRandomNumber(100)/100
endfor
```

```File 0001 : abcdefghj------ | _______123.7654%  #     end
File 0002 : abcdefghj------ | _______595.1900%  #     end
File 0003 : abcdefghj------ | _______690.4000%  #     end
File 0004 : abcdefghj------ | _______785.2200%  #     end
File 0005 : abcdefghj------ | _______880.7000%  #     end
File 0006 : abcdefghj------ | _______975.6800%  #     end
File 0007 : abcdefghj------ | ______1070.2600%  #     end
File 0008 : abcdefghj------ | ______1165.3100%  #     end
File 0009 : abcdefghj------ | ______1260.9900%  #     end
File 0010 : abcdefghj------ | ______1355.5900%  #     end
File 0011 : abcdefghj------ | ______1450.9000%  #     end
File 0012 : abcdefghj------ | ______1545.1600%  #     end
```

Jan [ WhTurner ] The Netherlands

Tuesday, September 17, 2013 12:05 PM
• Atari missile command game   SKL606

Download sounds ( missile ,alarm , bomb explosion ) from here . And save them in your "Program.directory".

Great job!

Ed Price, SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

Friday, September 20, 2013 11:29 PM
• Physics Challenge

Make a pendulum that swings as accurately as possible  FWR293-1   (Locally runs well)

By mouse ,   click yellow circle, move it, release it.   * Acceleration arrow image is added.

Great job!

Ed Price, SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

Friday, September 20, 2013 11:37 PM
• Any suggestions for next month or even any volunteers to write them to get a bit of variety?

They will be published a bit early for October since I will be away for a couple weeks.

Tuesday, September 24, 2013 7:34 PM
• This is my first step for Game Challenge: VHH620.

Nonki Takahashi

Wednesday, September 25, 2013 9:22 AM
• This is my sample of Community Suggestion 2.1: DWM520.

Nonki Takahashi

Wednesday, September 25, 2013 12:34 PM
• This is my sample of Community Suggestion 2.2: JRH717.

Nonki Takahashi

Thursday, September 26, 2013 10:47 AM
• OK, would have some suggestions that seem makeable in SB:

For 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 (SampleImg in vbs but should also be possible in SB)

For 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-directoy viewer for selectable folder (eg. 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.

Thursday, September 26, 2013 7:58 PM
• This is my second step but still alpha version of game challenge: VHH620-0.

Nonki Takahashi

Friday, September 27, 2013 1:25 AM