0

Maybe I misunderstand my assignment last time.The actually problem description should be like the following:

I have an array: A B AB BAB ABBAB BABABBAB

The number of each term of the array is base on the Fibonacci number.

Put the n-th string and the n+1-th string together, then producing the n+2-th string:

BABABBAB = BAB + ABBAB

Then is the x-th (eg.10^16-th) letter of the n-th term which count from the last letter is A or B? Eg. the 6th letter was B, not only in the 6th term BABABBAB but also in the later terms ABBABBABABBAB

The 7th letter is A in the the 6th term BABABBAB and also in the later terms - ABBABBABABBAB

The most inspiring news is that someone has a Θ(1) solution.

if [x / g] * g >= x - 1 then it's B else it's A. g is the golden mean.

but he or she didn't explain why it works.

Neomatrix
  • 31
  • 4
  • I just thought that: if x > f(n) and x < f(n+1), that means x is among the f(n+1) and it's the x - f(n-1) in the f(n-2) then just going on until to the 1st or 2nd term.But the complexity will be Θ(n). The solution I added was so simple and perfect to solve the problem, but I can't figure out. – Neomatrix Mar 20 '11 at 06:59
  • 1
    possible duplicate of [Fibonacci string array](http://stackoverflow.com/questions/5353107/fibonacci-string-array) – Paul R Mar 20 '11 at 08:45
  • You should update your original question with the new information, rather than starting a new question on the same topic. – Paul R Mar 20 '11 at 08:46
  • @Paul R: It's a different problem from the previous one,though they have same assumptions. – Neomatrix Mar 20 '11 at 09:20
  • Can you post a link to where you got that from? I don't think it works. `[6 / g] * g = 4.8`, which is not at least `5`. So you would say it's A when in fact it's B. – IVlad Mar 20 '11 at 10:04
  • @IVlad @Paul R @Brian Roach Thanks for your attention! It's all my fault to misunderstand much information.I found the original problem. http://projecteuler.net/index.php?section=problems&id=230 – Neomatrix Mar 22 '11 at 15:44

1 Answers1

0

Have a look at the Wikipedia article on Fibonacci Word. A formula for the n'th digit is given there along with references.

Dale Gerdemann
  • 739
  • 5
  • 7
  • +1: The problem gives the reverse of Fibonacci words. Can prove using induction... –  Mar 26 '11 at 05:10