Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

3.2 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68d2ba1468508398389487d0 Challenge 75: Hidden Treasure 29 challenge-75

--description--

Given a 2D array representing a map of the ocean floor that includes a hidden treasure, and an array with the coordinates ([row, column]) for the next dive of your treasure search, return "Empty", "Found", or "Recovered" using the following rules:

  • The given 2D array will contain exactly one unrecovered treasure, which will occupy multiple cells.

  • Each cell in the 2D array will contain one of the following values:

    • "-": No treasure.
    • "O": A part of the treasure that has not been found.
    • "X": A part of the treasure that has already been found.
  • If the dive location has no treasure, return "Empty".

  • If the dive location finds treasure, but at least one other part of the treasure remains unfound, return "Found".

  • If the dive location finds the last unfound part of the treasure, return "Recovered".

For example, given:

[
  [ "-", "X"],
  [ "-", "X"],
  [ "-", "O"]
]

And [2, 1] for the coordinates of the dive location, return "Recovered" because the dive found the last unfound part of the treasure.

--hints--

dive([[ "-", "X"], [ "-", "X"], [ "-", "O"]], [2, 1]) should return "Recovered".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(dive([[ "-", "X"], [ "-", "X"], [ "-", "O"]], [2, 1]), "Recovered")`)
}})

dive([[ "-", "X"], [ "-", "X"], [ "-", "O"]], [2, 0]) should return "Empty".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(dive([[ "-", "X"], [ "-", "X"], [ "-", "O"]], [2, 0]), "Empty")`)
}})

dive([[ "-", "X"], [ "-", "O"], [ "-", "O"]], [1, 1]) should return "Found".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(dive([[ "-", "X"], [ "-", "O"], [ "-", "O"]], [1, 1]), "Found")`)
}})

dive([[ "-", "-", "-"], [ "X", "O", "X"], [ "-", "-", "-"]], [1, 2]) should return "Found".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(dive([[ "-", "-", "-"], [ "X", "O", "X"], [ "-", "-", "-"]], [1, 2]), "Found")`)
}})

dive([[ "-", "-", "-"], [ "-", "-", "-"], [ "O", "X", "X"]], [2, 0]) should return "Recovered".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(dive([[ "-", "-", "-"], [ "-", "-", "-"], [ "O", "X", "X"]], [2, 0]), "Recovered")`)
}})

dive([[ "-", "-", "-"], [ "-", "-", "-"], [ "O", "X", "X"]], [1, 2]) should return "Empty".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(dive([[ "-", "-", "-"], [ "-", "-", "-"], [ "O", "X", "X"]], [1, 2]), "Empty")`)
}})

--seed--

--seed-contents--

def dive(map, coordinates):

    return map

--solutions--

def dive(map, coordinates):
    row, col = coordinates
    target = map[row][col]

    if target == "-":
        return "Empty"

    if target == "O":
        for r in range(len(map)):
            for c in range(len(map[r])):
                if (r != row or c != col) and map[r][c] == "O":
                    return "Found"
        return "Recovered"

    return "Found"