
-----------------------------------
HB
Tue Mar 06, 2012 11:17 am

Extremely basic program
-----------------------------------
What is the problem you are having?
I can't figure out how to generate a pattern in Turing using * with for loops



Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
im looking to generate a Turing program that makes this pattern 


*
**
***
****
*****
******


-----------------------------------
Zren
Tue Mar 06, 2012 12:40 pm

RE:Extremely basic program
-----------------------------------
What have you tried so far?

-----------------------------------
QuantumPhysics
Wed Mar 07, 2012 12:26 am

RE:Extremely basic program
-----------------------------------
use the character ASCII value of the star and have the user enter a bottom row value. Have the program out put that number of stars and reduce one everytime, or add one every time untill it gets to the max row number

-----------------------------------
S_Grimm
Wed Mar 07, 2012 9:03 am

Re: RE:Extremely basic program
-----------------------------------
use the character ASCII value of the star and have the user enter a bottom row value. Have the program out put that number of stars and reduce one everytime, or add one every time untill it gets to the max row number

Or you know, start at the first line and each time you go to a new line add another star to the output.

Take a look at For Loops inside For Loops.

-----------------------------------
HB
Wed Mar 07, 2012 10:40 am

RE:Extremely basic program
-----------------------------------
Is there a tutorial for For Loops inside For Loops?

-----------------------------------
HB
Wed Mar 07, 2012 10:47 am

RE:Extremely basic program
-----------------------------------
for y : 1 .. 8
    for z : 1 .. y
        put "*" ..
    end for
    put""
end for

muahahahahaha

-----------------------------------
S_Grimm
Wed Mar 07, 2012 12:50 pm

Re: RE:Extremely basic program
-----------------------------------
for y : 1 .. 8
    for z : 1 .. y
        put "*" ..
    end for
    put""
end for

muahahahahaha

Looks about right. I don't have access to a Turing Compiler at work, so I cant verify.

-----------------------------------
smool
Wed Mar 07, 2012 4:20 pm

Re: Extremely basic program
-----------------------------------

proc Star (numrows : int)
    for i : 1 .. numrows
        for j : 1 .. i
            put "*" ..
        end for
        put ""
    end for
end Star

Star (4)

-----------------------------------
Dreadnought
Wed Mar 07, 2012 4:42 pm

Re: Extremely basic program
-----------------------------------
You can also use [tdoc]repeat[/tdoc]. It's faster than nesting a for loop because you call [tdoc]put[/tdoc] only once per line of '*'. On the other hand, you can't use it for lines with more than 255 '*'. (I assume that wouldn't be an issue though...)
