Challenge of the Month - November 2012

# Challenge of the Month - November 2012

• Wednesday, October 31, 2012 8:34 PM
Moderator

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.

Text Challenge 1

Get the user to input a sentence and count how many times each letter in the alphabet is used.

Find the most common letter; often it is ‘e’.

Text Challenge 2

Write a TextWindow program to welcome a user and ask for their name.

Ask for more details like their age or where they live.  After each question, reply using some of the information already gained about the user to ask a new question.  For example if the user is under 18 you might ask if they are at school, otherwise you might ask if they work.

A conversation might go like this:

Computer: Welcome, what is your name?
User: John
Computer: Hello John, how old are you?
User: 15
Computer: Are you still at school John?
User: Yes
Computer: Where do you live John?
User: New York
Computer: Is New York near Seattle?
etc

Math Challenge 1

Find all the numbers less than 1000, where the sum of the digits is 15, for example 96 or 177.  How many are there?

If you fancy a further challenge, then calculate how many numbers less than 1000 there are that have a sum of digits equal to each of the possible values (not just 15, i.e. 1, 2, 3 … 25, 26, 27).

Math Challenge 2

Create a program that allows the user to create 3 points on the GraphicsWindow – perhaps use a mouse click to set a point.  Your program will join them up and calculate the area of the resulting triangle.

Graphical Challenge

Draw a scene with weather conditions, perhaps cloudy sky, or rain, wind or snow.

Events Challenge

Use the keyDown and keyUp events to display a simple keyboard on the GraphicsWindow showing which keys are currently pressed (perhaps red while the key is down).

It doesn’t have to be all possible keys, you could just do it for the arrow keys.

Physics Challenge

Running out of simple physics challenges - this one isn't much harder, just takes more explaining.

An ideal gas has the following equation relating its pressure (P Bars), volume (V litres) and temperature (T degC).  http://en.wikipedia.org/wiki/Ideal_gas

(1)    P * V / (273 + T) = constantA (ideal gas equation)

This means that if we know the starting state (P, V & T) and any 2 quantities are changed then the 3rd can be calculated.

If we start at P = 2 Bar, V = 1 litre and T = 20 C and change the pressure, volume or temperature, then the others will change to keep the equation equal to constantA.

For example if we keep the temperature constant and double the volume, then the pressure will half (Boyle’s Law).

If there is no heat transfer (or technically no entropy change), then the following equation also holds for gases.  https://en.wikipedia.org/wiki/Isentropic_process

(2)    P * V^g = constantB (isentropic or adiabatic expansion)

g is a property of the gas (isentropic exponent), for air it is about 1.4.

V^g means V to the power of g; in SmallBasic this is Math.Power(V, g).  If you don’t know about powers then use P * V * V = constantB.

If we know the starting pressure and volume, then we can calculate the change in either P or V if the other is changed.

An example of gas compression heating a gas is the warming of a bicycle pump, and gas expansion cooling a gas might be ice that forms on the nozzle when a CO2 fire extinguisher is used, or even how a fridge works.

So if the volume changes, then the pressure will change according to (eqn 2) and the resulting pressure and volume change lead to a change in temperature (eqn 1).

Calculate and perhaps plot the change in temperature and pressure as we increase (expand) or decrease (compress) the gas volume.

Hint: Equations 1 and 2 can be written to show how the initial and new values of P,V,T are related:

(273 + T2) / (P2 * V2) = (273 + T1) / (P1 * V1)
P2 = P1 * (V1/V2)^g
where P1,V1,T1 are initial values and P2,V2,V2 are new values.

How much must we expand 1 litre of air to cool it from 20C to 0C?  What is the pressure change if we start at 2 Bar?

Not a programming question, but would it take more or less or similar effort pump up a cycle tire on a hot or cold day?

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

### All Replies

• Thursday, November 01, 2012 3:26 PM

Unable to resist the urge to troll and be the first to post. Here is a solution for the first text challenge. Enjoy.  :-)

importCode: SCB444

• Thursday, November 01, 2012 5:17 PM

Events Challenge : SJV156

Only did the arrow keys, I will maybe do the rest later...

• Thursday, November 01, 2012 5:39 PM

It was a day off at school so I decided to do both the second math challenge and the graphics challenge -- COMBINED!!

So here it is:

Import code: BFQ294

Link: BFQ294

There. The math took me a few tries, but I believe I've got it.

I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

• Edited by Thursday, November 01, 2012 5:42 PM
• Edited by Thursday, November 01, 2012 5:44 PM
• Edited by Thursday, November 01, 2012 6:15 PM
• Edited by Thursday, November 01, 2012 7:52 PM
• Edited by Friday, November 02, 2012 3:15 AM
• Edited by Friday, November 02, 2012 3:16 AM
• Edited by Friday, November 02, 2012 3:16 AM
• Edited by Friday, November 02, 2012 3:16 AM
•
• Thursday, November 01, 2012 6:39 PM
Moderator

Nice snow, I like the flakes.  Not sure the triangle area is right.  I drew one with full width and height of the green grass (should be length 400 and height 200 - the height was a good bit larger).  Do you know anything about trig or vector cross products?

• Thursday, November 01, 2012 6:41 PM
Moderator

The keys works well, sometimes if I hold 3 keys down (all three light up well), but when I let the keys up sometimes some of the red lights stay on.
• Thursday, November 01, 2012 6:42 PM
Moderator

The text challenge looks good.
• Thursday, November 01, 2012 7:50 PM

Just fixed it. I used wikipedia to help.

I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

• Thursday, November 01, 2012 11:30 PM

Math Challenge 2     BJW864

*Calculating formula

'   X^2+y^2=a^2    ...........  ①
'  (c-x)^2+y^2=b^2  .......... ②
'  ② -  ① =  (c-x)^2  -  x^2 = b^2  -  a^2     therefore   2cX=(a^2 - b^2+c^2)  --->  X= (a^2 -b^2+c^2) /2c
'  Y  =  sqr(a^2  -  x^2)

• Edited by Thursday, November 01, 2012 11:31 PM
•
• Friday, November 02, 2012 3:13 AM

Perhaps for the next physics challenge it could be to display nuclear fission in motion using shapes methods.

I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

• Friday, November 02, 2012 11:08 AM
Moderator

If 3 points of a triange are (Ax,Ay) (Bx,By) and (Cx,Cy), then by cross product the triangle area is:

Area = Abs[(Bx-Ax)*(Cy-Ay) - (By-Ay)*(Cx-Ax)] / 2

This is equvalent to (|AB|*|AC|*sin(BAC)/2) the length of 2 sides multiplied * Sin(of angle between them), all divided by 2.

• Friday, November 02, 2012 6:52 PM

Here is my solution for Text Challenge 1  :  RLB426

It can read multiple lines from the keyboard or from a textfile.

It counts upper case characters, lower case characters en the sum of these.

It gives also the total number of alphabetical characters, number of digits , number of spaces and number of other characters as ?!@#\$%^&*()

Also it reports the most abundant character.

Jan [ WhTurner ] The Netherlands

• Friday, November 02, 2012 7:18 PM
Moderator

Nice work Jan, here's mine - a bit more basic.

TextWindow.WriteLine("Enter a sentence")
txt = TextWindow.Read()

chars = ""
For i = 1 To Text.GetLength(txt)
char = Text.GetSubText(txt,i,1)
chars[char] = chars[char]+1
EndFor

charIndex = Array.GetAllIndices(chars)
charCommon = ""
For i = 1 To Array.GetItemCount(charIndex)
char = charIndex[i]
TextWindow.WriteLine(char+" occured "+chars[char]+" times")
If (chars[char] > chars[charCommon]) Then
charCommon = char
EndIf
EndFor
TextWindow.WriteLine("The most common letter was "+charCommon)

• Saturday, November 03, 2012 6:47 AM

My thought on the question about the pump and cycle tire:

I think it would take [slightly] more effort on a cold day to pump the tire because the air molecules have less energy therefore making them "clump" together, meaning you have to force the "clumps" through the hose.

Hence, it would be easier to pump a tire on a hot day because the air molecules have more energy, making the matter less viscous and more willing to go through the hose.

I guess if you think about the tire as well, on a cold day, the outside air is cooled, compressed naturally ever so slightly, pulling on the tire. This would create a [very slight] vacuum inside the tire, pulling air through the hose.

Likewise, on a hot day, the outside air is more energized and less viscous, pushing on the tire. This makes the tire a bit less acceptant of more air, increasing your effort.

There may be other factors that would contribute to this, and if I am rambling on about nothing, am wrong on something, or heading in the right direction, please tell me :)

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

• Saturday, November 03, 2012 2:44 PM
Moderator

Good thoughts,  on a cold day the air will be denser,  but the volume of air needed to increase the tire pressure will be about the same as on a hot day so the same number of pump strokes.  Because the air on a cold day is denser it may take a bit more effort to pump and may loose a bit more of the pumping effort as heat it may be slightly harder on a cold day.

Here is a start for the programming part.

initialPressure = 2 'Bar
initialVolume =  1 'Litre
initialTemperature = 20 'degC
isentropicExponent = 1.4 'Approximately air

constantA = initialPressure * initialVolume / (273 + initialTemperature)
constantB = initialPressure * Math.Power(initialVolume, isentropicExponent)

For Volume = 0.8 To 1.2 Step 0.01
Pressure = constantB / Math.Power(Volume, isentropicExponent)
Temperature = (Pressure * Volume / constantA) - 273
'Write results rounding to 2 decimal places
TextWindow.WriteLine("Volume = "+0.01*Math.Floor(0.5+100*Volume)+" Pressure = "+0.01*Math.Floor(0.5+100*Pressure)+" Temperature = "+0.01*Math.Floor(0.5+100*Temperature))
EndFor

• Saturday, November 03, 2012 3:56 PM

litdev,

I added a lot of graphicswindow commands to your program to show a graph, published as RXP916

Jan [ WhTurner ] The Netherlands

• Saturday, November 03, 2012 4:05 PM
Moderator

Wow that was quick!
• Saturday, November 03, 2012 10:42 PM

Right, the volume of air... Tsk, tsk, tsk, how'd I forget that?

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

• Sunday, November 04, 2012 9:39 PM

Here is my Text Challenge 2:

TextWindow.Title = "Text Challenge 2 - November 2012"
TextWindowPlus.Width = 100
TextWindowPlus.Height = 25
TextWindow.Top = 0
TextWindow.Left = 0

TextWindow.Write("Welcome! What is your name? ")
name = TextWindow.Read()
TextWindow.WriteLine("How are you today, " + name + "?")
TextWindow.Write("Press 1 for Great!, 2 for Okay, or 3 for Not Very Good: ")
mood = TextWindow.Read()
If mood = "1" Then
TextWindow.Write("That's good! I am glad to hear that! So, tell me, " + name + ", what is your hobby? ")
hobby = TextWindow.Read()
Goto Next
ElseIf mood = "2" Then
TextWindow.Write("You're feeling only 'okay'? What's your hobby? That might cheer you up! ")
hobby = TextWindow.Read()
Goto Next
ElseIf mood = "3" then
TextWindow.Write("I am sorry to hear that, " + name + "! Maybe your hobby would make you feel better! What is your hobby? ")
hobby = TextWindow.Read()
Goto Next
Else
TextWindow.Write("Please input a valid number: ")
EndIf
Next:
TextWindow.Write("Where do you live? ")
live = TextWindow.Read()
TextWindow.WriteLine("So you " + hobby + " in/at " + live + "? Sounds interesting!")
Program.Delay(2000)
TextWindow.Write("What time is it? (HH:MM AM/PM) [Write with colon ':'] ")
Time = TextWindow.Read()
TextWindow.WriteLine("Here is your overview:")
TextWindow.WriteLine("Your name is " + name + ", who lives in/at " + live + ", where you " + hobby + " at " + Time + ".")
Program.Delay(5000)
TextWindow.Write("It has been great talking to you, " + name + "! Bye.")
Program.Delay(1500)
Program.End()

When I use a variable, it may not be grammatically correct, depending on what the user inputs.

I am thinking of making it a more GUI based program with buttons instead. Destroys the purpose of being a "Text Challenge," but I want to get more used to making GUIs :P

I will supply an Import code when my tweaks are completed.

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

• Sunday, November 04, 2012 11:16 PM
Answerer

HiYa Joman Mied!

Some bits of tips for your Text Challenge 2:

• TextWindowPlus.Width = 100 & TextWindowPlus.Height = 25 are extension methods, which are not allowed according to challenge rules!
• Those Goto Next are very redundant. They're being used inside a "chained" If...ElseIf...Else...EndIf! The thing is, if any of them are evaluated as "True", all the rest below is ignored, and the execution would leap straight to the next statement after the EndIf anyways!!! Perhaps it's a confusion to a similar method using keyword Case, which demands the use of keyword Break to interrupt it. But they're not implemented in Small Basic yet.
• And for our lazy users of your program, please use TextWindow.ReadKey() rather than TextWindow.Read(); lest we need to press <Enter> even if the input is just a single key! Of course, TextWindow.Read() is still needed for a whole sentence input; same to TextWindow.ReadNumber for a literal value input!

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

• Monday, November 05, 2012 12:17 AM

Right, GoToLoop, I forgot that TextWindowPlus is an extension. Sorry 'bout that! I will rewrite without.

And, I will take your suggestion of using TextWindow.ReadKey() and/or TextWindow.ReadNumber() and add that to my rewrite as well.

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

• Monday, November 05, 2012 12:20 AM

Here is my rewrite, feel free to give any other feedback:

TextWindow.Title = "Text Challenge 2 - November 2012"
TextWindow.Top = 0
TextWindow.Left = 0

TextWindow.Write("Welcome! What is your name? ")
name = TextWindow.Read()
TextWindow.WriteLine("How are you today, " + name + "?")
TextWindow.Write("Press 1 for Great!, 2 for Okay, or 3 for Not Very Good: ")
mood = TextWindow.ReadNumber()
If mood = "1" Then
TextWindow.Write("That's good! I am glad to hear that! So, tell me, " + name + ", what is your hobby? ")
hobby = TextWindow.Read()
Goto Next
ElseIf mood = "2" Then
TextWindow.Write("You're feeling only 'okay'? What's your hobby? That might cheer you up! ")
hobby = TextWindow.Read()
Goto Next
ElseIf mood = "3" then
TextWindow.Write("I am sorry to hear that, " + name + "! Maybe your hobby would make you feel better! What is your hobby? ")
hobby = TextWindow.Read()
Goto Next
Else
TextWindow.Write("Please input a valid number: ")
EndIf
Next:
TextWindow.Write("Where do you live? ")
live = TextWindow.Read()
TextWindow.WriteLine("So you " + hobby + " in/at " + live + "? Sounds interesting!")
Program.Delay(2000)
TextWindow.Write("What time is it? (HH:MM AM/PM) [Write with colon ':'] ")
Time = TextWindow.Read()
TextWindow.WriteLine("Here is your overview:")
TextWindow.WriteLine("Your name is " + name + ", who lives in/at " + live + ", where you " + hobby + " at " + Time + ".")
Program.Delay(5000)
TextWindow.Write("It has been great talking to you, " + name + "! Bye.")
Program.Delay(1500)
Program.End()

Like I said, give any feedback you want to, I am open to positive (or negative) criticism.

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

• Monday, November 05, 2012 12:24 AM

Here is my more graphical version. I am thinking of, instead of waiting 20 seconds, adding an "Enter" button or "Continue" button so you can add as much info as you want. Warning: The questions are a little different! And as before, the grammar my be a little messed up depending on what the user's input is!

'(C) 2012 by JOman Mied. Comments throughout code!
GraphicsWindow.Title = "Text Challenge 2 - November 2012 (Graphic Version)"
GraphicsWindow.Width = 852
GraphicsWindow.Height = 500
GraphicsWindow.Top = 0
GraphicsWindow.Left = 0
i = 0

'GraphicsWindow Setup
GraphicsWindow.BackgroundColor = "darkblue"
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(0, 3, "Use the provided text-box to type your responses. Your answers will be saved and the textbox will be automatically cleared after 20 seconds.")
GraphicsWindow.BrushColor = "Black"
Resp = Controls.AddTextBox(339, 20,)
GraphicsWindow.BrushColor = "White"
GraphicsWindow.DrawText(0, 40, "Questions will appear here:")

'First, a pause so the user can read the instructions, then the questions begin!
Program.Delay(20000)
'Question One
GraphicsWindow.DrawText(0, 60, "1. What is your name?")
Program.Delay(20000)
'You can find the subroutine at the end of this code
GetAnswer()
'Using the user's name, I ask question 2:
GraphicsWindow.DrawText(0, 80, "2. How are you today, " + Answer[1] + "? Available answers are: 'Great', 'Okay', or 'Bad'.")
Program.Delay(20000)
GetAnswer()
'Using the user's input for mood, I create different scenarios with the same question:
If Answer[2] = "Great" Or Answer[2] = "great" Then
GraphicsWindow.DrawText(0, 100, "3. You're feeling great? That's good to hear! Say, " + Answer[1] + ", what is your hobby?")
ElseIf Answer[2] = "Okay" Or Answer[2] = "okay" Then
GraphicsWindow.DrawText(0, 100, "3. You're feeling only 'okay'? What's your hobby? Maybe it'll cheer you up!")
ElseIf Answer[2] = "Bad" or Answer[2] = "bad" then
GraphicsWindow.DrawText(0, 100, "3. I am sorry to hear that, " + Answer[1] + "! Maybe your hobby will make you feel better. What is your hobby?")
EndIf
'Getting the answer for #3 (Burried in the If...ElseIf...EndIf statement.
Program.Delay(20000)
GetAnswer()
'Question 4:
GraphicsWindow.DrawText(0, 120, "4. So you like to " + Answer[3] + "? What time is it? (Format-> HH:MM AM/PM)")
Program.Delay(20000)
GetAnswer()
'Using time:
GraphicsWindow.DrawText(550, 120, "It is " + Answer[4] + ".")
'Question 5, using user's name again:
GraphicsWindow.DrawText(0, 140, "5. May I ask where you live, " + Answer[1] + "?")
Program.Delay(20000)
GetAnswer()
'Question 6, using user's answer to question 5:
GraphicsWindow.DrawText(0, 160, "6. You live in " + Answer[5] + "? Cool! Is that near the Canada-US border? (Yes or No)")
Program.Delay(20000)
GetAnswer()
'Using user's answer to q. 6 to make statements
If Answer[6] = "Yes" Or Answer[6] = "yes" Then
GraphicsWindow.DrawText(0, 180, "7. Good choice, " + Answer[1] + "! Do you want a summary of your answers? (Yes or No)")
CanUsBorder = "near the Canada-US border."
Program.Delay(20000)
ElseIf Answer[6] = "No" Or Answer[6] = "no" Then
GraphicsWindow.DrawText(0, 180, "7. Neat-o, " + Answer[1] + "! Do you want a summary of your answers? (Yes or No)")
CanUsBorder = "away from the Canada-US border."
Program.Delay(20000)
EndIf
'Get the answer for question 7 (hidden in the previous If...ElseIf...EndIf statement)(Summary: Yes or No).
GetAnswer()
If Answer[7] = "Yes" or Answer[7] = "yes" Then
GraphicsWindow.DrawText(0, 200, "Your Name is " + Answer[1] + " and you like to " + Answer[3] + ".")
GraphicsWindow.DrawText(0, 220, "It was " + Answer[4] + " and you live in/at " + Answer[5] + ", which is " + CanUsBorder + ".")
Program.Delay(20000)
ElseIf Answer[7] = "No" Or Answer[7] = "no" Then
GraphicsWindow.DrawText(0, 210, "Hmmmm... Well,")
Program.Delay(5000)
EndIf
GraphicsWindow.DrawText(0, 240, "Thank you for using this program! Ending in 10 seconds.")
Program.Delay(10000)
Program.End()

'My GetAnswer subroutine:
Sub GetAnswer
i = i + 1
Answer[i] = Controls.GetTextBoxText(Resp)
Controls.SetTextBoxText(Resp, "")
EndSub

Give any feedback on this code as well as my rewrite of the textwindow version! I am glad to implement any changes or add-ons!

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

• Edited by Monday, November 05, 2012 12:26 AM because I wanted to add a couple of sentences.
•
• Monday, November 05, 2012 4:32 AM
Answerer

Well, here it goes!  HEHE

I still can't see TextWindow.ReadKey() in your re-write. (Neither had removed those redundant Gotos!)  O_o

The right place to implement it is just after where you ask to hit either of the <1>, <2> or <3> keys. Like this:

mood = TextWindow.ReadKey()

But why? Let me re-explain myself:

1. You just need 1 key hit. So there's no need to signal the input is finished by pressing <Enter>. Thus you can relieve the user from that.
2. Even though <1>, <2> or <3> are numbers, you're not interested in their numerical value, but on them being part of any other single key "entity" from keyboard!

Another tidbit:

It's rather pointless on asking the user to type current time, since SB already knows it. Just check the Clock object methods.

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

• Monday, November 05, 2012 4:54 AM
Answerer

It's cool you're getting your feet wet on trying the GraphicsWindow!

But to fully adapt TextWindow.Read/ReadNumber/ReadKey(), you need 1 more piece -> the <Enter> key!

You've already provided the text field box where the user can type in. The missing piece is how he/she can signal to the app it's finished doing that!

That's where you have to provide a button to be clicked for that. Introducing now Controls.AddButton(), Controls.ButtonClicked & Controls.LastClickedButton!

You can also add buttons to clear the field and to exit the app for example. Just search for examples on how to implement it. :P

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

• Monday, November 05, 2012 5:04 AM

Okay, I didn't know that I could use ReadKey() for numbers too. I guess I didn't use it before because I don't see it in Intellisense when I type it.

I just thought it'd be a fun little question to have the user type the time.

*Sigh* Here goes another rewrite.

I have used buttons before, and am adding an "Enter" button to my program. Rewriting is kinda tiring b/c I have to find and change the code in so many spots. Whew!

Anyway, my graphical version WITH button(s) should be available tomorrow. Hopefully.

Same with my rewrite for the text-based program; implementing the ReadKey()

Any more criticism before I log off?

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

• Wednesday, November 07, 2012 8:07 AM

Math Challenge 2

Import Code : SPM491

I am not sure whether the calculated area is accurate or not i did not verified the answer on copy manually...

Thanks

They say working hard is good but i say working smart is best...

• Wednesday, November 07, 2012 12:38 PM

Idea for next months challenges:

Physics: Gravity simulator where you show a one shape in orbit around another by tracking mass and motion of each object

Graphics: Holiday theme, drawing a tree with ornaments and flashing lights.

• Wednesday, November 07, 2012 1:35 PM

Math Challenge 1

sum = 0
For num = 1 To 1000
For i = 1 To Text.GetLength(num)
sum = sum + Text.GetSubText(num,i,1)
EndFor
If sum = 15 Then
TextWindow.WriteLine(num)
EndIf
sum = 0
EndFor

They say working hard is good but i say working smart is best...

• Wednesday, November 07, 2012 7:29 PM
Moderator

Coding Cat -  do you fancy doing the challenges next month? - good to have a little variety.  If you do, then just post the challenge as a discussion at the start of December and we can make it sticky.
• Wednesday, November 07, 2012 7:57 PM
Moderator

Amir, the area looks right to me.

• Thursday, November 08, 2012 4:08 AM

Had a minor setback while creating the graphic program with button, but NaochanON provided me with a source code that worked :)

I manipulated it as to add more questions.

Thanks, NaochanON!

I will have that version ready by midnight (MST) tomorrow.

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

• Friday, November 09, 2012 1:04 AM

Or maybe not.

I have some homework, so I should have the program ready by midnight (MST) tomorrow, not today.

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

• Friday, November 09, 2012 10:13 AM

My second entry for the same challenge... The math challenge II

Import : CKR178

Update : PDC282

(it now respond to window re-sizing event)

Update  : PDC282-0

(it now respond much faster to window resize event)

This program is completely different from the previous one.

Screenshot:

They say working hard is good but i say working smart is best...

• Edited by Friday, November 09, 2012 10:46 AM
• Edited by Friday, November 09, 2012 10:47 AM
• Edited by Saturday, November 10, 2012 6:36 AM
•
• Friday, November 09, 2012 10:25 AM

@Math Man

Your snow downfall simulation is very good i also tried to generate a scenery using the "Perlin Noise" algorithm it was slow like hell but still am working on it, hope i could post my program here before the month end :)

They say working hard is good but i say working smart is best...

• Edited by Friday, November 09, 2012 10:26 AM
•
• Friday, November 09, 2012 4:53 PM

My Scene Generator using Perlin's Algorithm

Import : MXP129

Sreenshot :

I completely redesign it to use two GraphicsWindow.DrawLine() commands only to draw the scene instead of GraphicsWindow.SetPixel() whis was too much slow.

Well, it is still not complete. So, i will add rain snow and wind effects later... :)

They say working hard is good but i say working smart is best...

• Edited by Saturday, November 10, 2012 5:27 AM
•
• Saturday, November 10, 2012 12:11 AM

@ Amir CPS

Thank you. I like your mountain scene. I could probably never do something like that.

I am a 10 year old that loves math, games, and computers. 'Binary is as easy as 1, 10, 11.'

• Saturday, November 10, 2012 5:16 AM
Answerer

@ Amir CPS

Thank you. I like your mountain scene. I could probably never do something like that.

Me neither! But one thing I can do at least -> Make it about 3 times faster!!!

Check it out -> MXP129-1

P.S.: Perhaps I've lost some smoothness on the seed generator.  *_*

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

• Saturday, November 10, 2012 5:29 AM

@ Amir CPS

Thank you. I like your mountain scene. I could probably never do something like that.

Me neither! But one thing I can do at least -> Make it about 3 times faster!!!

Check it out -> MXP129-0

P.S.: Perhaps I've lost some smoothness on the seed generator.  *_*

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

Would you please like explaining a bit how you have done it???

They say working hard is good but i say working smart is best...

• Saturday, November 10, 2012 5:53 AM
Answerer

Hello!

Well, I've used all my tricks! HEHE

But I guess the trim which made the most difference was this one:

For i = 0 to 799
range[i]=0
EndFor

A simple -> range = "" quickly erases the whole array, which is nothing more than a big string anyways!

P.S.: I've adjusted some parameters, so the program can work on different resolutions as well!

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

• Saturday, November 10, 2012 7:02 AM

Graphical Challenge

Tornade and snow    CCD321

• Sunday, November 11, 2012 2:38 AM

Here is my graphical version with button: PZK052

Thanks to NaochanON, it works like a dream. And now I understand the whole "parallel instance" thing and how to get around it!

Anything else I want to add?

Oh yeah, for question 9 to work, you have to enter one of the listed languages. "None" isn't hooked up quite yet, so I am calling this version "Version 1.5: Programmer's Edition." You can write "None," but 9 will execute and make no sense. "You program in None, how difficult is it for you?" It works, but I am adding in the if statement for that so it can be a "Version 1.5"

Happy programming, everyone!

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

• Edited by Sunday, November 11, 2012 2:40 AM
•
• Sunday, November 11, 2012 3:30 AM

All of my variations of Text Challenge 2, so there's [hopefully] no confusion:

V 1.5: Programmer's Edition (Programmer's Question Graphic - Button)    - SLN246
V 1.5:                                 (All Users Graphic - Button)                           - QBD569
V 1.25:                                    (Graphic No Button)                                 - PNK298
V 1.0:                                                 (Text)                                            - QDH330

For the graphic versions: Version # (bottom right corner) doesn't show in SilverLight (Browser).

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

• Edited by Sunday, November 11, 2012 3:32 AM adding info
•
• Sunday, November 11, 2012 12:16 PM
Moderator

Joman,

The Text Challenge answers work really well - feels like a conversation.

• Sunday, November 11, 2012 5:02 PM

Thank you, LitDev!

That is precisely what I was going for :P

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

• Monday, November 12, 2012 8:08 PM
Answerer

Future Math challenge idea: Write a program to calculate a random number without using Math.GetRandomNumber

What do you think?

One thing that is impossible is impossible no matter if it is proven so first.

• Monday, November 12, 2012 8:30 PM

Zock77,

I think that is a great idea, I would love to try it!

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

• Wednesday, November 14, 2012 8:30 PM

Wow I really like the scene generator of Amir's, Math Man's snow is really cool too, lots of cool programs being written - the tornado is really interesting.
• Tuesday, November 27, 2012 12:05 PM
Answerer

This is my Graphical Challenge: ZPJ862.

Nonki Takahashi

• Tuesday, November 27, 2012 1:22 PM
Answerer

This is my another Graphics Challenge: SMB798.

Nonki Takahashi

• Tuesday, November 27, 2012 5:16 PM
Answerer

This is my third Graphics Challenge: NKC523.

Local environment will be recommended.

Nonki Takahashi

• Tuesday, December 04, 2012 1:38 AM
Answerer

My idea for a future graphical challenge: Draw Christmas tree.

Nonki Takahashi

• Tuesday, December 04, 2012 2:52 PM
Answerer

My idea for future math challenge: Calculate happy numbers below 1000.

Nonki Takahashi

• Sunday, December 09, 2012 6:44 AM

I didn't see a full solution for the events challenge so here's mine (albiet a bit late...)

GraphicsWindow.Hide()
GraphicsWindow.Title = "Small Basic Keyboard Challenge November 2012"
DEBUG="False" ' setting this to "True" will show the history of keys pressed

' Making a pretty keyboard from scratch was too much work so thanks go to both the original creator and current host of this image
urlImage = "http://www.informatique.math.jussieu.fr/public/documentation/fr/annexes/chevaleret/hosts/gamma.math.jussieu.fr/kbd/img/qwerty.png"
imgKeyboard = ImageList.LoadImage(urlImage)
imgWidth = ImageList.GetWidthOfImage(imgKeyboard)
imgHeight = ImageList.GetHeightOfImage(imgKeyboard)

If DEBUG Then
GraphicsWindow.Width = imgWidth+120
Else
GraphicsWindow.Width = imgWidth
EndIf
GraphicsWindow.Height = imgHeight
GraphicsWindow.DrawImage(imgKeyboard,0,0)

GraphicsWindow.FontName = "Courier New"
GraphicsWindow.BrushColor = "Black"

If DEBUG="True" Then
GraphicsWindow.DrawText(imgWidth+5,5,"Key History:")
tbHistory = Controls.AddMultiLineTextBox(imgWidth+5,20)
Controls.SetSize(tbHistory,110,imgHeight-25)
EndIf

' Overlay color is half-transparent red
GraphicsWindow.PenColor = "#77FF0000"
GraphicsWindow.BrushColor = "#77FF0000"

' Define event handlers
GraphicsWindow.KeyDown = onKeyDown
GraphicsWindow.KeyUp = onKeyUp

DefineKeyOverlays()
GraphicsWindow.Show()

' These keys have width > 32 pixels
For i = 1 to 13 ' Array.GetItemCount(keyName)
key[wkeyName[i]] = Shapes.AddRectangle(wkeyWidth[i],32)
Shapes.Move(key[wkeyName[i]],wkeyX[i],wkeyY[i])
Shapes.HideShape(key[wkeyName[i]])
EndFor

' These keys are all 32 x 32 pixels
For r = 1 To 6
For i = 1 to Array.GetItemCount(keyName[r])
key[keyName[r][i]] = Shapes.AddRectangle(32,32)
Shapes.Move(key[keyName[r][i]],keyX[r][i],rowY[r])
Shapes.HideShape(key[keyName[r][i]])
EndFor
EndFor
'----------------------------------------
Sub onKeyDown
lastKey = GraphicsWindow.LastKey
If DEBUG = "True" Then
Controls.SetTextBoxText(tbHistory,Text.Append(lastKey+Text.GetCharacter(10),Controls.GetTextBoxText(tbHistory)))
EndIf
If Text.StartsWith(lastKey,"Return") Then
Shapes.ShowShape(key["Return1"])
Shapes.ShowShape(key["Return2"])
Else
Shapes.ShowShape(key[lastKey])
EndIf
EndSub
'----------------------------------------
Sub onKeyUp
If Text.StartsWith(GraphicsWindow.LastKey,"Return") Then
Shapes.HideShape(key["Return1"])
Shapes.HideShape(key["Return2"])
Else
Shapes.HideShape(key[GraphicsWindow.LastKey])
EndIf
EndSub
'----------------------------------------
Sub DefineKeyOverlays
' special keys Return (two keys) and Add (height = 71)
key["Return1"] = Shapes.AddRectangle(77,32)
Shapes.Move(key["Return1"],498,163)
Shapes.HideShape(key["Return1"])

key["Return2"] = Shapes.AddRectangle(32,71)
Shapes.Move(key["Return2"],851,203)
Shapes.HideShape(key["Return2"])

key["Add"] = Shapes.AddRectangle(32,71)
Shapes.Move(key["Add"],851,124)
Shapes.HideShape(key["Add"])

' Define overlay names and offsets for wide keys
wkeyName = "1=Back;2=Tab;3=Oem5;4=Capital;5=LeftShift;6=RightShift;7=LeftCtrl;8=LWin;9=Space;10=RWin;11=Apps;12=RightCtrl;13=NumPad0"
wkeyWidth = "1=67;2=50;3=49;4=60;5=87;6=87;7=51;8=43;9=203;10=43;11=44;12=51;13=71"
wkeyX = "1=508;2=13;3=526;4=13;5=13;6=488;7=13;8=70;9=168;10=426;11=475;12=524;13=737"
wkeyY = "1=84;2=124;3=124;4=163;5=202;6=202;7=242;8=242;9=242;10=242;11=242;12=242;13=242"

' Y-Offsets for key rows below
rowY = "1=11;2=84;3=124;4=163;5=202;6=242"

' Define overlay names and offsets for keys that are 32 x 32 pixels
keyName[1] = "1=Escape;2=F1;3=F2;4=F3;5=F4;6=F5;7=F6;8=F7;9=F8;10=F9;11=F10;12=F11;13=F12;14=Scroll;15=Pause"
keyX[1] = "1=13;2=79;3=116;4=154;5=193;6=254;7=292;8=330;9=368;10=428;11=467;12=505;13=543;14=640;15=678"
keyName[2] = "1=Oem3;2=D1;3=D2;4=D3;5=D4;6=D5;7=D6;8=D7;9=D8;10=D9;11=D0;12=OemMinus;13=OemPlus;14=Insert;15=Home;16=PageUp;17=NumLock;18=Divide;19=Multiply;20=Subtract"
keyX[2] = "1=13;2=51;3=89;4=127;5=165;6=203;7=241;8=279;9=317;10=355;11=393;12=432;13=470;14=602;15=640;16=678;17=737;18=775;19=813;20=851"
keyName[3] = "1=Q;2=W;3=E;4=R;5=T;6=Y;7=U;8=I;9=O;10=P;11=OemOpenBrackets;12=Oem6;13=Delete;14=End;15=Next;16=NumPad7;17=NumPad8;18=NumPad9"
keyX[3] =  "1=69;2=107;3=145;4=183;5=221;6=259;7=297;8=335;9=373;10=411;11=449;12=487;13=602;14=640;15=678;16=737;17=775;18=813"
keyName[4] = "1=A;2=S;3=D;4=F;5=G;6=H;7=J;8=K;9=L;10=Oem1;11=OemQuotes;12=NumPad4;13=NumPad5;14=NumPad6"
keyX[4] =  "1=79;2=117;3=155;4=193;5=232;6=270;7=308;8=346;9=384;10=422;11=460;12=737;13=775;14=813"
keyName[5] = "1=Z;2=X;3=C;4=V;5=B;6=N;7=M;8=OemComma;9=OemPeriod;10=OemQuestion;11=Up;12=NumPad1;13=NumPad2;14=NumPad3"
keyX[5] =  "1=105;2=144;3=182;4=221;5=259;6=297;7=335;8=373;9=412;10=450;11=640;12=737;13=775;14=813"
keyName[6] = "1=Left;2=Down;3=Right;4=Decimal"
keyX[6] =  "1=602;2=640;3=678;4=813"
EndSub