Challenge of the Month - January 2013
-
mercredi 2 janvier 2013 10:19Modérateur
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.
Small Challenge 1
Write a program to calculate the average of 10 random numbers (in the range 1 to 100). Then calculate the average of 100, 1000 or more of the random numbers. The average is just all the random numbers added together and then their total divided by the number of random numbers.
Small Challenge 2
Write a program to display a colorful welcome message in the GraphicsWindow when a button is clicked.
Small Challenge 3
Write a program to play 'Happy Birthday' or another well known tune using the Sound method.
Text Challenge
I have a lot of Small Basic files and they are not always well named - I can sometimes remember a variable name I used in one or some other phrase, but not the file name.
Write a program that searches all Small Basic programs in a directory to find all files (and the line numbers) containing a user input text.
Basically 'find a text' in files.
Physics Challenge
Write a program to reflect a light beam off a rotated surface.
Further challenge - make a game where the user must rotate the surfaces to get the beam to bounce off several surfaces and hit a target.
Community Suggestion Challenges
By Nonki Takahashi
1] Draw a picture of any zodiac (star) sign.
2] Write a quine. (Math Man early answer HRC429). Can you do it without a File command that reads the file, i.e. only File write commands?
By Amir CPS
1] Convert a number in decimal form to the equivalent mixed number with the fraction portion reduced to lowest terms.
Sample Input:
- 2.96
- 14.2
- 5.625
Sample Output:
- 2 AND 24/25
- 14 AND 1/5
- 5 AND 5/8
2] Read a string and determine whether each left parenthesis ‘(‘ has a matching right parenthesis ‘)’.
Sample Input:
- (3 + (7 * 2) – 6)
- HELLO AND (WELCOME (TO THE) SB (FORUM)
- TODAY) IS ((SATURDAY())
Sample Output:
- MATCH
- NO MATCH
- NO MATCH
3] The 8-Queens problem in chess is to place 8 queens on a chess board such that none of the queens is threatening any of the others. The problem is to input the 8 columns of the queens on the rows of a chess board, with 1 being the first column and 8 being the last, e.g. 1 2 3 4 5 6 7 8 means the queens are along the diagonal, which would not be a valid solution.
Write a program to test a user input guess.
Examples:
- Enter board configuration: 2 4 6 8 3 1 7 5 - This is a valid configuration (as above).
- Enter board configuration: 1 8 2 5 3 7 4 6 - This is NOT a valid configuration.
Do you have an idea for a future challenge? Please post it here!
- Modifié litdevMicrosoft Community Contributor, Moderator mercredi 2 janvier 2013 14:29
- Modifié litdevMicrosoft Community Contributor, Moderator mercredi 2 janvier 2013 17:37
- Modifié litdevMicrosoft Community Contributor, Moderator mercredi 2 janvier 2013 17:41
- Modifié litdevMicrosoft Community Contributor, Moderator jeudi 3 janvier 2013 20:08
- Modifié litdevMicrosoft Community Contributor, Moderator dimanche 6 janvier 2013 22:30
Toutes les réponses
-
mercredi 2 janvier 2013 13:56
My solution for the Text Challenge is published as JDS276.
It can search for text with and without ignoring upper/lower case.
A simple sulution for Amir CPS Challenge 2 is:
''PARENTHESES 2013-01-02 WhTurner t[1]="(3 + (7 * 2) – 6)" t[2]="HELLO AND (WELCOME (TO THE) SB (FORUM)" t[3]="TODAY) IS ((SATURDAY())" For i=1 To Array.GetItemCount(t) txt=t[i] TextWindow.WriteLine(txt) count=0 For j=1 To Text.GetLength(txt) char=text.GetSubText(txt,j,1) If char="(" Then count=count+1 EndIf If char=")" Then count=math.Max(0,count-1) EndIf EndFor If count=0 Then TextWindow.WriteLine("MATCH") Else TextWindow.WriteLine("NO MATCH") EndIf TextWindow.WriteLine("") EndFor
Jan [ WhTurner ] The Netherlands
- Modifié WhTurner33 mercredi 2 janvier 2013 13:56
- Modifié WhTurner33 mercredi 2 janvier 2013 14:00
-
mercredi 2 janvier 2013 14:14Modérateur
Good, but why use the Math.Max bit, "(3 + (7 * 2) – 6))" comes out as a MATCH.
Also we should find some way to make this not match "(3 + (7 * 2) – 6))(".
-
mercredi 2 janvier 2013 14:24Amir published the problem first in a post in the december 2012 challenge, with the requirement that a first right parantheses should be ignored. That was the reason for the math.max.
Jan [ WhTurner ] The Netherlands
-
mercredi 2 janvier 2013 14:27ModérateurOK, I understand - can you do it so the examples I gave also work.
-
mercredi 2 janvier 2013 14:45
If you put these lines instead of the IF/ENDIF with Math.Max in it it signals the lonely right parentheses, but gives then MATCH if the number left/right are equal.
If char=")" Then
count=count-1
If count<0 then
TextWindow.WriteLine("Right parentheses before a left one")
EndIf
EndIf
Jan [ WhTurner ] The Netherlands
-
mercredi 2 janvier 2013 14:50ModérateurYes that works, so some way to lead this to say NO MATCH. This is maybe one of the few cases where a GoTo is the best approach to get out of the For loop if count is ever < 0.
-
mercredi 2 janvier 2013 15:00place count=999 after the "Right parentheses before a left one". This gives surely a NO MATCH
Jan [ WhTurner ] The Netherlands
-
mercredi 2 janvier 2013 15:08Modérateur
That works too, assuming there aren't 999 misplaced right parentheses!
Also if count is < 0 then there is no way we can get a MATCH so there is no point continuing counting - therefore slightly more efficient to Break out of the loop; most languages have a Break command for this - Small Basic doesn't hence using a GoTo for this is one option, or set i = Array.GetItemCount(t) which ends the loop.
- Modifié litdevMicrosoft Community Contributor, Moderator mercredi 2 janvier 2013 15:11
-
mercredi 2 janvier 2013 20:42Auteur de réponse
Physics Challenge
LMB722
A spark to start a fire is necessary. But mainly you need dry kindling.
- Modifié Zock77Editor mercredi 2 janvier 2013 20:44
-
jeudi 3 janvier 2013 00:31
Here is the code I wrote for the famous 8-Queens problem in chess. I tried it on sevaral configurations and it turned out to work well. However I'm not still sure if there aren't any bugs. Try to find bugs and let me know (if any). Here is the link:
And here is the source code:
startover: TextWindow.WriteLine("Enter your configuraion as a serial number from left of the board to the right of the board(The nth character of your serial number represents the row at which the nth queen is located): ") config = TextWindow.Read() length = Text.GetLength (config) If length<>8 Then TextWindow.ForegroundColor = "red" TextWindow.WriteLine("There are supposed to be 8 queens, but your serial number has "+length+ " characters") TextWindow.ForegroundColor = "White" Goto startover EndIf For i=1 To length t[i] = Text.GetSubText(config, i, 1) EndFor For i=1 To length t2[i] = t[i] EndFor validity = "true" For i=1 To length For j=1 To length If t[i] = t2[j] And i<>j Then TextWindow.ForegroundColor = "Red" TextWindow.WriteLine("THIS IS NOT A VALID CONFIGURATION. The "+i+"th and the " +j+ "th queens threaten each other horizontally") TextWindow.WriteLine("") validity = "false" TextWindow.ForegroundColor = "White" Goto end EndIf EndFor EndFor If validity<>"false" Then For i=1 To length For j=1 To length If ((t[i] = t2[j] - (i-j)) Or (t[i] = t2[j] - (j-i))) And i<>j Then TextWindow.ForegroundColor = "Red" TextWindow.WriteLine("THIS IS NOT A VALID CONFIGURATION. The queen at the "+t[i]+"th row and "+i+"th column threatens the queen at the " +t2[j]+"th row and the "+j+"th column.") TextWindow.WriteLine("") validity = "false" TextWindow.ForegroundColor = "White" Goto end EndIf EndFor EndFor EndIf end: If validity = "true" Then TextWindow.ForegroundColor = "Red" TextWindow.WriteLine("It is valid configuration. Congratulations!") TextWindow.WriteLine("") TextWindow.ForegroundColor = "White" EndIf Goto startover
- Modifié Behnam Azizi jeudi 3 janvier 2013 00:32
- Modifié Behnam Azizi jeudi 3 janvier 2013 00:40
- Modifié Behnam Azizi jeudi 3 janvier 2013 00:41
- Modifié Behnam Azizi jeudi 3 janvier 2013 00:51
- Modifié Behnam Azizi jeudi 3 janvier 2013 00:56
- Modifié Behnam Azizi jeudi 3 janvier 2013 01:18
- Modifié Behnam Azizi jeudi 3 janvier 2013 01:21
-
jeudi 3 janvier 2013 02:34Auteur de réponse
This is my community suggestion challenge 3] by Amir CPS: QDX521.
Black queens means valid and red queens means NOT valid.
Nonki Takahashi
-
jeudi 3 janvier 2013 04:52
@Nonki
Woow, it was amazing!!!! How did you manage to draw the queens?
-
jeudi 3 janvier 2013 07:38
My solution for the 8-Queen problem.
Import : SMP050
@Nonki
Your program not working for me..??
@WhTurner33
Highlight the first lone right parenthesis if occurred or show a appropriate error message.
AndWhat about highlighting like this?
(3 + (7 * 2) – 6)
Merry Xmas!
-
jeudi 3 janvier 2013 08:54Auteur de réponse
This is my community suggestion challenge 1] by Nonki: RSH103.
2013 is a year of the snake as Oriental Zodiac.
Nonki Takahashi
-
jeudi 3 janvier 2013 08:57Auteur de réponse
Behnam,
Check source code of my program. I used unicode characters for chessmen.
Thanks.
Nonki Takahashi
- Modifié Nonki TakahashiEditor vendredi 4 janvier 2013 00:30
- Modifié Nonki TakahashiEditor vendredi 4 janvier 2013 00:31
-
jeudi 3 janvier 2013 08:59Auteur de réponse
Amir CPS,
Input such as "12345678".
Following inputs will be neglected.
"1 2 3 4 5 6 7 8"
"1234567"
"11234567"
"12345679"Or can't see any queens?
Nonki Takahashi
- Modifié Nonki TakahashiEditor jeudi 3 janvier 2013 12:26
- Modifié Nonki TakahashiEditor jeudi 3 janvier 2013 23:14
-
jeudi 3 janvier 2013 11:59Auteur de réponse
-
jeudi 3 janvier 2013 12:10
A new version for the parentheses checking follows. It marks matching parentheses with a "graphical" textline, and marks lonely right parentheses, and nonmatched left parentheses.
''PARENTHESES 2013-01-03 WhTurner space=" " line="^--------------------------------------------------------------------------------------" t[1]="(3 + (7 * 2) – 6))(" t[2]="HELLO AND (WELCOME (TO THE) SB (FORUM)" t[3]="TODAY) IS ((SATURDAY())" t[4]="(aaa(bbb(ccc)(ddd)))) For i=1 To Array.GetItemCount(t) pos=0 a="" txt=t[i] TextWindow.ForegroundColor="Green" TextWindow.WriteLine(txt) TextWindow.ForegroundColor="Gray" For j=1 To Text.GetLength(txt) If Text.GetSubText(txt,j,1)="(" Then pos=pos+1 a[pos]=j endif If Text.GetSubText(txt,j,1)=")" Then If pos=0 then TextWindow.Write(Text.GetSubText(space,1,j-1)) TextWindow.ForegroundColor="Red" TextWindow.Write("^") TextWindow.Write(" lonely right parentheses") TextWindow.ForegroundColor="Gray" TextWindow.WriteLine(" END checking") TextWindow.WriteLine("") j=999 ''end of check else TextWindow.Write(Text.GetSubText(space,1,a[pos]-1)) TextWindow.WriteLine(Text.GetSubText(line,1,j-a[pos])+"^") a[pos]="" pos=pos-1 endif endif '' ) EndFor ''j (textlength) If pos>0 Then For k=1 To pos TextWindow.Write(Text.GetSubText(space,1,a[k]-1)) TextWindow.ForegroundColor="Red" TextWindow.WriteLine("^") endfor TextWindow.WriteLine("unpaired left parentheses") TextWindow.WriteLine("") TextWindow.ForegroundColor="Gray" endif EndFor ''i (all teststrings)
Jan [ WhTurner ] The Netherlands
- Modifié WhTurner33 jeudi 3 janvier 2013 13:01
-
jeudi 3 janvier 2013 15:55Auteur de réponseBTW I forgot to tell yall... Use the up/down arrows to change the angle on my
Physics Challenge (LMB722)
A spark to start a fire is necessary. But mainly you need dry kindling.
-
jeudi 3 janvier 2013 18:39ModérateurNice work, can you add a second rotating reflection mirror - tough one this.
-
jeudi 3 janvier 2013 19:15
Amazing!! Didn't know that one could make such good shapes using unicode. Actually I don't have the knowledge to understand these yet.
I need a simple code by which I can learn the basics of making a shape using unicode characters. Can anyone help me?
- Modifié Behnam Azizi jeudi 3 janvier 2013 19:22
-
jeudi 3 janvier 2013 22:49Auteur de réponse
Behnam,
I couldn't find any bugs in your 8-Queens program. I tried 3 non-valid configurations and 13 valid configurations.
Test data:
NOT valid:
12345678
18253746
87654321
valid:
24683175
17468253
17582463
41582736
51842736
31758246
51468273
71386425
51863724
57142863
63184275
53172864
46827135
Nonki Takahashi
- Modifié Nonki TakahashiEditor vendredi 4 janvier 2013 00:31
- Modifié Nonki TakahashiEditor vendredi 4 janvier 2013 00:32
-
jeudi 3 janvier 2013 23:13Auteur de réponse
Behnam,
How to use unicode characters in Small Basic program:
(1) Find characters in charmap.exe.
I can find chessmen only in "MS UI Gothic" font.
(2) Copy characters (e.g. "♟") or their code (e.g. "U+265F").
(3) For code, convert hexadecimal to decimal (e.g. 265F -> 9823) and use Text.GetCharacter(code).Nonki Takahashi
-
vendredi 4 janvier 2013 18:16
Small Challenge 1
Code :
'---------------------------------------------------------------- 'Challenge of the month : January 2013 | 'Category : Small Challenge 1 | 'Date 4/01/2013 - DD/MM/YYYY | '---------------------------------------------------------------- 'Title of the text window TextWindow.Title = "Avarage of sum of N number" 'Call main subrutine Init() Sub Init Sum = 0 TextWindow.Write("Enter number : ") 'Ask user to input a number Num = TextWindow.ReadNumber() 'Get user input and allow only if Num is a whole number If Math.Floor(Num) - Num <> 0 Or Num < 0 Then ' Show a error message if condition is not met Error() Else 'proceed further otherwise Go() EndIf EndSub Sub Go 'Generate random number GenRandomNums() 'sum em all SumofAllNum() 'Print the output on text window Print() EndSub Sub GenRandomNums For i = 1 To Num Rnd = Math.GetRandomNumber(100) RandomNums[i] = Rnd ' Store number in an array EndFor EndSub Sub SumofAllNum For i = 1 To Num Sum = Sum + RandomNums[i] 'Sum all of them EndFor EndSub Sub Print For i = 1 To Num TextWindow.WriteLine(RandomNums[i]) EndFor TextWindow.WriteLine("---------------------------------------------------------------------") TextWindow.WriteLine("Sum of all random numbers = "+Sum) Avarage = Sum / Num TextWindow.WriteLine("Avarage of all random numbers = "+Avarage) TextWindow.Pause() TextWindow.Clear() Init() EndSub Sub Error TextWindow.WriteLine("Should be a whole number. Please try again.") TextWindow.Pause() TextWindow.Clear() Init() EndSub
Merry Xmas!
-
vendredi 4 janvier 2013 18:36Modérateur
Amir, this works well, I like the input validation. For a large number input, what would you expect the average to be?
For large, numbers Small Basic arrays are slow, and in this case they are not needed. All the work could be done in one loop without storing the random numbers to an array - speeds it up a lot for say 10000. With this mod I can calculate 1000000 in about 1 sec.
-
vendredi 4 janvier 2013 18:51
Amir, this works well, I like the input validation. For a large number input, what would you expect the average to be?
For large, numbers Small Basic arrays are slow, and in this case they are not needed. All the work could be done in one loop without storing the random numbers to an array - speeds it up a lot for say 10000. With this mod I can calculate 1000000 in about 1 sec.
I tried up to 10000 times and the average was always 50 ∓ 2-3.
And about the program, i actually made it to look like a 'program' otherwise i was could make it under 10 lines.
Edit :
TextWindow.Write("Enter a whole number : ") Sum = 0 Num = TextWindow.ReadNumber() For I = 1 To Num Rnd = Math.GetRandomNumber(100) TextWindow.WriteLine(Rnd) Sum = Sum + Rnd EndFor Avarage = Sum/Num TextWindow.WriteLine("The sum is = "+Sum+" And the Average is = "+Average)
Merry Xmas!
-
vendredi 4 janvier 2013 19:21ModérateurVery good, would you expect the average to be closest to 49, 49.5, 50, 50.5, 51 or something else?
-
samedi 5 janvier 2013 04:47
Num = 100 FiftyCount = 0 For J = 1 To 1000000 Main() EndFor TextWindow.WriteLine(FiftyCount +" Times") Sub Main Sum = 0 For I = 1 To Num Rnd = Math.GetRandomNumber(100) Sum = Sum + Rnd EndFor Average = Sum / Num If Average = 50 Then FiftyCount = FiftyCount + 1 EndIf EndSubI Ran this program multiple times the occurrence of Average was :
In a range of 49-51 = 48456
And exact 50 was occurred 1385 times.
Merry Xmas!
-
samedi 5 janvier 2013 10:02Modérateur
50 is not the average "exact" value I would expect - there are 100 numbers possible from 1 to 100, their average can be seen below.
sum = 0 For i = 1 To 100 sum = sum + i EndFor TextWindow.WriteLine(sum/100)
Or by symmetry 1+100 = 101, 2+99 = 101 .... 50+51 = 101, therefore the average is (first+last)/2 = (1+100)/2.
-
dimanche 6 janvier 2013 17:07
Average of random numbers.
The following program shows what happens if you calculate the average of a number of random numbers.
For 100, 1000 and 10000 the average is calculated 1000 times. The distribution of the results is shown in a graphical window. You can see values between 50 and 50.9999 are the most abundant, and the distribution becomes smaller for a greater number of draws of random numbers.
''Disribution of average random 2013-01-06 WhTurner ''=========================================== col="1=Red;2=Green;3=Blue" GraphicsWindow.Show() GraphicsWindow.Top=10 GraphicsWindow.Height=650 GraphicsWindow.PenColor="Black" GraphicsWindow.BrushColor="Black" GraphicsWindow.DrawText(100,50,"Distribution of the average of Math.GetRandomNumber(100)") GraphicsWindow.DrawText(100,70,"calculated 1000 times") GraphicsWindow.DrawLine(100,600,500,600) For i=40 To 60 Step 5 GraphicsWindow.DrawLine(10*i-205,600,10*i-205,100) GraphicsWindow.DrawText(10*i-215,610,i) EndFor N=10 For k=1 To 3 N=N*10 ''100,1000,10000 GraphicsWindow.BrushColor=col[k] GraphicsWindow.PenColor=col[k] GraphicsWindow.DrawText(400,50+20*k,"average of "+N+" draws") For i=1 To 1000 sum=0 For j=1 To N sum=sum+math.GetRandomNumber(100) EndFor bar=math.Floor(sum/N) Distr[k][bar]=Distr[k][bar]+1 EndFor lx=200 ly=600 For i=40 To 59 ii=10*i-200 aa=600-Distr[k][i]/2 GraphicsWindow.DrawEllipse(ii-3,aa-3,6,6) GraphicsWindow.DrawLine(lx,ly,ii,aa) lx=ii ly=aa EndFor endfor
Jan [ WhTurner ] The Netherlands
- Modifié WhTurner33 dimanche 6 janvier 2013 17:08
-
dimanche 6 janvier 2013 21:27Text Challenge : DKC138
-
dimanche 6 janvier 2013 22:23
My decimal to lowest terms fraction convertor: PBS429
Amir, I've found a problem in one of your outputs. 2 AND 19/20 should be 2 AND 24/25.
I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'
-
dimanche 6 janvier 2013 22:32ModérateurWell spotted MathMan and nice answer - corrected challenge.
-
lundi 7 janvier 2013 20:24
@Math Man,
Nice your answer is nice. BTW there is very simple way to achieve this
WholeNumber = Text.GetSubText(Input,1,WhereDecimalPoint-1) 'the decimal part AfterDecimalPoint = Text.GetSubTextToEnd(Input,WhereDecimalPoint+1) If Text.GetLength(AfterDecimalPoint) > MaxDecimalLength Then 'it exceeds the total length so we shorten it AfterDecimalPoint = Text.GetSubText(AfterDecimalPoint,1,MaxDecimalLength)By
AfterDecimalPoint = Input - Math.Floor(Input) BeforeDecimalPoint = Math.Floor(Input)
Merry Xmas!
-
lundi 7 janvier 2013 20:29
My decimal to lowest terms fraction convertor: PBS429
Amir, I've found a problem in one of your outputs. 2 AND 19/20 should be 2 AND 24/25.
I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'
My Solution, not commented like yours neither has any input validation but i managed to done it in a single nested loop and couple of if else commands.
Import : DZS164
Merry Xmas!
-
lundi 7 janvier 2013 20:40
The shape was drawn by an external program? May be by your Shapes Editor?
Unfortunately i did not get the calender output like in the ScreenShot.
Merry Xmas!
- Modifié 4mir '- lundi 7 janvier 2013 20:40
-
mardi 8 janvier 2013 23:46
Community Suggestion Challenges By Amir CPS
1] Convert a number in decimal form to the equivalent mixed number with the fraction portion reduced to lowest terms.
maxNMB=Math.Power(10,6) ' you may change Power number
TextWindow.Write("input a number= ")
a=textwindow.ReadNumber()
For i=1 To maxNMB
b=a*i
If (b*10-math.Floor(b)*10)=0 Then
bb=i 'Denominator
bs=math.Floor(b) 'Numerator+WholeNumber
i=maxNMB
EndIf
EndFor
nmb=math.Floor(bs/bb) 'WholeNumber
bs=bs-nmb*bb 'Numerator
TextWindow.WriteLine("Answer= "+nmb+" and "+bs+"/"+bb)
resid=bs/bb ' confirmation
midP=text.GetIndexOf(resid,".")
TextWindow.WriteLine("Your input number is ... "+nmb+" . "+Text.GetSubTextToEnd(resid,midP+1)) -
mercredi 9 janvier 2013 19:23Modérateur@NaochanON - Nice concise and efficient algorithm.
-
jeudi 10 janvier 2013 01:10Auteur de réponse
Amir,
Yes, the shape was drawn by Shapes Editor.
The calendar is just a text drawn by Shapes.AddText(). So I used "Consolas" as fixed pitch font. Your screen shot seems using proportional font. If you don't have "Consolas" in your system, please use fixed pitch font such as "Courier New" in Cal_DrawMonth subroutine.
Nonki Takahashi
-
jeudi 10 janvier 2013 15:15
Text Challenge QWT409 Input File No and click "Load_OK"
- Modifié NaochanON jeudi 10 janvier 2013 15:18
-
vendredi 11 janvier 2013 06:05
My Solution for the Text Challenge
Import : LSB518
@NaoChanON
look like you have big collection of Small Basic programs, if you don't have any problem please send me all those files. :)
@LitDev
Could you explain what is the reason behind getting average of random numbers close to 50 every time. I ask my teacher the same question and he replied that you will learn all this in next grades.
PS: My Email is amir_rt@live.com :P @NaoChanON
- Modifié 4mir '- vendredi 11 janvier 2013 06:10
-
vendredi 11 janvier 2013 13:44
Amir,
LitDev gave an answer on januari 5th. MathGetRandomNumber(X) gives all possible integer numbers from 1 to X. So MathGetRandomNumber(100) gives all number from 1 to 100 inclusive with equal possibilities. The average is then (1+100)/2.
When you want simulate the throw of a dice the possible outcomes are 1,2,3,4,5 and 6. The average is then (1+6)/2 = 3.5 You can try that in your average-calculation program with MathGetRandomNumber(6). You will get then the average of 3.5 after a sufficient numer of draws.
Jan [ WhTurner ] The Netherlands
-
vendredi 11 janvier 2013 14:05
@NaoChanON
look like you have big collection of Small Basic programs, if you don't have any problem please send me all those files. :)
Amir and guys.
Most of them are available from here. Total 212 files. (Those are all published programs)
3 folders.
1)Co-Op programs ...11 (with absolue,amir,zock)
2)My programs........ 73
3)Other person's programs...128 (Microsoft,Litdev,Amir,Nonki,Math man,Alex,Krueg,timo etal)
-
vendredi 11 janvier 2013 15:08
Thanks NaoChanON & WhTurner33
Merry Xmas!
-
samedi 12 janvier 2013 17:47
I have made a new version of my TextSearch program (Text Challenge) JDS276-0
In addition to give linenumbers in all *.sb files in which the text is found, it can now LIST the lines in one given file in which the search text is found.
Jan [ WhTurner ] The Netherlands
- Modifié WhTurner33 dimanche 13 janvier 2013 10:40
-
samedi 12 janvier 2013 23:50
Text Challenge new version . it shows the line numbers . QWT409-1
-
dimanche 13 janvier 2013 17:23
My Physics Challenge: XKS442
It doesn't have a great collision detection system, but it works okay.
I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'
-
dimanche 13 janvier 2013 18:23Modérateur
@Math Man. Pretty good, I like the use of the reflection angle method.
LightBeamAngle = (Normal-LightBeamAngle)*2+LightBeamAngle
The detection of hitting a mirror could be modified using algebra (basically finding the intersection of 2 lines, the mirror and light beam), but what you have works well and certainly meets the challenge.
-
lundi 14 janvier 2013 00:38Idea for a future easy challenge: Make a program to organize an array alphabetically.
I am an 11 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'
- Modifié Math Man lundi 14 janvier 2013 00:38
-
lundi 14 janvier 2013 15:08
I've posted my answer to the
Small Challenge 2Write a program to display a colorful welcome message in the GraphicsWindow when a button is clicked.
http://smallbasic.com/smallbasic.com/program/?FBT176
It has 2 buttons and is hopefully simple to read and use for the operator. Not overly colourful but some animation designed to assist the operator.
I'm not upto the controls part of the curriculum yet so it was a good exercise for me.
It runs better on my PC than it does in the Program Listing window...?
-
mardi 15 janvier 2013 10:58
@ Math Man:
In my solution to TextChallenge I (december 2012) was included a part to sort a array with words alphabetically
Jan [ WhTurner ] The Netherlands
-
mardi 15 janvier 2013 14:23Auteur de réponse
This is my community suggestion challenge 2] by Nonki.
code[1] = "C = Text.GetCharacter(99)" code[2] = "O = Text.GetCharacter(111)" code[3] = "D = Text.GetCharacter(100)" code[4] = "E = Text.GetCharacter(101)" code[5] = "BL = Text.GetCharacter(91)" code[6] = "BR = Text.GetCharacter(93)" code[7] = "SP = Text.GetCharacter(32)" code[8] = "EQ = Text.GetCharacter(61)" code[9] = "WQ = Text.GetCharacter(34)" code[10] = "For i = 1 To 15" code[11] = " TextWindow.WriteLine(C+O+D+E+BL+i+BR+SP+EQ+SP+WQ+code[i]+WQ)" code[12] = "EndFor" code[13] = "For i = 1 To 15" code[14] = " TextWindow.WriteLine(code[i])" code[15] = "EndFor" C = Text.GetCharacter(99) O = Text.GetCharacter(111) D = Text.GetCharacter(100) E = Text.GetCharacter(101) BL = Text.GetCharacter(91) BR = Text.GetCharacter(93) SP = Text.GetCharacter(32) EQ = Text.GetCharacter(61) WQ = Text.GetCharacter(34) For i = 1 To 15 TextWindow.WriteLine(C+O+D+E+BL+i+BR+SP+EQ+SP+WQ+code[i]+WQ) EndFor For i = 1 To 15 TextWindow.WriteLine(code[i]) EndFor
Nonki Takahashi
- Modifié Nonki TakahashiEditor mardi 15 janvier 2013 14:27
-
mardi 15 janvier 2013 20:42ModérateurVery cool Nonki, good challenge and good answer!
-
jeudi 17 janvier 2013 02:42Auteur de réponse
-
samedi 19 janvier 2013 05:39
I thought the challenge meant for when a mouse button was clicked, but I see many others put a real button in their programs.
Nonetheless, I bring you my taste of "Small Challenge 2."
As always, I used the GraphicsWindow.GetRandomColor... I am addicted to it :P
Here is the import code: SXK087
TextWindow.Write("Do you like Small Basic? Y/N: ")
yn = TextWindow.Read()
If yn = "Y" Then
TextWindow.WriteLine("High-Five! You are awesome!")
ElseIf yn = "N" Then
TextWindow.WriteLine("Deep down inside, you like Small Basic :)")
EndIf- Modifié Joman Mied samedi 19 janvier 2013 05:40 Added a hyperlink to my import code for the Silverlight Web-based app.
-
samedi 19 janvier 2013 07:37
Physics Challenge TJZ561
I made a game for this challenge. ...... Bullet reflection shooting game.
1 wall rotates. 2nd wall is stable. Can you hit red ball within 10 shots?
- Modifié NaochanON samedi 19 janvier 2013 07:45 changed photo
-
lundi 28 janvier 2013 17:12
10-Line solution for Small Challenge 1: QBK201 / http://smallbasic.com/program/?QBK201
This program calculates and displays the average of 10, 100, then 1,000 random numbers:
For i = 1 To 3 End = Math.Power(10, i) DisplayAverageOfRands() EndFor Sub DisplayAverageOfRands For j = 1 To End Total = Total + Math.GetRandomNumber(100) EndFor TextWindow.WriteLine("Average of " + End + " numbers: " + Total / End) EndSubNote that I didn't bother with user input.
EDIT: I added 8 lines, and now it safely handles user input and clueless users. New code: SGW300 / http://smallbasic.com/program/?SGW300
TextWindow.Write("Calculates the average of random numbers. Input a positive number to average that many numbers, or input nothing or '0' to see examples of 10, 100, and 1,000 numbers: ") End = Math.Round(TextWindow.ReadNumber()) If End > 0 Then DisplayAverageOfRands() ElseIf End < 0 Then TextWindow.WriteLine("Only positive integers are accepted.") Else For i = 1 To 3 End = Math.Power(10, i) DisplayAverageOfRands() EndFor EndIf Sub DisplayAverageOfRands For j = 1 To End Total = Total + Math.GetRandomNumber(100) EndFor TextWindow.WriteLine("Average of " + End + " numbers: " + Total / End) EndSubNote that if you input any value over 10,000,000 even this simple implementation will lag pretty badly. Anything under 100,000 should be instantaneous.
- Modifié AgentE382 lundi 28 janvier 2013 18:11 Changed program.
-
lundi 28 janvier 2013 17:12Auteur de réponse
-
lundi 28 janvier 2013 17:15
Ideas for next month's challenge
Draw a periodic table (Chemistry) and show all the basic properties of the element in a popup box when mouse is clicked on a box.
Draw a heart shape and calculate it's the area.
Merry Xmas!
-
mardi 29 janvier 2013 00:01
Mirror 2 does not reflect.
This is the way I thought. Maybe detection of X2,Y2 is wrong.
Note; Slope i will be decided automatically.- Modifié NaochanON mardi 29 janvier 2013 00:05

