물음표 살인마의 개발블로그

알고리즘 문제/CodeWar

Find the Mine!

BEstyle 2022. 11. 14. 13:12

DESCRIPTION:

You've just discovered a square (NxN) field and you notice a warning sign. The sign states that there's a single bomb in the 2D grid-like field in front of you.

Write a function mineLocation/MineLocation that accepts a 2D array, and returns the location of the mine. The mine is represented as the integer 1 in the 2D array. Areas in the 2D array that are not the mine will be represented as 0s.

The location returned should be an array (Tuple<int, int> in C#) where the first element is the row index, and the second element is the column index of the bomb location (both should be 0 based). All 2D arrays passed into your function will be square (NxN), and there will only be one mine in the array.

Examples:

mineLocation( [ [1, 0, 0], [0, 0, 0], [0, 0, 0] ] ) => returns [0, 0]
mineLocation( [ [0, 0, 0], [0, 1, 0], [0, 0, 0] ] ) => returns [1, 1]
mineLocation( [ [0, 0, 0], [0, 0, 0], [0, 1, 0] ] ) => returns [2, 1]

 


def mineLocation(f):
    l=len(f)
    for i in range(l):
        for j in range(l):
            if f[i][j]==1:
                return [i,j]

'알고리즘 문제 > CodeWar' 카테고리의 다른 글

First Character that repeats  (0) 2022.11.15
Row Of The Odd Triangle  (0) 2022.11.15
Sequences and Series  (0) 2022.11.14
Remove the Parentheses  (0) 2022.11.10
Simple Frequency Sort  (0) 2022.11.10