none
Challenge of the Month - September 2015 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.

    Also post feedback on the kind of challenges that you want to see more of in the future.

    Text Challenge

    • "ecnetnes a ni sretcarahc eht lla esrever ot margorp a etirW"
    • "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"
    • HINT - use the stack object


    Graphics Challenge

    • Draw a picture of a clown



    Game Challenge

    • Make a roulette gambling wheel game


    Physics Challenge

    • Animate a physically realistic pendulum
    • Try to get its period correct for the scale length of the swing
    • See here or  many other sites on this topic

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

    Tuesday, September 1, 2015 6:50 PM
    Moderator

All replies

  • Here's my solution for Physics Challenge.

    http://smallbasic.com/program/?ZSP744-0

    Wednesday, September 2, 2015 6:15 AM
    Moderator
  • Here's my solution for Physics Challenge.

    http://smallbasic.com/program/?ZSP744-0

    Nice job.
    Wednesday, September 2, 2015 7:50 PM
    Moderator
  • Thanks LD

    Here's the text book I used for pendulum: scroll down a bit in Ch 3:  http://natureofcode.com/book/chapter-3-oscillation/

    Best resource I've seen for ages. And what befitting name for this book, The Nature of Code.

    Wednesday, September 2, 2015 11:35 PM
    Moderator
  • Thanks LD

    Here's the text book I used for pendulum: scroll down a bit in Ch 3:  http://natureofcode.com/book/chapter-3-oscillation/

    Best resource I've seen for ages. And what befitting name for this book, The Nature of Code.


    That's cool. Thanks Jibba Jabba!

    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Wednesday, September 16, 2015 6:20 AM
    Owner
  • Here's my solution for Physics Challenge.

    http://smallbasic.com/program/?ZSP744-0

    Blogged about it here:

    Pendulum Sim - Small Basic Featured Program


    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Friday, September 18, 2015 9:33 PM
    Owner
  • Here's my browser solution for Clown drawing: Click me

    I scanned the image, parsed the pixel XY's into Line draws then embedded the data.

    Great for simple solid color images. Line draw format very slow for non-solid parts, in this case the black outline.

    So I trimmed the black down so it would be small enough for browser and put it in a worker thread.

    Is it possible to embed browser programs into forum posts?

    Saturday, September 19, 2015 11:30 PM
    Moderator
  • Is it possible to embed browser programs into forum posts?

    Not as far as I can see.

    But your method is very ingeneous.


    Sunday, September 20, 2015 5:15 PM
    Moderator
  • This is my first version for the game challenge (roulette): LNM164-4.

    Screen shot of a program Small Roulette 0.4a

    The roulette can move with [Start] button.  But can't bet yet.


    Nonki Takahashi

    Tuesday, September 22, 2015 7:42 AM
    Moderator
  • Thanks litdev.

    Wednesday, September 23, 2015 9:44 PM
    Moderator
  • Next month's challenges will be a bit late since I'm away for a couple weeks.
    Friday, September 25, 2015 7:31 PM
    Moderator
  • Next month's challenges will be a bit late since I'm away for a couple weeks.
    Okay. Thanks!

    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Monday, September 28, 2015 9:09 PM
    Owner
  • Here's my browser solution for Clown drawing: Click me

    I scanned the image, parsed the pixel XY's into Line draws then embedded the data.

    Great for simple solid color images. Line draw format very slow for non-solid parts, in this case the black outline.

    So I trimmed the black down so it would be small enough for browser and put it in a worker thread.

    Is it possible to embed browser programs into forum posts?

    Holy cow! That's amazing! I think LitDev was looking for an original clown, but this is awesome!

    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Monday, September 28, 2015 9:10 PM
    Owner
  • This is my first version for the game challenge (roulette): LNM164-4.

    Screen shot of a program Small Roulette 0.4a

    The roulette can move with [Start] button.  But can't bet yet.


    Nonki Takahashi

    Great start!

    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Monday, September 28, 2015 9:11 PM
    Owner
  • As there is no sulution yet for the text challenge, I will give here an answer for "newbees" ;-))

    code="ecnetnes a ni sretcarahc eht lla esrever ot margorp a etirW"
    TextWindow.WriteLine(code)
    Len=Text.GetLength(code)
    For i=1 To Len
      Stack.PushValue("T",Text.GetSubText(code,i,1))
    EndFor
    For i=1 To Len
      TextWindow.Write(Stack.PopValue("T"))
    EndFor
    TextWindow.WriteLine("")
    TextWindow.WriteLine("")
    
    code="yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"
    code=code+" "
    TextWindow.WriteLine(code)
    Len=Text.GetLength(code)
    For i=1 To Len
      char=Text.GetSubText(code,i,1)
      If char<>" " Then  
        Stack.PushValue("T",char)
      Else
        cnt=Stack.GetCount("T")
        For j=1 To cnt
          TextWindow.Write(Stack.PopValue("T"))
        EndFor
        TextWindow.Write(" ")
      EndIf
    EndFor
    TextWindow.WriteLine("")
    TextWindow.WriteLine("")
    


    Jan [ WhTurner ] The Netherlands

    Tuesday, September 29, 2015 10:58 AM
    Answerer
  • I like Nonki's idea of simplifying the game mechanics, wish I had thought of doing that.  Although I did take some liberties with the wheel aesthetics.

    Anyway, here's my entry.  It's reasonably finished feature-wise: You can bet and win, but it only supports betting one chip at a time and only simple bets...no multibets.  Can't promise it's bug free though, so let me know if you run into something.

    The game can be imported as: KGX852

    It doesn't work properly in the browser.

    Wednesday, September 30, 2015 12:46 PM
  • The game can be imported as: KGX852

    OzJerry this program ID isn't importing for me.
    Wednesday, September 30, 2015 1:30 PM
    Moderator
  • The game can be imported as: KGX852

    OzJerry this program ID isn't importing for me.

    That's strange as I can re-import it OK with that code.  Here's the link to the browser based version:

    http://smallbasic.com/program/?KGX852

    You could try cut and pasting the code from there.  It's very late here now, so I'll try it on another machine on a different network in the morning.

    Update: I managed to import it onto another machine on a separate network.  Just in case, I re-published it again: KGX852-0

    • Edited by OzJerry Thursday, October 1, 2015 12:55 PM Updated
    Wednesday, September 30, 2015 1:41 PM
  • I managed to import it on to another machine on a different network, so the code seems OK....not sure what is going on Jibba Jabba.  

    I re-published it again as KGX852-0

    Thursday, October 1, 2015 12:57 PM
  • Hey OzJerry

    Now I can import the original.

    Had no luck on several attempts yesterday but could import others.

    A bit odd. Thought I should let know.

    Nice program.

    Thursday, October 1, 2015 1:42 PM
    Moderator
  • Maybe try this?

    <object data="data:application/x-silverlight-2," height="480" id="sbapp" type="application/x-silverlight-2" width="640"> <param name="source" value="http://smallbasic.com/program/ClientBin/SBWeb.xap" /><param name="onError" value="onSilverlightError" /><param name="background" value="white" /><param name="minRuntimeVersion" value="3.0.40624.0" /><param name="autoUpgrade" value="true" /><param name="initParams" value="programId=PMT149" /></object>
    Thursday, October 1, 2015 7:19 PM
    Answerer
  • Hmm. It seems to work before you post it, and then it stops working.

    It is written: "'As surely as I live,' says the Lord, 'every knee will bow before me; every tongue will acknowledge God.'" Romans 14:11

    Thursday, October 1, 2015 7:35 PM
    Answerer
  • JDB017

    I still dont have the hang of stack so I usually just do work arounds and spend hours making things difficult for myself.


    Alex Warrington - alex.warrington@live.co.uk


    Sunday, October 11, 2015 12:12 AM
  • Featured Jibba Jabba's clown: http://blogs.msdn.com/b/smallbasic/archive/2015/10/10/small-basic-featured-program-a-crazy-way-to-draw-a-clown.aspx

    Ed Price, Azure & Power BI Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Sunday, October 11, 2015 9:21 AM
    Owner
  • that is actually quite ingenious. i was working on a website dictionary algerithm to get the first sentence of a wikipedia page. i actually got the whole html of the website, found teh first instance of "<p>" and got all the letters in between. 

    for this challenge, couldnt u just get the last letter of the sentence and rewrite it in reverse by setting each character as an array then reprinting it? 

    Wednesday, October 14, 2015 1:49 AM
  • Heres the program to reverse the sentence-

    CGM245 

    Its literally 14 -15 lines of code

    Wednesday, October 14, 2015 2:05 AM
  • Not  Text Challenge    (Graphicswindow version//  shapes.animate)

    "ecnetnes a ni sretcarahc eht lla esrever ot margorp a etirW"

    size=12
    letter="ecnetnes a ni sretcarahc eht lla esrever ot margorp a etirW"
    Len=Text.GetLength(letter)
    GraphicsWindow.Width=size*Len+30
    GraphicsWindow.FontSize=size
    For i=1 To Len
      Stack.PushValue("txt",Text.GetSubText(letter,i,1))
    EndFor
    For i=1 To Len
      shp[i]=Shapes.AddText(Stack.PopValue("txt"))
      Shapes.Animate(shp[i],10+(i-1)*12,100,1000)
    EndFor

    Wednesday, October 14, 2015 4:15 AM
    Answerer
  • nice job, a bit easier than mine but i didnt use stacks. i used arrays. But nice job with the aimation.
    Wednesday, October 14, 2015 2:19 PM
  • Hi

    Dont forget we can use the For loop in reverse mode with the "Step" keyword and the "-1" value.

    code="ecnetnes a ni sretcarahc eht lla esrever ot margorp a etirW"
    TextWindow.WriteLine(code)
    Len=Text.GetLength(code)
    For i=Len To 1 Step -1
      TextWindow.Write(Text.GetSubText(code,i,1))
    EndFor
    TextWindow.WriteLine("")
    

    Regards,


    Yan Grenier

    Merci de bien vouloir "Marquer comme réponse", les réponses qui ont répondues à votre question, et de noter les réponses que vous avez trouvé utiles.

    Wednesday, October 14, 2015 2:26 PM
    Answerer
  • yeah. but that wont be the case with the second challenge.
    Wednesday, October 14, 2015 4:06 PM
  • Yes, I would just recall this option in some case :)

    Regards,


    Yan Grenier

    Merci de bien vouloir "Marquer comme réponse", les réponses qui ont répondues à votre question, et de noter les réponses que vous avez trouvé utiles.

    Wednesday, October 14, 2015 5:58 PM
    Answerer
  • I finished the challenge of the month. for reversing each letter of the word. Import is PLJ957.
    Text1 = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow " ' slight modification i added a space at the end. is that legal?
    TextWindow.WriteLine(Text1)
    find = " "
    j = 0 ' word count
    For i = 0 To Text.GetLength(text1) ' gets every character and puts it in a array of words
      letter = Text.GetSubText(text1, i, 1)
      If letter = find Then
        j = j + 1   
      Else 
      EndIf 
    endfor
    TextWindow.WriteLine("starting the word selection")
    TextWindow.Pause()
    pos = 1
    total = Text.GetLength(text1)
    k = 0
    For i = 1 To j Step 1 
      For l = 0 To total Step 1 'this will not go completly. there will be a skip
        word[i][l] = Text.GetSubText(Text1, pos, 1) 'gets the letter
        If word[i][l] = find Then ' if the word = <space>
          pos = pos + 1
    
          Goto skip 
        Else 
          pos = pos + 1  
        EndIf
      EndFor
      TextWindow.Pause()
      skip:
    endfor
    TextWindow.WriteLine("writing words")
    TextWindow.Pause()
    For i = 1 To j Step 1
      For l = total To 0 Step -1 ' will write the word in letter reversal
        If word[i][l] = find Then 'wont write the character 
      else
            TextWindow.Write(word[i][l])
            EndIf
    EndFor
    TextWindow.Write(" ") ' once wor dis written adds a space for teh next word
    endfor

    Wednesday, October 14, 2015 6:23 PM
  • Hi, since i started really really late, i was not able to start until yesterday, but i was able to complete it. plz look at the lst thread posted by me(jetfire3201) i did it not use stack. see if you can do it with out stacks. that would be a great challenge. making things simple, not simpler.
    • Edited by JetFire3201 Wednesday, October 14, 2015 7:27 PM wrong wording
    Wednesday, October 14, 2015 7:26 PM
  • And there's a simple recursive solution to reversing stuff:

    string = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"
    
    Reverse()
    
    Sub Reverse
      TextWindow.Write(Text.GetSubText(string, Text.GetLength(string) - i, 1))
      i = i + 1
      While i < Text.GetLength(string)
        Reverse()
      EndWhile
    EndSub

     
    Wednesday, October 14, 2015 7:35 PM
    Moderator
  • an idea might be maybe to get an image of a place and make a distance calculation based on scale? like how you can use google maps and get the distance of a place to another place. 
    Wednesday, October 14, 2015 7:36 PM
  • And here's another way to do it.

    input = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"
    output = ""
    
    While (Text.GetLength(input) > 0)
      char = Text.GetSubText(input,1,1)
      input = Text.GetSubTextToEnd(input,2)
      If (char = " ") Then 'Or anyting that delimiates a word
        Reverse()
        output = Text.Append(output,char)
      Else
        Stack.PushValue("word",char)
      EndIf
    EndWhile
    Reverse() 'Any final non-terminated word
    TextWindow.WriteLine(output)
    
    Sub Reverse 'Unwind stack to reverse a word
      While (Stack.GetCount("word") > 0)
        output = Text.Append(output,Stack.PopValue("word"))
      EndWhile
    EndSub

    Wednesday, October 14, 2015 8:05 PM
    Moderator
  • wow. complicated. For me that seems really complicated. Would you say mines would be somewhat easier to follow for "newbees" if they do not understand stacks.
    Wednesday, October 14, 2015 8:14 PM
  • About reversing strings...

    If shapes.Zoom was capable of having negative values then a graphical solution could be:

    GraphicsWindow.Show()
    
    string = Shapes.AddImage(Program.Directory + "\string.png")
    
    For i = 1 To -1 Step -0.1  
      Shapes.Zoom(string, i, 1) 
    EndFor

    Wednesday, October 14, 2015 8:15 PM
    Moderator
  • this program only reversed the words but didnt reverse the sentence so it can be read grammatically correctly.
    Wednesday, October 14, 2015 8:16 PM
  • wow. complicated. For me that seems really complicated. Would you say mines would be somewhat easier to follow for "newbees" if they do not understand stacks.

    Perhaps this makes it a bit easier to follow - part of the point of the challenge is to learn the stack and maybe use While loops in place of For loops when appropriate.

    input = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"
    output = ""
    
    For i = 1 To Text.GetLength(input)
      char = Text.GetSubText(input,i,1) 'Next character
      If (char = " ") Then 'Or anything that delimiates a word
        Reverse() 'Reverse the last stored word in stack
        output = Text.Append(output,char) 'Add the deliminator character
      Else
        Stack.PushValue("word",char) 'Add character of a word to stack
      EndIf
    EndFor
    Reverse() 'Any final non-terminated word
    TextWindow.WriteLine(output)
    
    Sub Reverse 'Unwind stack to reverse a word
      While (Stack.GetCount("word") > 0)
        output = Text.Append(output,Stack.PopValue("word"))
      EndWhile
    EndSub

    Wednesday, October 14, 2015 8:29 PM
    Moderator
  • And here's another way to do it.

    input = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"
    output = ""
    
    While (Text.GetLength(input) > 0)
      char = Text.GetSubText(input,1,1)
      input = Text.GetSubTextToEnd(input,2)
      If (char = " ") Then 'Or anyting that delimiates a word
        Reverse()
        output = Text.Append(output,char)
      Else
        Stack.PushValue("word",char)
      EndIf
    EndWhile
    Reverse() 'Any final non-terminated word
    TextWindow.WriteLine(output)
    
    Sub Reverse 'Unwind stack to reverse a word
      While (Stack.GetCount("word") > 0)
        output = Text.Append(output,Stack.PopValue("word"))
      EndWhile
    EndSub
    what if you just wanted to get 1 word? then what? i dont really see a point in this porgram where you can write that. I might be wrong. you could set a limit. Could you plz show me how you would do that(i am at a total lose on how to use stacks. I'd rather use arrays)


    Wednesday, October 14, 2015 8:31 PM
  • Ahhhh. Makes sense now. comments are life savers. I know one guy whos a genius in python... but never writes any comments and he excpects you to know the point of each line. I know that this was to teach stacks, but what if you found it easier to make an 2d array where the first [] was the word and teh second[] was the number of letters in each word? would you still have accomplished the total goal of teh challenge, learning and expanding your intellect on the process of smallbasic api?
    Wednesday, October 14, 2015 8:39 PM
  • I'm not sure what you mean by 'just wanted to get 1 word?'

    Using arrays is fine, but learning to use a stack (and other collection types beyond Small Basic) can be useful.

    Just like using GoTo can seem intuitive, but it can lead to problems later so best to learn how to do without it as a training.

    Wednesday, October 14, 2015 8:40 PM
    Moderator
  • Well... As I originally posted but tidied up a little.

    sent = "ecnetnes a ni sretcarahc eht lla esrever ot margorp a etirW"
    len = Text.GetLength(sent)
    total = ""
    For i = 0 to len
      char = Text.GetSubText(sent,len-i,1)
      total = total+char
    EndFor
    I have not used the "Sent -1" function before but it seems interesting.


    Alex Warrington - alex.warrington@live.co.uk

    Wednesday, October 14, 2015 8:42 PM
  • if you run my code, you can see that its in 2 for loops for print the whole sentence, you can change the value of (ithink its j) j to a number less that 11 and it will only print out the first word to the word you want to end with. or you can start at any word and write only that word. thats why i used arrays. so i can be specific in any printing i wished for. i also used goto to "skip" when i encountered a space.
    Wednesday, October 14, 2015 8:43 PM
  • I did it in even fewer lines of code than what i started with(12) now i did it in half, but i did take out the total = "" value. in my case i found there was no need to have that since all i was doing was printing it in reverse

    text1 = "ecnetnes a ni sretcarahc eht lla esrever ot margorp a etirW"
    pos = Text.GetLength(text1)
    For i = pos To 0 step -1
      letter[i] = Text.GetSubText(text1, i,1)
      TextWindow.Write(letter[i])
    endfor 


    • Edited by JetFire3201 Wednesday, October 14, 2015 8:51 PM
    Wednesday, October 14, 2015 8:49 PM
  • I see, so we want an array of reversed words, perhaps like this then is how I might do that.

    input = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"
    words = ""
    GetWords() 'Get an array of words with characters reversed in each word
    first = 1 'The fist word to start with in output
    last = numWord 'The last word to end on
    WriteResult() 'Write out the result
    
    Sub GetWords
      For i = 1 To Text.GetLength(input)
        char = Text.GetSubText(input,i,1)
        If (char = " ") Then 'Or anyting that delimiates a word
          Reverse()
        Else
          Stack.PushValue("word",char)
        EndIf
      EndFor
      Reverse() 'Any final non-terminated word
    EndSub
    
    Sub Reverse 'Unwind stack to reverse a word
      numWord = Array.GetItemCount(words)+1 'Next word
      While (Stack.GetCount("word") > 0)
        words[numWord] = Text.Append(words[numWord],Stack.PopValue("word"))
      EndWhile
    EndSub
    
    Sub WriteResult
      For i = first To last
        TextWindow.Write(words[i])
        If (i < last) Then 'Add a space between output words (apart from the last)
          TextWindow.Write(" ")
        EndIf
      EndFor
      TextWindow.WriteLine(" ") 'New line
    EndSub

    Wednesday, October 14, 2015 8:59 PM
    Moderator
  • right. thats another way to do it if you did a combination of arrays and stacks. for numWord = array, could you just have done numword = numberword+1?
    Wednesday, October 14, 2015 9:07 PM
  • Yes, the reason I did it this way is because I didn't initialise numWord to 0 at the start.  In many languages you have to initialise everything - not in SB, sometimes you can assume it is 0 initially, but from habit and for generality I prefer not to assume this, so either set numWord to 0 art the start and do numWord = numword+1 or as I did, just add to the next element in the growing array.

    I prefer the way I did it becase I don't have to check that numWord is initialised properly or know that SB will handle it without initialisation.  In a larger program it may be hard to determine that something is properly initialised, especially if it used in may places so updating it based on the size of array ensures I will be OK, even if I modify the code later in some other way.

    No right answer, just different methods and tricks - its good to have a knowledge of different ways to do stuff and choose te best for each task.



    Wednesday, October 14, 2015 9:17 PM
    Moderator
  • perfect. Makes sense. so would you say challange 1 and 2 of the text challange has been simplified as much as possible using both methods (your method (stacks) which is what we were suppose to do and the idiot method(mine) where we used arrays)?
    • Edited by JetFire3201 Wednesday, October 14, 2015 9:23 PM
    Wednesday, October 14, 2015 9:22 PM
  • Absolutely, the idea is to see different way to do things, discuss and understand different approaches, exactly as we did.

    Job done.

    Wednesday, October 14, 2015 9:23 PM
    Moderator
  • As to you. :-)
    Wednesday, October 14, 2015 9:24 PM
  • this program only reversed the words but didnt reverse the sentence so it can be read grammatically correctly.

    You're right JetFire.

    Here's recursive to reverse the words and not the sentence:

    string = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow" + " "
    Reverse()
    
    Sub Reverse
      word = Text.GetSubText(string, 1, Text.GetIndexOf(string, " ")-1)
      string = Text.GetSubTextToEnd(string, Text.GetIndexOf(string, " ") + 1)   
      ReverseWord()  
      While Text.IsSubText(string, " ")
        TextWindow.Write(" ")
        Reverse()    
      EndWhile  
    EndSub
    
    Sub ReverseWord
      While Text.GetLength(word) > 0     
        TextWindow.Write(Text.GetSubText(word, Text.GetLength(word), 1))
        word = Text.GetSubText(word, 1, Text.GetLength(word) -1) 
        ReverseWord()    
      EndWhile
    EndSub

    Wednesday, October 14, 2015 9:29 PM
    Moderator
  • Another good way, actually you don't need recursion here, this also works.

    Sub ReverseWord
      While Text.GetLength(word) > 0     
        TextWindow.Write(Text.GetSubText(word, Text.GetLength(word), 1))
        word = Text.GetSubText(word, 1, Text.GetLength(word) -1) 
        'ReverseWord() 'NOT NEEDED    
      EndWhile
    EndSub


    Wednesday, October 14, 2015 9:34 PM
    Moderator
  • interesting. As with everything, everything can be simplified further. Nice work. (a little advice> comment so people can see the point of each line so they can follow along with what you were thinking when you wrote it)
    Wednesday, October 14, 2015 9:35 PM
  • @litdev

    You're right. That would be more natural. lol, I had my recursive blinkers on.

    @jetfire

    Has it been perfectly simplified? Who knows? If someone could work out how to invert a Shape Image that would be really sweet.

    That was fun.

    Wednesday, October 14, 2015 9:46 PM
    Moderator
  • would shapes.rotate(180) be the answer to inverting a shape image?
    Wednesday, October 14, 2015 9:47 PM
  • That's a good thought.

    Inverting on the X-axis would be the equivalent of zooming to:

    Shapes.Zoom(shapeName, scaleX, scaleY)

    where scaleX = -1

    Wednesday, October 14, 2015 9:53 PM
    Moderator
  • I just revised my code for the reverse in array and i dropped 12 lines :

    Text1 = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow " ' slight modification i added a space at the end. is that legal?
    find = " "
    j = 0 ' word count
    total = Text.GetLength(text1)
    For i = 0 To total ' gets every character and puts it in a array of words
      letter = Text.GetSubText(text1, i, 1)
      If letter = find Then
        j = j + 1   
      Else 
      EndIf 
    endfor
    TextWindow.Pause()
    pos = 1
    For i = 1 To j Step 1 
      For l = 0 To total Step 1 'this will not go completly. there will be a skip
        word[i][l] = Text.GetSubText(Text1, pos, 1) 'gets the letter
        If word[i][l] = find Then ' if the word = <space>
          pos = pos + 1
          Goto skip 
        Else 
          pos = pos + 1  
        EndIf
      EndFor
      TextWindow.Pause()
      skip:
      For l = total To 0 Step -1 ' will write the word in letter reversal
        If word[i][l] = find Then 'wont write the character 
            else
            TextWindow.Write(word[i][l])
            EndIf
          EndFor
          TextWindow.Write(" ")
    endfor

    Wednesday, October 14, 2015 10:00 PM
  • Text Challenge

    • "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow"

    Letter = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow "
    midP= Text.GetIndexOf(Letter," ")
    While midP>0
      tmp= Text.GetSubText(Letter,1,midp-1)
      Letter=Text.GetSubTextToEnd(Letter,midP+1)
      reverse()
      midP= Text.GetIndexOf(Letter," ") 
    EndWhile
    TextWindow.WriteLine(Newletter)

    Sub reverse
      tmp2=""
      Len= Text.GetLength(tmp)
      For i= 1 to Len
        tmp2= Text.GetSubText(tmp,i,1)+tmp2   
      EndFor
      Newletter=Newletter+tmp2+" "
    EndSub

    Thursday, October 15, 2015 8:29 AM
    Answerer
  • wow. thats really really smart. you really shortened the length of lines for that program for sure. plz add comments so we can follow.
    Thursday, October 15, 2015 11:53 PM
  • wow. thats really really smart. you really shortened the length of lines for that program for sure. plz add comments so we can follow.

    added comments.

    Letter = "yfidoM eht margorp ot esrever lla eht sretcarahc ni hcae drow "
     midP= Text.GetIndexOf(Letter," ")  '   search 1st space point  = 7 
     While midP>0
       tmp= Text.GetSubText(Letter,1,midp-1) '  get a word block  (1st: yfidoM )
       Letter=Text.GetSubTextToEnd(Letter,midP+1) '  remained letter (eht margorp ot esrever lla eht sretcarahc ni hcae drow )
       reverse()
       midP= Text.GetIndexOf(Letter," ")  ' search next 1st space point  (4,8,3,....... 5,0) 
     EndWhile
     TextWindow.WriteLine(Newletter)

    Sub reverse
       tmp2=""
       Len= Text.GetLength(tmp)
       For i= 1 to Len
         tmp2= Text.GetSubText(tmp,i,1)+tmp2  '  reverse   
       EndFor
       Newletter=Newletter+tmp2+" "
     EndSub

     Note)  remained letter becomes  

     (eht margorp ot esrever lla eht sretcarahc ni hcae drow )  : 1st space point =4

     (margorp ot esrever lla eht sretcarahc ni hcae drow )    : 1st space point =8

       ----------

       ----------

     (drow )   : 1st space point =5

     ( )   : 1st space point =0

     

    Saturday, October 17, 2015 2:42 AM
    Answerer