HI, Want Help to print a series
Hi All,
I want to write a program which would display the 慛抰h term in the series, given N.
1, 11, 21, 1211, 111221, 312211, 13112221 ...
how to go about please help...
The logic is:
1 = 1
11 = One 1
21 = two 1
1211 = One 2 Two 1
111221 = three 1 two 2 one 1
and it goes on
Do I detect a request for someone to just do your homework for you? Nah, it must be my imagination.
Here's my suggestion: Do the tutorials.
http://java.sun.com/docs/books/tutorial/
Other than that, then before we'll do your homework for you, you'll have to indicate you have at least two conditions from the following:
1) This is of utmost urgency
2) It's your professor's ineptitude at teaching (not your ineptitude at learning) which brought you to this point
3) Family emergencies have prevented you from dedicating enough study time
4) Your course of study does not really require learning this, so you should just be handed solutions so you can pass and get on with your true vocation
Can you describe how you'd find the nth term of the series if you were doing it on paper? What's the pattern? How do you figure out how to go from one step to the next?
Solve your series problem or watch Feist sing "1 2 3 4": http://www.youtube.com/watch?v=p8Z-DIAthbMSorry, you lose ;-)
The pattern is like this:
The First number is :
1 : as there is: one 1
the second number will be : 11 : as there is ( two 1)
the the third number is : 21 : as there is (One 2) (One 1)
the the fourth number is : 1211 : as there is ( one 1) and (one 2) and (two 1)
the fifth number is : 111221 as there is : (One 1) (one 2) (two 1)
the series continues like this:
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
I still have no idea what the rules of the pattern are.If you can't explain it in simple, precise terms, without resorting to examples, then you can't possibly write code to do it.
jverda at 2007-7-12 22:06:14 >

> The First number is : 1 : as there is: one 1
> the second number will be : 11 : as there is ( two 1)
What's the rule that says to add another 1?
> the the third number is : 21 : as there is (One 2) (One 1)
What's the rule that says to change the 1 to a 2?
> the the fourth number is : 1211 : as there is ( one 1) and (one 2) and (two 1)
> the fifth number is : 111221 as there is : (One 1) (one 2) (two 1)
I think you got the fifth one wrong.
Is the pattern dependent on the symbols being numbers, or could you just as easily use letters, ie:
A
AA
BA
ABAA
etc
Ah! I get it now! I'll leave it to the OP to describe it himself as a learning exercise though.
> Ah! I get it now! I'll leave it to the OP to describe> it himself as a learning exercise though.I got it, too, and was going to post a proper description, but you are right -- it's time the poster learned to be clear.
> Ah! I get it now! I'll leave it to the OP to describe
> it himself as a learning exercise though.
Yeah, I finally caught on. I'm even slower than usual today. I was trying to help the bartender last night by getting rid of the beer in front of me, but as soon as I'd take care of one, she'd put another one in front of me. She kept this up until closing. Do a person one little favor and they think they can impose on you again and again. I'll have to make sure to go there and give her a piece of my mind after work today.
jverda at 2007-7-12 22:06:14 >

> > The First number is : 1 : as there is: one 1
> > the second number will be : 11 : as there is ( two
> 1)
>
> What's the rule that says to add another 1?
>
> > the the third number is : 21 : as there is (One 2)
> (One 1)
>
> What's the rule that says to change the 1 to a 2?
>
> > the the fourth number is : 1211 : as there is ( one
> 1) and (one 2) and (two 1)
> > the fifth number is : 111221 as there is : (One 1)
> (one 2) (two 1)
>
> I think you got the fifth one wrong.
>
> Is the pattern dependent on the symbols being
> numbers, or could you just as easily use letters,
> ie:
> A
> AA
> BA
> ABAA
> etc
Actually, this is fairly clear as to the pattern
The First number is :
1 : as there is: one 1
the second number will be : 11 : as there is ( two 1)
the the third number is : 21 : as there is (One 2) (One 1)
the the fourth number is : 1211 : as there is ( one 1) and (one 2) and (two 1)
the fifth number is : 111221 as there is : (One 1) (one 2) (two 1)
the series continues like this:
1
11
21
1211
111221
312211
13112221
1113213211
31131211131221
Read in the number
Count the number of time the first digit occurs
write out the result as
<number of consecutive appearances><digit>
loop thru rest of digits
1 ->> <number of times digit appears>1 <digit>1
11 ->> <number of times digit appears>2 <digit>1
21 --> <number of times digit appears>1 <digit>2 <number of times digit appears>1 <digit>1
etc.
~Tim
Wouldn't it have been better to let the OP work through how to describe the pattern?
jverda at 2007-7-12 22:06:14 >

Solving this has been a moderately interesting and educational regex exercise. :-)
jverda at 2007-7-12 22:06:14 >

Actually, I found his description fairly coherent. And at least I did not give him the code to solve it with. methinks it is time for you to go get that cold beverage!! I know it is time for me to get one.Have a fun weekend everyone!~Tim
> Solving this has been a moderately interesting and> educational regex exercise. :-)Regex, huh?I solved the old fashioned way, with loops and substrings, and converting (Big)ints into strings!! I don't need no stinkin' regex!!~Tim
> > Solving this has been a moderately interesting and
> > educational regex exercise. :-)
>
> Regex, huh?
Yeah, though I'm still trying to work out why using a possessive quantifier caused it to go from not working to working.
> I solved the old fashioned way, with loops and
> substrings,
I'm too lazy for that.
> and converting (Big)ints into strings!! I
> don't need no stinkin' regex!!
No ints for me--other than string lengths.
jverda at 2007-7-21 22:57:44 >

HI sorry,
My computer was down...
The series
1,11,21,1211,111221....
here
11 means : quantity =1 and 1
then 21 means : there were two one's present= 21
then 1211 means... One two is present and then one 1 is present...
hopefully I am clear this time
> HI sorry,
> My computer was down...
> The series
> 1,11,21,1211,111221....
>
> here
> 11 means : quantity =1 and 1
> then 21 means : there were two one's present= 21
> then 1211 means... One two is present and then one 1
> is present...
> hopefully I am clear this time
Yes, we understand it. But you have to be able to explain it more precisely if you're going to tell the computer how to do it.
First iteration is a 1.
Subsequent iterations:
* Read the string of the previous iteration.
* For each group of repeating digits
-append the number of digits in that group
-append that digit
Note that "For each group of repeatin digits" is still not precise enough for a computer. It has to be broken down into smaller, simpler steps. I'll leave that as an exercise for you.
Do it on paper. Think about the smallest pieces--what you're keeping track of in your head, which tiny, simple, basic steps you're doing.
Then translate that all to Java. And if you do your English explanation correctly, translating it to Java will be trivial. This exercise is more about communication than about Java.
jverda at 2007-7-21 22:57:44 >

