목록Algorithms (64)
from collections import deque gear_list = [] # gear_list[0], gear_list[1], gear_list[2], gear_list[3] for _ in range(4): gear = ' '.join(input()) gear_list.append(deque(map(int, gear.split()))) k = int(input()) options = [] for _ in range(k): options.append(list(map(int, input().split()))) def rotate(gear_list, option): selection = option[0] direction = option[1] present_gear = gear_list[selecti..
https://programmers.co.kr/learn/courses/30/lessons/42842 코딩테스트 연습 - 카펫 Leo는 카펫을 사러 갔다가 아래 그림과 같이 중앙에는 노란색으로 칠해져 있고 테두리 1줄은 갈색으로 칠해져 있는 격자 모양 카펫을 봤습니다. Leo는 집으로 돌아와서 아까 본 카펫의 노란색과 �� programmers.co.kr def solution(brown, yellow): answer = [] n = brown + yellow li = [] for i in range(3,n+1): if n % i == 0: a = i b = n//i if a = v: if (v+2)*(l+2) - yellow == brown: return [l+2, v+2] print(solution(..
https://programmers.co.kr/learn/courses/30/lessons/42841 코딩테스트 연습 - 숫자 야구 [[123, 1, 1], [356, 1, 0], [327, 2, 0], [489, 0, 1]] 2 programmers.co.kr def check_score(question, candidate, s, b): strike = 0 for i in range(len(question)): if question[i] == candidate[i]: strike += 1 if s != strike: return False ball = len(set(question) & set(candidate)) - strike if b != ball: return False return True d..
1. 시작점 x, y 2. 방향 이동 1 (east), 2 (west), 3(north), 4(south) nx, ny 새로 정의 3. 지도 넘는 경우 분류 (지도 넘으면 그대로 있기, 지도 넘지 않는 경우 이동) 4. 이동 방향에 해당 하는 주사위로 주사위 위치 변경 동쪽: east, bottom, west, top = bottom, west, top, east 서쪽: top,south, bottom, north = west, bottom, east, top 북쪽: top, south, bottom, north = south, bottom, north, top 남쪽: top, south, bottom, north = north, top, south, bottom 5. 이동한 위치 값 분류 (0인 경우,..
from itertools import permutations def is_prime(n): li = [True] * (n+1) if n == 0 or n == 1: return False for i in range(2, n+1): if li[i] == True: for j in range(2*i, n+1, i): li[j] = False return li[n] def solution(numbers): answer = 0 numbers = list(numbers) n = len(numbers) for i in range(1, n+1): temp = set(map(''.join, permutations(numbers, i))) for j in temp: j = int(j) n = len(str(j)) if..
완전 탐색 문제 같은 경우 조건에 맞는 모든 순열 혹은 조합을 모두 구해서 체크 1. itertools 모듈 사용 1) 하나의 리스트에서 모든 조합 구하기 from itertools import permutations from itertools import combinations a = [] b = [] items = [1,2,3,4,5] # 모든 경우의 수 1,2 != 2,1 for i in list(permutations(items, 2)): a.append(i) # 뽑기만 하는 경우 1,2 = 2,1 for i in list(combinations(items, 2)): b.append(i) print(a) print(b) --------- [(1, 2), (1, 3), (1, 4), (1, 5), ..