Author |
Message |
pokerface
|
Posted: Fri Oct 15, 2004 5:12 pm Post subject: patterns |
|
|
im trying to make a program that out puts a pattern depending of what number u input.
******************************************
var num : int
put "Enter a negative number to stop."
loop
put "How many patterns do you want? " ..
get num
exit when num <= 0
for count : 1 .. num
put "!" ..
end for
put ""
end loop
*******************************************
example of what im looking for
(if you type a 8 then u get "!@#!@#!@" as the answer but if u type 1 then u get "!" or a 9 then u get "!@#!@#$!@#") need me 2 further explain then please ask me for me to answer what i mean! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
AsianSensation
|
Posted: Fri Oct 15, 2004 9:08 pm Post subject: (No subject) |
|
|
well, I suggest a bit of a string manipulation.
declare a string variable, something like this:
code: | var symbol := "!@#$%^&*" |
and instead of outputting the "!".. in your code, output a random letter of the string above. |
|
|
|
|
|
wtd
|
Posted: Fri Oct 15, 2004 9:14 pm Post subject: (No subject) |
|
|
Get a number of characters.
Create a counter variable, set it to 1.
Create an empty string variable to hold the output pattern.
Start a loop.
If the counter is greater than the number of characters, exit the loop.
Add "!" to the string.
Increase the counter by one.
If the counter is greater than the number of characters, exit the loop.
Add "@" to the string.
Increase the counter by one.
If the counter is greater than the number of characters, exit the loop.
Add "#" to the string.
Increase the counter by one.
End the loop. |
|
|
|
|
|
AsianSensation
|
Posted: Fri Oct 15, 2004 9:19 pm Post subject: (No subject) |
|
|
wait, what was the pattern?
like if I input 1, it out puts "!"
2 and "!@"
3 and "!@#"
4 and "!@#$" or something?
but 8 was "!@#!@#!@", so it was taken in groups of 3s
and 9 was "!@#!@#$!@" which was weird because it had 10 chars and weird repeating patterns.
I suggest a further explaination. |
|
|
|
|
|
pokerface
|
Posted: Fri Oct 15, 2004 9:52 pm Post subject: (No subject) |
|
|
i want it to put ! if the user asked to put 1 symbol
but !@ if the user asked for 2 symbols.
its werid but i want it to add # if they ask for 3 symbols!!!
*****************************************
How many patterns do you want? 1
!
How many patterns do you want? 2
!@
How many patterns do you want? 3
!@#
How many patterns do you want? 4
!@#!
How many patterns do you want? 5
!@#!@
How many patterns do you want? 6
!@#!@#
How many patterns do you want? 7
!@#!@#!
********************************************
You get what i mean? |
|
|
|
|
|
wtd
|
Posted: Fri Oct 15, 2004 10:15 pm Post subject: (No subject) |
|
|
pokerface wrote: You get what i mean?
The algorithm I provided does exactly what you want. |
|
|
|
|
|
pokerface
|
Posted: Fri Oct 15, 2004 10:26 pm Post subject: (No subject) |
|
|
sorry that was directed to AsianSensation |
|
|
|
|
|
wtd
|
Posted: Fri Oct 15, 2004 10:34 pm Post subject: (No subject) |
|
|
I know. Just seemed kind of odd that you were still fishing when I'd thrown out a way of getting it done. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
AsianSensation
|
Posted: Fri Oct 15, 2004 11:58 pm Post subject: (No subject) |
|
|
yah, I was confused about the Quote: a 9 then u get "!@#!@#$!@#" I didn't see where the "$" came from. |
|
|
|
|
|
pokerface
|
Posted: Sat Oct 16, 2004 9:03 am Post subject: (No subject) |
|
|
wtd i dont understand! could u show me an example? dont worry this is not for school! i just wanted to make a pattern cause a question for school is very simular! |
|
|
|
|
|
AsianSensation
|
Posted: Sat Oct 16, 2004 11:26 am Post subject: (No subject) |
|
|
I guess something like this:
code: | var symbol := "!@#"
var num : int
get num
for rep : 1 .. num
if rep mod 3 not= 0 then
put symbol (rep mod 3) ..
else
put symbol (3) ..
end if
end for
|
|
|
|
|
|
|
pokerface
|
Posted: Sat Oct 16, 2004 12:15 pm Post subject: (No subject) |
|
|
ty
for ur time! |
|
|
|
|
|
wtd
|
Posted: Sat Oct 16, 2004 2:17 pm Post subject: (No subject) |
|
|
pokerface wrote: wtd i dont understand! could u show me an example? dont worry this is not for school! i just wanted to make a pattern cause a question for school is very simular!
I won't show you in Turing, because then you could just copy and paste.
[code]# get an integer representing the number of characters
num_chars = gets.to_i
counter = 1
output = ""
loop do
break if counter > num_chars
output += "!"
counter += 1
break if counter > num_chars
output += "@"
counter += 1
break if counter > num_chars
output += "#"
counter += 1
end loop
puts output |
|
|
|
|
|
Andy
|
Posted: Sat Oct 16, 2004 2:20 pm Post subject: (No subject) |
|
|
wtd wrote: I won't show you in Turing, because then you could just copy and paste.
i thought it was cuz u dont have turing on ur comp lol |
|
|
|
|
|
wtd
|
Posted: Sat Oct 16, 2004 2:22 pm Post subject: (No subject) |
|
|
dodge_tomahawk wrote: wtd wrote: I won't show you in Turing, because then you could just copy and paste.
i thought it was cuz u dont have turing on ur comp lol
For something this simple, I can manage to write code that would work. |
|
|
|
|
|
|