I’ve found a bug. I’ve written the dynamic algorithm in C++ (I use Codecombat to learn Python), and then it returned good return. But, the lasers remain(why?)
Hmm, C++ is not supported in codecombat, I don’t get why you’re attempting to use it? Or is it something else?
But I tested if the python algorihtm is bad by writting the ggod one in c++ (level is subarray retreat, I tested if the gems I selected are the best combination) Do you want some screenshots?
I use python but I have a c++ compiler so I wanted to test if my code is wrong (I got the gem values and tested if my python code works good)
# Find the subarray of gems with the best summary value. # This function solves the problem in linear time. def dynamicMaxSum (gems): cycles = 0 maxStartIndex = 0 maxEndIndex = 0 maxEndHere = gems.value currentStartIndex = 0 maxBest = 0 for i in range(len(gems)): cycles += 1 maxEndHere += gems[i].value if maxEndHere < 0: maxEndHere = 0 currentStartIndex = i + 1 if maxEndHere > maxBest: maxStartIndex = currentStartIndex maxEndIndex = i maxBest = maxEndHere hero.say("I's taken " + cycles + " cycles.") return [maxStartIndex, maxEndIndex] # This function solves the problem in quadratic time. def naiveMaxSum(gems): cycles = 0 maxStartIndex = 0 maxEndIndex = 0 maxBest = 0 for i in range(len(gems)): sum = 0 for j in range(i, len(gems)): cycles += 1 if cycles > 104: hero.say("I fed up of calculations.") return [i, j] sum += gems[j].value if sum > maxBest: maxStartIndex = i maxEndIndex = j maxBest = sum hero.say("I's taken " + cycles + " cycles.") return [maxStartIndex, maxEndIndex] # Don't worry "findItems" sort out gems by X coordinate. items = hero.findItems() # Δ: Maybe we should change this function? #edges = naiveMaxSum(items) edges = dynamicMaxSum(items) x1 = edges * 4 + 4 x2 = edges * 4 + 4 # Collect gems from x1 to x2 and escape: hero.moveXY(x1, 40) hero.moveXY(x2, 40) hero.moveXY(40,64)
This is my code
Did you change any of the the Dynamic code?
It didn’t work yesterday and now… it is success
Anyway that must be a strange bug
you know with pender you can just walk through
I mean it’s better if you do it the normal way.
also with ritic. Thats to only way to get 1 in the leaderboards
Note that, doing the level as it tell you to is always better than doing something else and solving it.