Good morning! We're back with another challenge which comes from AlexisHappy on Codewars. Today, you are asked to write a program that will return the name of the person who will drink the n-th Cola at the vending machine
Sheldon, Leonard, Penny, Rajesh and Howard are in the queue for a "Double Cola" drink vending machine; there are no other people in the queue. The first one in the queue (Sheldon) buys a can, drinks it and doubles! The resulting two Sheldons go to the end of the queue. Then the next in the queue (Leonard) buys a can, drinks it and gets to the end of the queue as two Leonards, and so on.
For example, Penny drinks the third can of cola and the queue will look like this:
Rajesh, Howard, Sheldon, Sheldon, Leonard, Leonard, Penny, Penny
Write a program that will return the name of the person who will drink the n-th cola. The input data consist of an array which contains at least 1 name, and single integer n which may go as high as the biggest number your language of choice supports (if there's such limit, of course). The output data returns the single line — the name of the person who drinks the n-th can of cola. The cans are numbered starting from 1.
Good luck, and happy coding!
Want to propose a challenge for a future post? Email firstname.lastname@example.org with your suggestions!