I won’t solve your problem for you but my hint to you is to put a print statement inside the loop so you can see what is happening at each step. Hopefully you will see what the issue is.
No you haven’t understood how to get the sequence correctly.
You were given your first 5 so what is the 6th(Well 30th really and my quick googling didn’t get 5805 for the length of the number either)?(1, 11, 21, 1211, 111221)
To highlight you mentioned these as the first 5…
(1,11,12,21,111,222)
P.S I found the sequence based around google searches for conway and morris.
Correct so now write a program to find the 30th and count the length.
Hint if you actually find the sequence name you’ll find people have done the home work programming isn’t my strong point but I do have the answer.
I found it twice one using lambda and one using a relatively simple function, sadly I bailed out at expanding it and just did a wc on the 30th to find the length.
The answer is well wrong all numbers in the sequence are made from 123 as far as I’m aware.(Edit well less than you showed it would seem sometimes other digits do pop up but they didn’t stand out to me in the seq to 30 with a seed as 1)
You have the full range of digits from my quick look. Answer that gives you 79
As Ken said throw in some print statements from my quick look the else isn’t even being triggered.
P.S.
Both solutions I’ve found seem to be using the length of the string to equate the next number any way. My crude glancing reckons you’re not doing enough with the len of the number to equate the next number in the sequence. I also suspect not enough nesting to equate it.
You understand how to generate the sequence but you’re generating many sequences with different seeds you’ve been given the first 5 for your sequence you have the formula the sequence you’re interested in is…
1, 11, 21, 1211, 111221, 312211 … (Till you get to the 30th number generated in this sequence)
Your example isn’t a sequence. Where does 2 come from? Presuming a slip up whilst you’re getting the answer right I’m not sure whether you understand the how…
1211 => 111221
1211 = 11 12 2*1
You gave me the 6th in sequence …
312211
111221 = 31 22 1*1
maybe that will help finding the name of the sequence is really going to help I’m not sure you’ve found that out yet.
I’d imagine your problem is sourcing the vimrc iirc gvim won’t use vimrc but can be told how to start with .vimrc or put them in .gvimrc (gvim --help). The instructions look pretty valid but been a while since I did it.
On 2010-10-19, snowman1967 <snowman1967@no-mx.forums.opensuse.org> wrote:
>
> Hello,
>
> I have this problem a = [1, 11, 21, 1211, 111221
> Now I need the length of the 30 number.
>
> So i thought this would solve that:
>
> Code:
> --------------------
>
> getal = “1”
> vorig = getal[0]
> aantal = 0
> uitkomst2 = 0
> uitkomst = “”
> einde = 30
> hoevaak = 1
> while hoevaak < 30:
> for nummers in getal:
> if nummers == vorig :
> aantal = aantal + 1
> vorig = nummers
> else:
> getal2 = str(aantal)
> uitkomst = uitkomst + getal2 + vorig
> aantal = 1
> vorig = nummers
> getal2 = str(aantal)
> uitkomst = uitkomst + getal2 + vorig
> uitkomst2 = uitkomst2 + len(uitkomst)
> hoevaak = hoevaak + 1
> print uitkomst
>
> --------------------
>
>
> So the answer is 78
> But he real answer is 5805
>
> What am I doing wrong ?
According to mine, the answer is 5808
Here is what I tried:
#! /usr/bin/python
import string
maxnum=30
num=0
start=“1”
getal=start
while num<=maxnum:
print num, ‘) ‘, len(getal)
vorige=getal[0]
out=’’
for c in getal:
if c!=vorige:
out=out+’ ’
vorige=c
out=out+c
getal=’’
for c in string.split(out, ’ '):
getal=getal+str(len(c))+c[0]
On 2010-10-21, snowman1967 <snowman1967@no-mx.forums.opensuse.org> wrote:
> Thank you for your solution.
> But I don’t see what’s wrong with my solution.
>
> Anyone who can give me a hint.