# [Community Puzzle] Gravity Centrifuge Tuning

https://www.codingame.com/training/medium/gravity-centrifuge-tuning

A post was merged into an existing topic: Community Puzzle - Gravity Centrifuge Tuning calcul

Gravity Centrifuge Tuning is very instructive. I suggest everyone to read the titles of the tests to get a clue.

There is one test that is at odds with the puzzle description though. The âConstraintsâ section states that âN > 0â, but the âWait, what?â test sets N to 0. Itâs probably easier to amend the constraint. If you solve it before the text is changedâŚ be aware of that.

2 Likes

I have just updated the constraints section.

2 Likes

Hihi,

If you finished the puzzle âGravity Centrifuge Tuningâ (Coding Games and Programming Challenges to Code Better)
would you mind explaining me the calcul method since i dont get it !!
From what i understood the âtumbles potentialâ of each bit is:
0 ->1
10 ->1+1=2
100 â 1+2=3
1000 â 2+3=5
10000-> 3+5=8
100000 â 8+5=13
and so on.
So, for the input 9, i guess that the output should be 9=8+1(1001) but the testcase expect me to answer 21(10101) ??!!
I am a bit lost âŚ

Have a look at the name of that testcase

1 Like

Beautiful puzzle. I enjoyed it a lot

Zeckendorf can indeed be proud

Kudos to the puzzle writer. Very very elegant.

2 Likes

Hi, Iâm trying to solve this puzzle with `javascript`,
Any clue how to manage the integer overflow?

Seems there is no `BigInt()` library (on spidermonkey compiler), how Iâm supposed to save `N` (number of tumbles) like on the last test:
`"Zeckendorf would be proud of you"`?

Even if somehow I managed to work on itâs string representation, and find the `binary bitstream` (as string), how I can convert the bitstream to octal without overflow?

You are correct that this is much harder in some languages due to the lack of bignum support . For the conversion at the end you can work a single character at a time - every 3 binary bits is one octal character.

Well ok itâs harder (and honestly, why would you use such languages when there are alternatives available? I digress), but I take offense at the âmuch harderâ distinction: if your algorithm is sound, you donât need any of the âhardâ operations, and you can trivially implement them all on a string or bitfield or whatever.

Thatâs supposed to be way easier than the initial conversion from decimal to your internal representation, whatever it is.

You donât think itâs a bug that I canât use `BigInt()`? (there is `BigInt()` in `node` but not in `spidermonkey`).

How is it possible to find the `N` tumbles if I canât reach the number due the overflow?

You can see that the puzzle starts with `var N = BigInt(readline());` example:

But you get

``````Errors
ReferenceError: BigInt is not defined
``````

Iâll try explain the problem:

The way Iâm trying to solve is building `N`, from then is just `binary` to `octal`.
but I canât get to `N` (in `node.js` I can) due the overflow.

I see three ways do solve that:

• Find a smarter solution that doesnât rely on big integers (for this problem I donât think there is one)
• Write your own BigInteger functions
• Use another language that supports it (C# and Java have BigInteger libraries for example, Python supports them natively)

I donât get the point with this âoctalâ conversion.
And the following extra rule just add more to the confusion:

Damaged Gravity Centrifuges
The Gravity Centrifuge youâve got access to has a cooling issue that hasnât been fixed yet. On your damaged Gravity Centrifuge, if two consecutive bits in the bitstream are set, the twin inertial drive overheats and burns down.
So donât do that.

As far as I understand the solution is to insert a â0â bit between each pair of â1â consecutive bits, Am I right ?

Any help will be greatly appreciated

Itâs not strictly needed to understand it to solve the puzzle. Itâs just there as an extra optimization enablerâŚ for those who see it.

No, no, thatâs not the idea Itâs not an âextra ruleâ to confuse people, itâs there as an additional constraint to the allowed solutions. (as a problem setter, I needed because without it I canât have a unique validator output).

See it this way: among the possible solutions to the problem, only output one that wouldnât overheat.

1 Like

For people who are not into maths, âmediumâ difficulty can be misleading.
This puzzle is based on a theorem and a method youâll have to lookup if you donât know it already. Trying to come up with a solution by trial and error is a total waste of time.
The needed keyword is hidden somewhere. Look closely and youâll find it.

Once the trick is found, 98% of the code is already done.
How disappointingâŚ

I really enjoyed this one.

There was a potential greedy solution but I didnât try it cause I thought that it wasnât guaranteed to work all the time so I went for a systematical recursive search.
And then I checked others solutions and saw that most of them used the greedy solution I was thinking of.
So I wondered if it was luck or not, if the greedy solution was always successful, and ended up demonstrating that it was indeed always successful.

Itâs always nice to see that an intuitive solution has actually solid foundations.

2 Likes