Asked by:
Challenge of the Month  April 2018
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 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 thread that will remain 'sticky' for the month. The only rule is that your solution must use standard Small Basic 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.
We may extend these challenges over into a second month if solutions and questions are still coming in.Graphics Challenge
Draw a picture of a mountain scene, maybe some clouds, trees, snow or a lake in the view.
Maths Challenge
Write a program to calculate the numbers less than 1000 that are divisible, by exactly 3 different prime numbers. How many can you get.
e.g. 2*3*5 = 30, 7*11*5=385
Text Challenge
Write a TextWindow program to input a sentence and then output it with one or more of the following:
 every vowel colored red, or
 the first and last letter of each word colored blue
Game Challenge
Write a simple whackamole type game.
Do you have an idea for a future challenge? Please post it here!
 every vowel colored red, or
All replies

primes count:
pp="2;3;5;7;11;13;17;19;23;29;31;37;41;43;47;53;59;61;67;71;73;79;83;89;97;101;103;107;109;113;127;131;137;139;149;151;157;163" pr=LDText.Split(pp ";") args=0 For t=30 To 999 v=LDCall.Function("ann" t) If Array.GetItemCount(v)=3 Then cc=cc+1 TextWindow.WriteLine(t+": "+v[1]+"; "+v[2]+"; "+v[3]) w[v[1]]=w[v[1]]+1 EndIf EndFor TextWindow.WriteLine("total listed nums: "+cc) TextWindow.WriteLine("2: "+w[2]) TextWindow.WriteLine("3: "+w[3]) TextWindow.WriteLine("5: "+w[5]) Sub ann 'lists all dividable primes less than req. number' aa=args[1] oo="" For q=1 To 38 qq=pr[q] If qq<aa and aa/qq=math.floor(aa/qq) Then oo=oo+pr[q]+";" EndIf EndFor return=LDText.Split(oo ";") EndSub
at end it lists groups count of 2,3,5 primes 



Here is my prime solution. I implemented a Prime Sieve at the top, so this should work with any top number... allowing for the time needed for the calculation. There are lots of ways that this could be made faster. I would be interested in seeing any improvements that others make.
'Sieve of eratosthenes to find all of the primes from 1 to 1000 top = 1000 'we can stop anywhere we wish. For i = 1 To top 'Mark all numbers as prime primes[i] = "True" EndFor For i =2 To top If primes[i] = "True" Then 'if the current number is prime For j = i * 2 To top Step i 'make all multiples of that number as not prime primes[j] = "False" EndFor EndIf EndFor 'Display all of the primes cnt = 0 For i = 1 To top If primes[i] = "True" Then TextWindow.Write(i + ", ") cnt = cnt + 1 primeList[cnt] = i 'make a list of just the primes to save time in the next step EndIf EndFor TextWindow.WriteLine("") TextWindow.WriteLine("") 'Now that we have the primes, check all the numbers from 1 to 1000 that qualify max = 0 maxNum = 0 lineCount = 0 For i = 1 To top 'For each number primeCount = 0 For j = 2 To cnt 'Check all primes If Math.Remainder(i,primeList[j]) = 0 Then 'If it divides evenly primeCount = primeCount + 1 'keep a count EndIf EndFor If primeCount = 3 Then 'If three work, print out this number TextWindow.Write(i + ", ") lineCount = lineCount + 1 If Math.Remainder(lineCount,15) = 0 then TextWindow.WriteLine("") endif EndIf If (primeCount > max) Then max = primeCount 'find the largest count just for fun maxNum = i EndIf EndFor TextWindow.WriteLine("") TextWindow.WriteLine("") TextWindow.WriteLine("Number with max count of primes: " + maxNum + " with " + max + " prime divisors")

Here's another sieve ID: SQF020, (but did'nt compare right now, too late). See the 'GetPrimes' Sub.
PS: After coloring you can click the right column of primes. Edited by Pappa LapubEditor Wednesday, April 4, 2018 10:07 PM

I get a total of 135 like nonki.
'Prime challenge April 2018
maxValue = 1000
GetPrimes()
FindResult()
Sub GetPrimes
primes = ""
numPrimes = 1
primes[numPrimes] = 2
try = 3
While (try <= maxValue /2)
For i = 1 To numPrimes
If (Math.Remainder(try,primes[i]) = 0) Then
Goto Next
EndIf
EndFor
numPrimes = numPrimes+1
primes[numPrimes] = try
Next:
try = try+2
EndWhile
EndSub
Sub FindResult
count = 0
For i = 1 To numPrimes
For j = i+1 To numPrimes
For k = j+1 To numPrimes
product = primes[i]*primes[j]*primes[k]
If (product < maxValue) Then
count = count+1
TextWindow.WriteLine("["+count+"] "+primes[i]+"*"+primes[j]+"*"+primes[k]+"="+product)
Else
k = numPrimes 'End loop here to save time
EndIf
EndFor
EndFor
EndFor
EndSub 


I do not know very well English, so I translate it through an interpreter. This program is not as fast as the moderator program, but it's also quite good :)
max_number = 1000 numbers = 0 For i = 1 To max_number number = i d = 2 n = 0 While number > 1 If Math.Remainder(number, d) = 0 Then number = number / d n = n + 1 a[n] = d Else d = d + 1 Endif EndWhile If (n = 3) And (a[1] <> a[2]) And (a[2] <> a[3]) And (a[1] <> a[3]) Then TextWindow.WriteLine("Результат: " + i + " " + a[1] + " " + a[2] + " " + a[3]) numbers = numbers + 1 EndIf EndFor TextWindow.WriteLine(numbers)
 Edited by Quttar Tuesday, April 10, 2018 4:01 PM

sine flower:
GraphicsWindow.BackgroundColor="teal" For y=50 To 200 Step 10 ss=0 i=1 For x=0 To 360 Step .5 cc=LDMath.Convert2Cartesian(300 300 ldmath.sin(x*10)*10+y x) ss[i][1]=cc[1] ss[i][2]=cc[2] i=i+1 EndFor pp=LDShapes.AddPolygon(ss) LDShapes.PenWidth(pp 0) LDShapes.BrushColour(pp LDColours.HSLtoRGB(j*15 1 .6)) LDShapes.ZIndex(pp, j) LDEffect.DropShadow(pp "") j=j+1 EndFor




hypnosis 2:HVD856
look at the centre of rotating flower for 30sec. then look elsewhere...
also at the centre appears a different blue circle. if u look at this pic after looking at anim. it appears rotating backwards)) Edited by Tryhest Monday, April 16, 2018 3:36 AM


