none
Challenge of the Month - April 2018 RRS feed

  • 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 whack-a-mole type game.

    What Can I Expect at a Healing Service? « revnettie

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

    Sunday, April 1, 2018 1:53 PM
    Moderator

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
    Monday, April 2, 2018 1:10 AM
  • This is my solution for the maths challenge: DFQ430-0.

    Nonki Takahashi

    Monday, April 2, 2018 6:38 AM
    Moderator
  • a little bug in try's prime count ?

    2*2*3*83=996

    Monday, April 2, 2018 9:53 AM
  • VMH447 Orignal by nonki with apples by AddImage upgraded by mahreen miangul with apples by AddText now draw the apples yourself by coding                                                                                   mahreen miangul
    Monday, April 2, 2018 11:11 AM
  • 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")
    

    Wednesday, April 4, 2018 8:59 PM
    Answerer
  • 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.
    Wednesday, April 4, 2018 10:06 PM
    Answerer
  • 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
    Wednesday, April 4, 2018 10:33 PM
    Moderator
  • found error, now it gets 135 as nonki's!

    Friday, April 6, 2018 3:45 AM
  • pulsating outline dots:

    HHN534


    • Edited by Tryhest Tuesday, April 10, 2018 10:25 AM
    Tuesday, April 10, 2018 10:08 AM
  • 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
    Tuesday, April 10, 2018 3:55 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

    Saturday, April 14, 2018 8:10 PM
  • Animate Rotate Opacity Zoom ID CLT244                                                          mahreen miangul
                                                                      For your Eyes only
    Sunday, April 15, 2018 3:59 AM
  • Sine Flower pulsating: BZF166
    Monday, April 16, 2018 2:44 AM
  • hypnotic rotating flower: ZQT921

    Monday, April 16, 2018 3:07 AM
  • 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
    Monday, April 16, 2018 3:31 AM
  • turtle-drawn nonki's face following mouse movements:

    LZN533

    Friday, April 20, 2018 6:10 AM
  • nonki v2.0

    PSS478

    • Edited by Tryhest Friday, April 20, 2018 10:30 AM
    Friday, April 20, 2018 10:29 AM
  •  to nonki with love KLC026                                                                                            mahreen miangul
    Thursday, April 26, 2018 4:53 AM