# Help on Gridmancer Redux

**URL:** <https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842>\
**Category:** Level Help\
**Created:** [May 27, 2020, 2:33pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842 "2020-05-27T14:33:54Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:33pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/1 "2020-05-27T14:33:54Z")

</div>

Can you help me? I just do not know what is wrong with my code. Here it is:

```python
# Welcome to Gridmancer!
# A relic of days long past, the puzzle returns!
# Your task is to collect all the coins.
# You are given special methods to help with hero task.
# hero.addRect(x, y, w, h) places a rectangle to collect coins.
# hero.removeRect(x, y) removes a previously added rectangle at the point.
# hero.navGrid is (basically) a 2-dimensional array containing "Coin" or "Wall"
# You must collect all coins under rectangles
# Rectangles cannot collide with themselves or walls
# You need to make at most 55 rectangles to beat hero level!

#hero.addRect(0, 18, 4, 2)
#hero.addRect(0, 0, 4, 3)
map = hero.navGrid

for i in range(20):
    addRect(i)

def addRect(row):
    y = row
    done = 0
    for col in map[row]:
        pos = map[row][col]
        if pos == "Coin" and done == 0:
            x = col
            w = 1
            done = 1
        elif pos == "Coin":
            w += 1
        elif pos == "Wall" and done == 1:
            done = 0
            hero.addRect(x, y, w, 1)
    if w == 20:
        hero.addRect(x, y, 20, 1)

```

please help

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:38pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/3 "2020-05-27T14:38:29Z")

</div>

What do you mean? What is with that code?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:40pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/4 "2020-05-27T14:40:56Z")

</div>

Is that the answer I tried playing the level by link?  
But I also have problems!

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:42pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/5 "2020-05-27T14:42:54Z")

</div>

No, I think it is not.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:43pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/6 "2020-05-27T14:43:13Z")

</div>

I will try it again(20 chars)

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:45pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/7 "2020-05-27T14:45:02Z")

</div>

what is the link(to the game)

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:46pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/8 "2020-05-27T14:46:12Z")

</div>

[https://codecombat.com/play/level/gridmancer-redux](https://codecombat.com/play/level/gridmancer-redux)?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:49pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/9 "2020-05-27T14:49:01Z")

</div>

it only lets me play javascript

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:49pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/10 "2020-05-27T14:49:14Z")

</div>

sorry(20 characters needed)

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:50pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/12 "2020-05-27T14:50:09Z")

</div>

Can’t you press Change hero or language and select phyton?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:50pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/13 "2020-05-27T14:50:36Z")

</div>

no i am not on that level because I played by link not by level

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:51pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/14 "2020-05-27T14:51:40Z")

</div>

Ok. Thanks for trying, @Jeremy_Yu! Anybody else?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:52pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/15 "2020-05-27T14:52:03Z")

</div>

But did it work did you try it?

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:52pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/16 "2020-05-27T14:52:38Z")

</div>

Now I am doing that.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:52pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/17 "2020-05-27T14:52:53Z")

</div>

Did it work if it does i will delete it

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:54pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/18 "2020-05-27T14:54:18Z")

</div>

i didnt did it?(20 chars)

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:54pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/19 "2020-05-27T14:54:31Z")

</div>

> [@Jeremy\_Yu](#):
>
> ```python
> # Welcome to Gridmancer!
> # A relic of days long past, the puzzle returns!
> # Your task is to collect all the coins.
> # You are given special methods to help with this task.
> # this.addRect(x, y, w, h) places a rectangle to collect coins.
> # this.removeRect(x, y) removes a previously added rectangle at the point.
> # this.navGrid is (basically) a 2-dimensional array containing "Coin" or "Wall"
> # You must collect all coins under rectangles
> # Rectangles cannot collide with themselves or walls
> # You need to make at most 55 rectangles to beat this level!
> array_greed = hero.navGrid
> 
> def getRectngle(index1, index2):
> width = 0
> height = 0
> if array_greed[index1][index2] == 'Coin':
> indy = index2
> indx = index1
> for x in range(indx, lenght_xy):
> if array_greed[x][indy] == 'Coin':
> width = width + 1
> else:
> break
> for y in range(indy, lenght_xy):
> width_tmp = 0
> for x in range(indx, lenght_xy):
> width_tmp = width_tmp + 1
> # hero.debug(x+'_'+y+'_'+array_greed[x][y])
> if array_greed[x][y] != 'Coin':
> return_object = {'x': index1, 'y': index2, 'width': width, 'height': height}
> return return_object
> elif (width_tmp >= width):
> height = height + 1
> break
> return_object = {'x': index1, 'y': index2, 'width': width, 'height': height}
> return return_object
> else:
> return None
> # return {x:,y:,w:,h:}
> 
> rect = [] # {x, y, w, h}
> lenght_xy = 20
> for x in range(lenght_xy):
> for y in range(lenght_xy):
> rectg = getRectngle(x, y)
> if rectg:
> # hero.say([rectg.x, rectg.y, rectg.width, rectg.height])
> rect.push(rectg)
> for xi in range(rectg.x, rectg.x + rectg.width):
> for yi in range(rectg.y, rectg.y + rectg.height):
> array_greed[xi][yi] = 'Got'
> # hero.say(xi+'_'+yi+'_'+array_greed[xi][yi])
> # hero.say(array_greed[0])
> # hero.say([rect[0].x, rect[0].y, rect[0].width, rect[0].height])
> index = 0
> break_i = 56
> for rec in rect:
> hero.addRect(rec.x, rec.y, rec.width, rec.height)
> if break_i == index:
> hero.say([rect[index].x, rect[index].y, rect[index].width, rect[index].height])
> break
> index = index + 1
> # hero.addRect(0, 0, 4, 3
> 
> ```

It works. Please delete it. Thanks for help, but I want to learn the strategy myself with my own code.

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:54pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/20 "2020-05-27T14:54:37Z")

</div>

did it work it failed right?

---

<div class="post-metadata">

**Author:** ![AnSeDra](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/ansedra/32/13123_2.png) [@AnSeDra](https://discourse.codecombat.com/u/AnSeDra)\
**Post date:** [May 27, 2020, 2:55pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/21 "2020-05-27T14:55:09Z")

</div>

It worked the one you sent me

---

<div class="post-metadata">

**Author:** ![Jeremy\_Yu](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/jeremy_yu/32/12445_2.png) [@Jeremy\_Yu](https://discourse.codecombat.com/u/Jeremy_Yu)\
**Post date:** [May 27, 2020, 2:55pm UTC](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842/22 "2020-05-27T14:55:21Z")

</div>

ok i deleted u delete yours

[Next page](https://discourse.codecombat.com/t/help-on-gridmancer-redux/21842.md?page=2)
