[SOLVED] Help with Golden Mirage


#1

Hey everyone,
I’ve been stuck on golden mirage (https://codecombat.com/play/level/golden-mirage?) for a while now but I’m stumped, I could do the levels i the mountain before it fine but I can’t seem to do this one.
Here’s my current code:

while True:
    coins = hero.findItems()
    fakeCoins = []
    realCoins = []
    for coin in coins:
        for coin2 in coins:
            if coin2.value == coin.value:
                fakeCoins.append(coin)
            else:
                continue
        if not coin in fakeCoins:
            realCoins.append(coin)
    nearCoin = hero.findNearest(realCoins)
    if nearCoin:
        hero.move(nearCoin.pos)

It doensn’t really make sense but I can’t work out how to go about solving it, could anyone give me some hints about what code I should use to solve this level that would be great, Thanks. :grin:


#2

It can’t really work because in that code you’ll end up comparing the same coin with itself so all coins are fake in the end

check the len of fakeCoins
that should give you a hand

for coin in coins:  # lets say coin = 0
        for coin2 in coins: # lets say coin2 = 0
            if coin2.value == coin.value:  # if coins[0].value == coins[0].value
                fakeCoins.append(coin) # put coins[0] in the array.

#3

Thanks so much man, I’ve done the level now, Thanks! That was a really helpful description of the problem and it really cleared it up for me. :hugs: