Created
April 7, 2022 15:30
-
-
Save jsrimr/d9d004a558e0eb1dca3ca31c911af040 to your computer and use it in GitHub Desktop.
https://programmers.co.kr/learn/courses/30/lessons/72415 풀라고 시도한 코드. 얼개는 짜놓았으나 이미 45분 지난 상태에서 compute_needed_move 구현하려니 도저히 안되겠어서 포기. permuation 이용하기 전에는 dfs 하려 했으나 어차피 필요한 순열 몇개 안되는 거 같아서 그냥 순열을 박아놓음
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import permutations | |
def solution(board, r, c): | |
answer = float('inf') | |
n_set = set() | |
for row in board: | |
for el in row: | |
n_set.add(el) | |
def compute_needed_move(dst, r,c): | |
pass | |
def find_el_from_board(target, board): | |
loc_list = [] | |
for i, row in enumerate(board): | |
for j, el in enumerate(row): | |
if el == target: | |
loc_list.append((i,j)) | |
return loc_list | |
def compute_n_move(order, r, c, copied_board): | |
n_move = 0 | |
for el in order: | |
card1_loc, card2_loc = find_el_from_board(el, copied_board) | |
card1_needed_move = compute_needed_move(card1_loc, r, c) | |
card2_needed_move = compute_needed_move(card2_loc, r, c) | |
if card1_needed_move <= card2_needed_move: | |
move1 = card1_needed_move | |
r,c = card1_loc | |
else: | |
move1 = card2_needed_move | |
r,c = card2_loc | |
_, move2 = compute_needed_move() | |
n_move += (move1 + move2 + 2) | |
copied_board[card1_loc] = 0 | |
copied_board[card2_loc] = 0 | |
return n_move | |
for search_order in permutations(n_set, 4): | |
cur_move = compute_n_move(search_order,r,c) | |
answer = min(answer, cur_move) | |
return answer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
위에거 완성한건데 그래도 실패하는 케이스들이 있음 ㅠ