TheCK / codeChallenges

assortment of my solutions to various coding challenges around the internet
20 stars 2 forks source link

Need Code Explanation #1

Closed baskaran-radhakrishnan-10 closed 5 years ago

baskaran-radhakrishnan-10 commented 5 years ago

Hello brother,

I just gone through code of "Predict the Number".

But i don't understand , why you have used

1.) Right Shift to find out the depth. 2.) what is the need of depth number.

Please kindly provide your explanation.

Thanks and Regards, Baskaran Radhakrishnan.

TheCK commented 5 years ago

Namaste,

1) The getLog function just calculates the log to base 2 by counting how often you can shift the number right by one bit before it becomes 0. (Shifting right basicly divides by 2, but is much faster)

2) "depth" is just the number of steps that is needed to create the sequence of the required length. Since the length of the sequence doubles with every step, the number of steps needed is log_2.

Then depth is used to recursively calculate just the slice of the sequence that is needed.

Hope this helps, and good luck with your job interview (I assume)

baskaran-radhakrishnan-10 commented 5 years ago

Thank you brother.

On Mon, Jun 17, 2019, 2:49 PM CK notifications@github.com wrote:

Namaste,1) The getLog function just calculates the log to base 2 by counting how often you can shift the number right by one bit before it becomes 0. (Shifting right basicly divides by 2, but is much faster)2) "depth" is just the number of steps that is needed to create the sequence of the required length. Since the length of the sequence doubles with every step, the number of steps needed is log_2.Then depth is used to recursively calculate just the slice of the sequence that is needed.Hope this helps, and good luck with your job interview (I assume)On 17 Jun 2019 9:34 am, Baskaran Radhakrishnan notifications@github.com wrote:Hello brother, I just gone through code of "Predict the Number". But i don't understand , why you have used 1.) Right Shift to find out the depth. 2.) what is the need of depth number. Please kindly provide your explanation. Thanks and Regards, Baskaran Radhakrishnan.

—You are receiving this because you are subscribed to this thread.Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/TheCK/codeChallenges/issues/1?email_source=notifications&email_token=AFKVDRJPZR32FPG2HBGJVYTP25JJ3A5CNFSM4HYT6CTKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODX2SDBQ#issuecomment-502604166, or mute the thread https://github.com/notifications/unsubscribe-auth/AFKVDRPSZLQKMT52H7HULNDP25JJ3ANCNFSM4HYT6CTA .