Tower Breakers - The Final Battle
Tower Breakers - The Final Battle
+ 0 comments And here's another solution. How it works is explained further down, see the entry of @kiwic.
''' How many stones (maximum) can you fit in for given cost? -> nmax(cost) Obviously every pile has to give this same cost, that is -> nmax(cost-1^2) + nmax(cost-2^2)+... ''' from functools import cache from itertools import count @cache def nmax(cost): if cost < 4: return 1 return sum(nmax(cost-pile**2) for pile in range(1,int(math.sqrt(cost))+1)) def towerBreakers(n): for cost in count(): if nmax(cost)>=n: return cost
+ 0 comments Here is Tower Breakers - The Final Battle problem solution in Python Java C++ and C programming - https://programs.programmingoneonone.com/2021/07/hackerrank-tower-breakers-the-final--battle-problem-solution.html
+ 0 comments This is not a hard algorithm, rather it's a horrible game, hard to understand & poorly explained by the platform.
+ 0 comments Precalculating all values in range for the inverse of the function you're actually interested in feels like a weird solution until you realize said inverse grows exponentially . . . I think. Frankly I wasn't very rigorous in my argument to myself that it isn't superexponential.
+ 1 comment According to problem statement x>=2 and k>= 1 and k<=x ;
so for example if n=4; coin =0 (initially) 4=>{2,2} since k >=1 left {2} and coin=1^2=1 now 2=>{1,1} i.e. x=2; now take both coin 2^2=4 so answer = 1+4=5 then why 6 in testcase ...
Sort 18 Discussions, By:
Please Login in order to post a comment