Computer Science Canada

patterns

Author:  pokerface [ 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!

Author:  AsianSensation [ Fri Oct 15, 2004 9:08 pm ]
Post 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.

Author:  wtd [ Fri Oct 15, 2004 9:14 pm ]
Post 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.

Author:  AsianSensation [ Fri Oct 15, 2004 9:19 pm ]
Post 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.

Author:  pokerface [ Fri Oct 15, 2004 9:52 pm ]
Post 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?

Author:  wtd [ Fri Oct 15, 2004 10:15 pm ]
Post subject: 

pokerface wrote:
You get what i mean?


The algorithm I provided does exactly what you want. Smile

Author:  pokerface [ Fri Oct 15, 2004 10:26 pm ]
Post subject: 

sorry that was directed to AsianSensation

Author:  wtd [ Fri Oct 15, 2004 10:34 pm ]
Post subject: 

I know. Just seemed kind of odd that you were still fishing when I'd thrown out a way of getting it done. Smile

Author:  AsianSensation [ Fri Oct 15, 2004 11:58 pm ]
Post subject: 

yah, I was confused about the
Quote:
a 9 then u get "!@#!@#$!@#"
I didn't see where the "$" came from.

Author:  pokerface [ Sat Oct 16, 2004 9:03 am ]
Post 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!

Author:  AsianSensation [ Sat Oct 16, 2004 11:26 am ]
Post 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

Author:  pokerface [ Sat Oct 16, 2004 12:15 pm ]
Post subject: 

ty
for ur time!

Author:  wtd [ Sat Oct 16, 2004 2:17 pm ]
Post 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. Wink

[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

Author:  Andy [ Sat Oct 16, 2004 2:20 pm ]
Post subject: 

wtd wrote:
I won't show you in Turing, because then you could just copy and paste. Wink


i thought it was cuz u dont have turing on ur comp lol

Author:  wtd [ Sat Oct 16, 2004 2:22 pm ]
Post subject: 

dodge_tomahawk wrote:
wtd wrote:
I won't show you in Turing, because then you could just copy and paste. Wink


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.

Author:  pokerface [ Sun Oct 17, 2004 7:27 pm ]
Post subject: 

thanks ppl! but do u know how i could seperate even numbers with odd numbers? ps without mods please

Author:  AsianSensation [ Sun Oct 17, 2004 7:58 pm ]
Post subject: 

you can use div

if some number div 2 = some number / 2

then it's even.

Author:  pokerface [ Sun Oct 17, 2004 8:14 pm ]
Post subject: 

is there an other way? i just want to know as many ways as possible?

Author:  AsianSensation [ Sun Oct 17, 2004 10:19 pm ]
Post subject: 

you can always convert it to a string, and check the last digit, if it's 0, 2, 4, 6, 8 then it's even, or else it's odd.

Author:  wtd [ Sun Oct 17, 2004 11:01 pm ]
Post subject: 

pokerface wrote:
thanks ppl! but do u know how i could seperate even numbers with odd numbers? ps without mods please


In integer arithmetic, dividing one integer by another always gives us another integer.

This is why

code:
3 div 2


gives us 1.

So we need a way of finding the remainder. "mod" allows for that.

Obviously, if we divide an even number by 2, there should be no remainder. So if the result of someNumber mod 2 is 0, then someNumber is even.

code:
if n mod 2 = 0 then
   % ...
end if

Author:  beard0 [ Thu Oct 21, 2004 8:08 pm ]
Post subject: 

code:
strintok (realstr (num / 2, 0))


true=even
false=odd


: