Small Basic Challenges - October 2018
These are the October 2018 challenges from Roshan Kumar Priya.
- We're also continuing the September 2018 challenges here: https://social.msdn.microsoft.com/Forums/en-US/0059173a-594e-4da4-afa6-e9c6ac9241fa/challenge-of-the-month-september-2018?forum=smallbasic
These October 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 Small Basic. 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 forum thread.
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.
Hard Challenges
Pascal Triangle
Write a program which will draw a Pascal triangle in GraphicsWindow.
Random Number Generator
Create a program which accepts two numbers then prints out a random number somewhere between those two numbers. Make sure you write your own code to generate the random number (ie. don't use the built in Math.GetRandomNumber() function).
You can be quite creative in how you achieve this but a common approach is to make use of the current time as part of your method.
Correct HTML
Create a program which will read in a file containing HTML and identify lines with incorrectly nested tags. This is an example of correctly nested tags:
<H1>This is my <span>heading</span></H1> <-- This is correct
And this is an example of incorrectly nested tags:
<H1>This is my <span>heading</H1></span> <-- This is wrong
Tic Tac Toe
Build a game of Tic Tac Toe. I would suggest you start off building a two player version then if you want a little extra challenge see if you can build a version where you get to challenge the computer.
Small Challenges
1. Write a program to check whether a number is odd or even.
2. Write a program that can convert numbers into triangles (in TextWindow).
For example, If you give input as 5,
The output should be
*
**
***
****
*****
Similarly, If you give the input as 3,
The output should be
*
**
***
3. Write a program to print prime numbers from 1 to 1000.
4. Write a simple program that can draw shapes on the Small Basic GraphicsWindow like the Paint application on Windows (Shapes editor).
This is a sample Shapes Editor.
GraphicsWindow``.``Show``(``)
rectangle ``= ``Controls``.``AddButton``(``"Add Rectangle"``,``0``,``0``)
ellipse ``= ``Controls``.``AddButton``(``"Add Ellipse"``,``0``,``50``)
Controls``.``ButtonClicked ``= ``OnBC
Sub ``OnBC
``If ``Controls``.``LastClickedButton ``= ``rectangle ``Then
``func ``= ``"rect"
``active ``= ``"T"
``If ``func ``= ``"rect" ``Then
``GraphicsWindow``.``MouseDown ``= ``OnMDrect
``EndIf
``Else
``func ``= ``"ell"
``active ``= ``"T"
``If ``func ``= ``"ell" ``Then
``GraphicsWindow``.``MouseDown ``= ``OnMDell
``EndIf
``EndIf
EndSub
Sub ``OnMDell
``ellx ``= ``GraphicsWindow``.``MouseX
``elly ``= ``GraphicsWindow``.``MouseY
``ell ``= ``Shapes``.``AddEllipse``(``0``,``0``)
``Shapes``.``Move``(``ell``,``ellx``,``elly``)
``If ``func ``= ``"ell" ``Then
``GraphicsWindow``.``MouseMove ``= ``OnMMell
``GraphicsWindow``.``MouseDown ``= ``OnMDell2
``EndIf
EndSub
Sub ``OnMMell
``If ``func ``= ``"ell" ``Then
``If ``active ``= ``"T" ``Then
``width ``= ``Math``.``Abs``(``ellx``-``GraphicsWindow``.``MouseX``)
``height ``= ``Math``.``Abs``(``elly``-``GraphicsWindow``.``MouseY``)
``Controls``.``SetSize``(``ell``,``width``,``height``)
``EndIf
``EndIf
EndSub
Sub ``OnMDell2
``func ``= ``""
``active ``= ``""
``height ``= ``0
``width ``= ``0
``rect ``= ``""
``ell ``= ``""
EndSub
Sub ``OnMDrect
``rectx ``= ``GraphicsWindow``.``MouseX
``recty ``= ``GraphicsWindow``.``MouseY
``rect ``= ``Shapes``.``AddRectangle``(``0``,``0``)
``Shapes``.``Move``(``rect``,``rectx``,``recty``)
``If ``func ``= ``"rect" ``Then
``GraphicsWindow``.``MouseMove ``= ``OnMMrect
``GraphicsWindow``.``MouseDown ``= ``OnMDrect2
``EndIf
EndSub
Sub ``OnMMrect
``If ``func ``= ``"rect" ``Then
``If ``active ``= ``"T" ``Then
``width ``= ``Math``.``Abs``(``rectx``-``GraphicsWindow``.``MouseX``)
``height ``= ``Math``.``Abs``(``recty``-``GraphicsWindow``.``MouseY``)
``Controls``.``SetSize``(``rect``,``width``,``height``)
``EndIf
``EndIf
EndSub
Sub ``OnMDrect2
``func ``= ``""
``active ``= ``""
``height ``= ``0
``width ``= ``0
``rect ``= ``"" ell = ""
EndSub
Thank you to Roshan for posting the October challenges!
Have a Small and Basic month!
- Ninja Ed