# \[SOLVED\] Mad Maxer Gets Greedy (python)

**URL:** <https://discourse.codecombat.com/t/solved-mad-maxer-gets-greedy-python/29809>\
**Category:** Level Help\
**Created:** [July 29, 2021, 2:51am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-gets-greedy-python/29809 "2021-07-29T02:51:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [July 29, 2021, 2:51am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-gets-greedy-python/29809/1 "2021-07-29T02:51:14Z")

</div>

```python
while True:
    bestCoin = None
    maxRating = 0
    coinIndex = 0
    coins = hero.findItems()
    # Try calculating "value / distance" to decide which coins to get.
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if coin:
            distance = hero.distanceTo(coin)
            if coin.value < maxRating:
                maxRating = coin.value / distance
                bestCoin = coin
        coinIndex += 1
        pass
    if bestCoin:
        pos = bestCoin.pos
        hero.move(pos)

```

So the only problem, is move() doesn’t work.  
Help greatly appreciated  
Here is [linkity link](https://codecombat.com/play/level/mad-maxer-gets-greedy?)

---

<div class="post-metadata">

**Author:** ![Hydrobolic](https://avatars.discourse-cdn.com/v4/letter/h/e47c2d/32.png) [@Hydrobolic](https://discourse.codecombat.com/u/Hydrobolic)\
**Post date:** [July 29, 2021, 8:10pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-gets-greedy-python/29809/2 "2021-07-29T20:10:58Z")

</div>

> `if coin.value < maxRating:`

You are comparing `coin.value`, the worth of the coin, to `maxRating`, which represents the value / distance of another coin. Comparing variables representing different types of values doesn’t make sense!

Try `if coin.value / distance > maxRating:`

---

<div class="post-metadata">

**Author:** ![Lydia\_Song](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/lydia_song/32/31461_2.png) [@Lydia\_Song](https://discourse.codecombat.com/u/Lydia_Song)\
**Post date:** [July 29, 2021, 8:14pm UTC](https://discourse.codecombat.com/t/solved-mad-maxer-gets-greedy-python/29809/3 "2021-07-29T20:14:55Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/2X/a/a9445509d1a758c41b5ddcddc8c8e20a5dedb67f.png) [@system](https://discourse.codecombat.com/u/system)\
**Post date:** [July 30, 2021, 8:15am UTC](https://discourse.codecombat.com/t/solved-mad-maxer-gets-greedy-python/29809/4 "2021-07-30T08:15:36Z")

</div>

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.
