# Challenge of the Month - February 2014

• ### 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 3.2

1. Write a program to read in a user's name, then create an array of the letters using Shapes.AddText for each letter.  Then animate the Text shapes in the array to reveal the name on the GraphicsWindow.
2. Write a program using arrays to store 20 balls and move them all in some way on the GraphicsWindow.
3. Write a program to shuffle a pack of cards and add the shuffled cards to a stack so they can be 'popped' or dealt.

Graphics Challenge

1. Draw a dial (perhaps a speedometer or some other dial).  It should be able to animate as a value is changed.
2. Write a short turtle program (10 lines or less) to draw interesting patterns.  Here is an example to get you started - try different mathematical combinations.

```Turtle.Speed = 10
For i = 1 To 600
Turtle.Move(10)
Turtle.Turn(i*11)
EndFor```

Text Challenges

1. Write a program to write and read Morse Code (dots and dashes) or even use sound in some way.

Maths Challenges

1. Write a program to solve quadratic equations, like x2 - 8x +15 = 0 has solutions x = 3 and x = 5.
2. Extend it if possible to solve cubic and quartic equations.

Game Challenge

1. Write a simple Snake game.

Community Suggestions (by Zock77)

1. Writea program in which the user will draw something with his mouse. then, when he inputs that he is done, the program will replay in real time what the user drew.

Community Suggestions (by Nonki)

1. Make a tr (UNIX-like translate) command.
2. Draw a Bezier or spline curve.
3. Measure pixel width of a text in GraphicsWindow.

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

Saturday, February 1, 2014 2:41 PM

### All replies

• Here is my first attempt to Community Suggestion 1:

```''tr command 140202 WhTurner
InString="THIS is a TEST string for the tr command"
OutString=""
options="d"  ''d = delete every char in Str1 from InString, make empty for no option.
Str1=" "
Str1="QWERTYUIOPASDFGHJKLZXCVBNM"
Str2="qwertyuiopasdfghjklzxcvbnm"  'translate every UPPERCASE to lowercase
Str2="ABCDEFGHIJKLMNOPQRSTUVWXYZ"  'translate uppercase to other characters

For i=1 To Text.GetLength(Str1)
InChar[i]=Text.GetSubText(Str1,i,1)
OutChar[i]=Text.GetSubText(Str2,i,1)
EndFor

For i=1 To Text.GetLength(InString)   ''every char in InString
Char=Text.GetSubText(InString,i,1)
Char2=Char
For j=1 To Array.GetItemCount(InChar)
If Char=InChar[j] Then
If Text.IsSubText(options,"d") then
Char2=""
Else
Char2=OutChar[j]
endif
EndIf
EndFor
OutString=Text.Append(OutString,Char2)
EndFor
TextWindow.WriteLine(InString)
TextWindow.WriteLine(OutString)
```

It does the standard tr command, and the possibility for the option s (to delete the characters in Str1 from InString).

There are some different Str1 and Str2 values in the program, which I used for testing.

Jan [ WhTurner ] The Netherlands

Sunday, February 2, 2014 3:44 PM
• My solution for curric challenge 3.2 (1)  KFC537.  "with Kentucky Fried Chicken ID"

I'm just starting to experiment a bit with a Program Structure that will be an Applet with a game loop built in that only runs updates when an event takes place, otherwise the program just waits without looping.

```'KFC537
'Just trying Screen Updates outside the UI thread, since SB has no async methods or forms.

'NOT SURE HERE, but
'Seems Not too tricky for SB since there's no forms with properties that have to be set in the UI thread.
'ref: http://msdn.microsoft.com/en-us/magazine/cc188732.aspx

'PURPOSE: is to build an Applet that can include a game mode without using an infinite Main loop
'   so the whole program waits for an event to happen then Resumes, processes Event Flags then
'   pauses and waits for next event. Not a resource greedy structure when nothing is happening.
'   WIP will put future programs into an UpdateProgram()  UpdateScreen() structure WITHOUT  an infinite loop.
'Hopefully.
'******************************************************************************************************

Initialise()
Timer.Tick = UpdateProgram

'=====================================================
'Update Program Only when an Event Happens (simple example) w/o game mode
'=====================================================
Sub UpdateProgram
Timer.Pause()

If keyUp Then
name = Controls.GetTextBoxText(nameBox)

If name <> nameBoxMessage And GraphicsWindow.LastKey = "Return" Then
AnimateName()
EndIf
EndIf

updated = "True"  '{marshaling the Event handlers}?
EndSub```

• Edited by Monday, February 3, 2014 6:56 PM
Monday, February 3, 2014 6:26 PM
• Turtle Challenge:

FFB727

It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

Tuesday, February 4, 2014 11:14 PM
• Zock77, interesting shape.

Nonki Takahashi

Saturday, February 8, 2014 3:53 AM
• WhTurner33, good try for tr command.

Nonki Takahashi

Saturday, February 8, 2014 3:25 PM
• @Zock77
Nice crop circle made of 10 Clothoids (Euler spirals), could be a nice picture frame

Played around a bit in a silent hour for Graphics Challenge 2:

Turtle PolySpiral   LNZ598  18 Lines , shortened as (too) much as could, but 3 figures, not my idea

TurtlePattern Brillie   JMC583   10 Lines   OK, but not my idea

Circle Series / Flower   QCL151  15 Lines

PS: Turtle.Hide sends Turtle (Image Shape) to Oblivion and it will never be seen in the same program again.  Turtle.Show wont bring it back.
Although not the same; to hide Turtle Shape and then show it up again Shapes.HideShape("_turtle") and Shapes.ShowShape("_turtle") can be used.

Wednesday, February 12, 2014 1:11 AM
• Thanks!!

I have another Idea for future challenges

what if each week we pick an extension to base a challenge off of (maybe go down the list?) Just a thought... :D

It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

Thursday, February 13, 2014 7:23 PM
• I think this is a good suggestion Zock. Progressive.

• Edited by Friday, February 14, 2014 10:36 AM shorten
Friday, February 14, 2014 5:48 AM
• Here is a variation on graphics challenge 2.  Changing the number used in the turtle code makes different pictures.  The following code makes a  pictogram for 0-9.  Then the user can make a pictogram to store a numeric code.

program : TLQ846

Turtle.Speed = 10
tutrix = Turtle.X
tutriy = Turtle.Y
For x = 0 To 9
GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()
Turtle.X = tutrix+(x*100)-300
Turtle.Y = tutriy - 100
Turtle.Angle=0
GraphicsWindow.FontSize = 20
GraphicsWindow.DrawText(Turtle.x,Turtle.y,x)
For i = 1 To 300 Step (x+1)
Turtle.Move(10)
Turtle.Turn((x+1)*i)
EndFor
EndFor

code = "1=3;2=5;3=6;4=8;5=2;6=2;7=5;8=0"
For x = 1 To Array.GetItemCount(code)
GraphicsWindow.PenColor = GraphicsWindow.GetRandomColor()
Turtle.X = tutrix+(x*100)-300
Turtle.Y = tutriy + 100
Turtle.Angle=0
GraphicsWindow.FontSize = 20
'GraphicsWindow.DrawText(Turtle.x,Turtle.y,code[x])
For i = 1 To 300 Step (code[x]+1)
Turtle.Move(10)
Turtle.Turn((code[x]+1)*i)
EndFor
EndFor

Sunday, February 16, 2014 1:03 PM
• This is my sample for community suggestions by Nonki 3: KTK906-0

Nonki Takahashi

• Edited by Monday, February 17, 2014 1:38 PM minor update for Silverlight
Monday, February 17, 2014 10:35 AM
• This is a first step for community suggestions by Nonki 1: XMG163

This program just parses it's arguments only.

```Option? a-z A-Z <in.txt >out.txt
1=a-z;2=A-Z;stdin=in.txt;stdout=out.txt;
Press any key to continue...
```

Nonki Takahashi

Tuesday, February 18, 2014 2:29 AM
• Curriculum Challenge 3.2(3) - use stack to shuffle and deal cards - Import KSS253.
Tuesday, February 18, 2014 8:56 PM
• Only 73 steps... Wow!

Nonki Takahashi

Wednesday, February 19, 2014 11:24 AM
• I finished to make community suggestion by Nonki 1: XMG163-1.

```Option? A-Z ZA-Y
IBM 9000
HAL 9000

Press any key to continue...
```

Usage:
Option? string1 string2 [<stdin] [>stdout]

Nonki Takahashi

• Edited by Wednesday, February 19, 2014 1:14 PM minor changed for remote
Wednesday, February 19, 2014 12:50 PM
• This is my challenge for Curriculum Challenges 3.2 3. : VHT007-0.

Nonki Takahashi

Wednesday, February 19, 2014 4:56 PM
• Hi Nonki,

Little Off-topic, but found a previous suggestion from you about Simulation of Brownian motion (Turtle)

Unfortunately there's no ID, also on your HP(es) i could only find a screenshot. Can you show an ID, i would be interested in how you made that? Thx

Wednesday, February 19, 2014 7:04 PM
• The real time drawing challenge beta: NMW662

Click to draw, right click to render.

It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

Wednesday, February 19, 2014 8:28 PM
• Hi Nonki,

Little Off-topic, but found a previous suggestion from you about Simulation of Brownian motion (Turtle)

Unfortunately there's no ID, also on your HP(es) i could only find a screenshot. Can you show an ID, i would be interested in how you made that? Thx

Pappa Lapub, OK. Now I'm out (from iPad 2). I"ll inform you when I come back.

Nonki Takahashi

Thursday, February 20, 2014 12:59 AM
• Pappa Lapub, the program ID of the program Brownian Motion Simulation with Turtle is RFV485.

Nonki Takahashi

Thursday, February 20, 2014 7:24 AM
• This is my sample for community sugesstion by Nonki 2: WWV142.

Click 10 sample points by mouse.  And 1 more click clears screen.

Nonki Takahashi

Thursday, February 20, 2014 4:29 PM
• Ah, Thanks Nonki for Brown Simulation. I think i seen it too complicated and technical and was irritated by the physics definitions (Wiener process etc.). Added TurtleHide() before the Turtle Loop, which should fasten the drawing a bit and does'nt affect Turtle.Angle and -.Move.

Btw. I Like your programs on nonkit.blogspot ,nonkit.com/en and nobukit.cocolog-nifty.com not only for advanced technics, but also for aesthetic touch. Unfortunately my Go skills are very limited but love Stomu Yamashta's Go sessions, if that does count too. :-)

Thx again!

Thursday, February 20, 2014 6:04 PM

Nonki Takahashi

Friday, February 21, 2014 8:43 AM
• This is my first step for game challenge: ZKG464-0.

Nonki Takahashi

Friday, February 21, 2014 11:55 AM
• I completed my Snake Game: ZKG464-1.

Nonki Takahashi

Saturday, February 22, 2014 2:41 AM
• Here's my crack at the game challenge: JMB267  It's complete enough to be playable, just needs a couple of minor tweaks which I'm still working on.

Eat as many apples as possible while avoiding hitting the snakes own tail or going off the screen.  The game gradually increases in speed to increase the difficulty.

Saturday, February 22, 2014 11:18 AM
• OzJerry:

Gee that's good code. Thanks for posting.

Nice apple. Haven't seen this before: GraphicsWindow.PenColor = "Transparent"

• Edited by Saturday, February 22, 2014 12:17 PM
Saturday, February 22, 2014 12:13 PM
• Thanks for the feedback Jibba Jabba.  It turned out to be not as simple a task as I thought it would be, so it kinda grew much longer than I had anticipated.

I can't remember where I learned about the transparent thing, but it would have been on here somewhere...either a forum post, someone else's code or an article.  Seems to work for any command that takes a colour as input.

I was quite proud of the apple too:).  Took me a while to get the right size and position of the shapes and make them fit into a 'cell' on the game board for easy positioning and erasing.

Sunday, February 23, 2014 1:59 AM
• Maths Challenges   graphical version   XHD450-0

* added Y=0 check code  // etc

Sunday, February 23, 2014 5:53 AM
• These are my ideas for a future challenge.

1. Make a hexadecimal dump program for UTF-8 encoded text file.
2. Make a subroutine to draw polygon with given vertices.
3. Make a subroutine to fill polygon with given vertices.

Nonki Takahashi

Sunday, February 23, 2014 6:08 AM
• I think this is a good suggestion Zock. Progressive.

Thank you!

I'm not too sure it would work though

It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

Monday, February 24, 2014 5:19 PM