# [Community Puzzle] Fibonacci's Rabbit

Coding Games and Programming Challenges to Code Better

Created by @Diabetos,validated by @Timinator,@yveslacroix83400 and @jddingemanse.
If you have any issues, feel free to ping them.

Only validator 6 result is over 2^63 (but still below 2^64). This makes the puzzle unnecessarily complicated in languages that have only âsigned int64â support, but not âunsigned int64â support.

3 Likes

To be honest i didnât check this, because i supposed it was a standard data type supported in every language, My bad. What language does not support it ?

I donât program in Java, but there might be problems.

The ones Iâm aware of are Java (no unsigned), php (no unsigned), javascript (double - roughly 2^53). They all have biginteger support so the problem is still possible but slightly more complicated if using one of those languages.

2 Likes

I liked it, I found the loops not as easy to write as I expected thank you !

I got stuck a while with the bigInt test until I understood I needed a bigInt. In javascript there is no error and the number calculated by my code was truncated but really close to the expected answer (only 95 of difference). It was funny to figure it out.
I agree with the others, it may be difficult for beginners to think of that, especially depending on the language.

I donât understand tests 7 and 8. Why the result is 64 for test 7 and 2066850 for test 8?

What do you think the answer should be, and what is your calculation (say, list the first few steps)?

The problem is that itâs a validator (12 for me) which is not working with a classic code in phpâŠIt can be hard to guess that itâs a problem with large numbers. Should be a good thing to swap validator 12 and test 12 no ?

1 Like

For test 7:
_At T0: nb of pairs = 8
_At T1: nb of pairs = 8
_At T2: nb of pairs = 8
_At T3: nb of pairs = 8
_At T4: nb of pairs = 16 (2T3)
_At T5: nb of pairs = 32 (2
T4)
_At T6: nb of pairs = 24 (T1+T2+T3)
_At T7: nb of pairs = 32 (T2+T3+T4)
_At T8: nb of pairs = 56 (T3+T4+T5)
_At T9: nb of pairs = 72 (T4+T5+T6)
_At T10: nb of pairs = 88 (T5+T6+T7)
_At T11: nb of pairs = 112 (T6+T7+T8)
_At T12: nb of pairs = 160 (T7+T8+T9)

Hi,

For Test 7 it should be:

``````T0: 8
T1: 0
T2: 0
T3: 8 (T0)
T4: 8 (T0 + T1)
T5: 8 (T0 + T1 + T2)
T6: 8 (T1 + T2 + T3)
T7: 16 (T2 + T3 + T4)
...
``````

The initial pairs are only old enough to produce new pairs starting at T3

Seeing the comments here I realised I set the maximum to be under 2^64 so it could be done in every languages, I didnât know there was no unsigned in some language, if itâs not too late to change that now that it is published Iâll edit that because even if there was the fact that the issue only occur on a validator is no good.

Itâs ok to edit the puzzle to remove the issues which prevent players of some programming languages from completing it.

1 Like

I set the maximum to be under 2^64 so it could be done in every languages

It would not be good enough for javascript, which has a max int value (2^53) -1

Itâs no big deal, javascript can have numbers up to 2^1024, youâre not the first one I see telling that but you have not any problem with overflows in js, Iâm no expert but Iâm pretty sure js only has the type ânumberâ for floats and ints and it can go way higher than 2^53, itâs not even like you had to specify you want a big number. No issue there

Well I realise I said something really wrong, it must have been too long since I last did Js, you can overcome the 2^53-1 limit by using BigInt. Something like the following will print the exact good answer:

``````const num = BigInt(2**64);
console.log(num.toString());
// Output : 18446744073709551616
``````

Test 7 and Test 8 are very surprising. I think it may be an error in the validation target.

This is TEST 8.

F0 = 50

N years = 50

a = 5

b = 10

50

50

50

50

50

100

150

200

250

300

350

450

600

800

1050

1350

1700

2150

2750

3550

4600

5950

7650

9800

12550

16100

20700

26650

34300

44100

56650

72750

93450

120100

154400

198500

255150

327900

421350

541450

695850

894350

1149500

1477400

1898750

2440200

3136050

4030400

5179900

6657300

6657300

### Ăchec

6657300

Attendu :

2066850

6657300 is the sum of newly born rabbits not yet turned into adults for the past five years.

6657300 = 757500 + 973550 + 1251250 + 1608150 + 2066850

The newly born rabbits for the last year is just 2066850.

Thank you for your help. But, for Tests 1 to 6, we have to output the n-th element of the Fibonacci suite, and simply the n-th element itself, that is F[N] very simply. But only for Test 7, we have to compute the difference between F[N] and F[N - a + 1] to get the New Borns only. And for Test 8, another type of computation.

This makes impossible for a unique code to match all the cases.