avatar Bite 268. Number Transformers

Inspired by the movie Transformer, John decides to design a "number transformer" as a test.

It is capable to perfom the transformation of the number 1 (one is the base) to any "target" number.

The two allowed operations/rules are:

  1. multiply by 2
  2. int divide by 3

The operations can be chained repeatedly, and maybe just needs to run one of the rules.

Let's see an example:

  • Convert 1 (base number) to 10 (target number) = 6 operations:

    1 * 2 * 2 * 2 * 2 // 3 * 2 = 10

  • Convert 1 (base number) to 8 (target number) = 3 operations:

    1 * 2 * 2 * 2 = 8

After some manual testing with a few small numbers, it seems to be working just fine.

But what about bigger numbers? What if the number is greater than 10?

Can you help him to design a function to mearsure the efficiency, aka, how many operations it will take to convert 1 (the base) to the asking target number?

[Hint] the data structure is the key here.

Login and get coding
go back Advanced level
Bitecoin 4X

70 out of 75 users completed this Bite.
Will you be the 71st person to crack this Bite?
Resolution time: ~105 min. (avg. submissions of 5-240 min.)
Our community rates this Bite 8.22 on a 1-10 difficulty scale.
» Up for a challenge? 💪

Focus on this Bite hiding sidebars, turn on Focus Mode.

Ask for Help