전체 글 216

[16일차][프로그래머스][2019 카카오 - 64061]크레인 인형뽑기 게임

def solution(board, moves): doll_location = { i+1 : [] for i in range(len(board)) } doll_arr = [] result = 0 for i in range(len(board)): for j in range(len(board[i])): if board[i][j] != 0: doll_location[j+1] = [board[i][j]] + doll_location[j+1] for move in moves: doll_len = len(doll_location[move]) if doll_len != 0: if len(doll_arr) != 0: if doll_arr[-1:][0] == doll_location[move][doll_len-1:][0..

[15일차][프로그래머스][2020 카카오 - 67256]키패드 누르기

def solution(numbers, hand): standard = 12 numbers_location = {} left_default_location = [1, 4, 7] right_default_location = [3, 6, 9] left_location = [0, 3] right_location = [2, 3] x_count = 0 y_count = 0 result = [] for idx in range(standard): if idx !=0 and int(idx) % 3 == 0: x_count = 0 y_count = y_count + 1 numbers_location[idx+1] = [x_count, y_count] x_count = x_count + 1 else: if idx+1 != ..

[14일차][프로그래머스][160586]대충 만든 자판

def solution(keymap, targets): answer = [] keymap_obj = {} for keys in keymap: for idx, key in enumerate(keys): if key not in keymap_obj: keymap_obj[key] = int(idx) + 1 else: keymap_obj[key] = min(int(keymap_obj[key]), int(idx + 1)) for idx, target in enumerate(targets): count = 0 for char in target: if char not in keymap_obj: count = -1 break else: count = count + keymap_obj[char] answer.append..

[13일차][프로그래머스][2021 카카오 - 72410]신규 아이디 추천

import re def solution(new_id): #1. new_id 대문자 -> 소문자 new_id = new_id.lower() #2. 알파벳 소문자, 숫자, -, _, . 제외한 나머지 모든 문자 제거 new_id = re.sub("[^a-z0-9-_.]", '', new_id) #3. .. = 16: new_id = new_id[0:15].strip('.') #7. new_id의 길이가 2자 이하이면 3이 될때까지 new_id의 끝문자를 반복해서 붙인다. while len(new_id)

[11일차][프로그래머스][2022 카카오 - 118666]성격유형 검사하기

def solution(survey, choices): standard = 4 preData = '' answer = '' character_list = { 'R' : 0, 'T' : 0, 'C' : 0, 'F' : 0, 'J' : 0, 'M' : 0, 'A' : 0, 'N' : 0, } for idx, data in enumerate(survey): choice = choices[idx] if int(choice) > int(standard): character_list[data[1]] = int(character_list[data[1]]) + int(choice) - int(standard) else: character_list[data[0]] = int(character_list[data[0]]) ..

[10일차][프로그래머스][161990]바탕화면 정리

def solution(wallpaper): wallpaper_max_x = len(wallpaper[0]) wallpaper_max_y = len(wallpaper) file_path_y = [] file_path_x = [] for wallpaper_y, data in enumerate(wallpaper): for wallpaper_x, val in enumerate(data): if val == '#': file_path_y.append(wallpaper_y + 1) file_path_x.append(wallpaper_x + 1) file_path_y_max, file_path_y_min = max(file_path_y), min(file_path_y) file_path_x_max, file_pat..

[9일차][프로그래머스][2023 카카오 - 150370]개인정보 수집 유효성 검사

def timestamp_create(year, month, day): timestamp_today = (int(year) * 12 * 28) + (int(month) * 28) + (int(day)) return timestamp_today def solution(today, terms, privacies): # timestamp로 비교 year, month, day = today.split('.') timestamp_today = timestamp_create(year, month, day) terms_obj = { data.split(' ')[0] : data.split(' ')[1] for data in terms } answer = [] for idx, data in enumerate(priva..

[8일차][프로그래머스][178871]달리기 경주

from collections import Counter def solution(players, callings): play_check = {player: i for i, player in enumerate(players)} idx_play_check = {i:player for i, player in enumerate(players)} for data in callings: # 현재 선수의 위치 now_idx = play_check[data] # 현재 선수 앞의 선수 위치 pre_idx = now_idx-1 # 현재 선수가 앞에 등수로 바뀌고, 앞에 선수가 뒷 등수가 된다. play_check[data] = pre_idx play_check[idx_play_check[pre_idx]] = now_idx..