물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Beeramid

BEstyle 2022. 10. 28. 21:35

DESCRIPTION:

Let's pretend your company just hired your friend from college and paid you a referral bonus. Awesome! To celebrate, you're taking your team out to the terrible dive bar next door and using the referral bonus to buy, and build, the largest three-dimensional beer can pyramid you can. And then probably drink those beers, because let's pretend it's Friday too.

A beer can pyramid will square the number of cans in each level - 1 can in the top level, 4 in the second, 9 in the next, 16, 25...

Complete the beeramid function to return the number of complete levels of a beer can pyramid you can make, given the parameters of:

  1. your referral bonus, and
  2. the price of a beer can

For example:

beeramid(1500, 2); // should === 12
beeramid(5000, 3); // should === 16

def beeramid(bonus, price):
    numBeer=bonus//price
    if numBeer<=0:
        return 0
    lv=1
    total=1
    while numBeer>=total:
        lv+=1
        total+=lv*lv
    return lv-1

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

Pair of gloves  (0) 2022.10.29
English Beggars  (0) 2022.10.28
Sum consecutives  (0) 2022.10.28
The Deaf Rats of Hamelin  (0) 2022.10.28
Converting string to camel case  (0) 2022.10.26