KATA는 기술과 기술 향상에 초점을 맞춘 코드 챌린지입니다.
일부는 프로그래밍 기본 사항을 교육하는 반면 다른 일부는 복잡한 문제 해결에 중점을 둡니다.
이 용어는 The Pragmatic Programmer 라는 책의 공동 저자인 Dave Thomas 가
무술에서 일본의 카타 개념을 인정하면서 처음 만들어졌습니다.
Dave의 개념 버전은 코드 카타를 프로그래머가
연습과 반복을 통해 기술을 연마하는 데 도움이 되는 프로그래밍 연습으로 정의합니다.
✔️ 제출 쿼리
✔️ 쿼리 분석
SELECT COUNT(NAME)
FROM CITY
WHERE POPULATION > 100000
✔️ 제출 코드
✔️ 코드 분석
def solution(clothes):
# 종류별 의상 갯수를 담는 딕셔너리 생성
clothes_dict = {}
# clothes 배열에서 뒤에 담긴 종류를 비교
for name, kind in clothes:
# clothes_dict에 kind가 있으면 1 증가
if kind in clothes_dict:
clothes_dict[kind] += 1
# clothes_dict에 kind가 없으면
# kind를 키, 1을 값으로 하여 딕셔너리에 추가
else:
clothes_dict[kind] = 1
# 경우의 수 계산
combinations = 1
for count in clothes_dict.values():
combinations *= (count + 1)
# 해당 종류를 입지 않는 경우 추가
# 아무것도 입지 않는 경우 제외
return combinations - 1
PYTHON
경우의 수 계산
# 테스트 데이터
clothes = [
["yellow_hat", "headgear"],
["blue_sunglasses", "eyewear"],
["green_turban", "headgear"]
]
def solution(clothes):
# 1 : 종류별 의상 갯수를 담는 딕셔너리
clothes_dict = {}
for name, kind in clothes:
if kind in clothes_dict:
clothes_dict[kind] += 1
else:
clothes_dict[kind] = 1
# 1 결과 :
clothes_dict = {
"headgear": 2, # yellow_hat, green_turban
"eyewear": 1 # blue_sunglasses
}
# 2 : 경우의 수 계산
combinations = 1 # 곱셈을 위해 초기값 1 세팅
for count in clothes_dict.values():
combinations *= (count + 1)
# 2 과정 :
headgear의 경우의 수 :
의상 개수 : 2
경우의 수 : 2 + 1 = 3
(yellow_hat, green_turban, 아무것도 입지 않음)
eyewear의 경우의 수 :
의상 개수 : 1
경우의 수 : 1 + 1 = 2
(blue_sunglasses, 아무것도 입지 않음)
# 2 결과 :
루프를 통해 각 종류별 경우의 수를 모두 곱하기 :
첫 번째 반복 :
combinations *= (2 + 1) -> combinations = 1 * 3 = 3
두 번째 반복 :
combinations *= (1 + 1) -> combinations = 3 * 2 = 6
return combinations - 1
# 아무것도 입지 않는 경우의 수 1 빼주기