Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

프로그래머스 [2023 KAKAO]. 개인정보 수집 유효기간 #181

Open
hojongs opened this issue Sep 10, 2023 · 0 comments
Open

프로그래머스 [2023 KAKAO]. 개인정보 수집 유효기간 #181

hojongs opened this issue Sep 10, 2023 · 0 comments

Comments

@hojongs
Copy link
Owner

hojongs commented Sep 10, 2023

Problem link

https://school.programmers.co.kr/learn/courses/30/lessons/150370?language=python3

Problem abstraction

문제의 핵심을 요약한다. 체계적인 문제 접근을 위해, 문제를 추상화한다

단순 구현 문제?

적합한 자료구조를 생각한다

Design(Plan) algorithm

# 1

---
# 2

---
# 3

Algorithm idea

추상화한 문제 이해를 기반으로 알고리즘의 대략적인 구현 계획을 서술한다

Pseudo-code

idea를 수도 코드로 작성해본다

today -> 비교할 수 있는 형태로 parse함
terms -> term_type to duration map으로 만들어서 O(1)으로 참조할 수 있도록 함
privacies:

  • 각 elem은 since와 term_type으로 구성됨.
  • term_type을 duration으로 변환.
  • since를 비교할 수 있는 형태로 parse 후, duration을 더함 (due가 됨)

Validate algorithm

알고리즘의 유효 여부를 구현 전에 검증한다

예제 입력을 수도 코드로 계산해보고, 놓친 알고리즘 오류가 있는지 확인한다

python built-in datetime object는 기간 연산을 지원하지 않는다. datetime을 쓸 필요가 없다.

since_month + months_addiation > 12인 경우, year를 비교하려면 올림처리를 먼저 해줘야 한다

y,m,d 각각 비교는 코드도 비교적 길다

Impl

from datetime import datetime


def solution(today, terms, privacies):
    answer = []
    
    today_ymd = list(map(int, today.split('.')))
    today_days = today_ymd[0] * 12 * 28 + today_ymd[1] * 28 + today_ymd[2]
    
    terms_map = {}
    for term in terms:
        term_type, months = term.split()
        terms_map[term_type] = int(months)
    
    for i, privacy in enumerate(privacies):
        since, term_type = privacy.split()
        since_ymd = list(map(int, since.split('.')))
        due_days = since_ymd[0] * 12 * 28 + since_ymd[1] * 28 + since_ymd[2]

        months_addition = terms_map[term_type]
        due_days += months_addition * 28
        
        if due_days <= today_days:
            answer.append(i+1)

    return answer

Self-feedback

구조적 접근: 문제를 추상화하여 구조적으로 접근했는가?

설계를 좀더 검증하고 수도 코드 작성 후 구현하자. 잘못 구현해서 재구현 삽질로 35분씩이나 걸림.

간단한 문제라도, 간단한 예제 입력을 3개 생각해보자.

사고력: 알고리즘을 완전히 이해했는가? (충분한 사고력을 가졌는가?)

구현력: 알고리즘을 신속, 정확하게 구현했는가?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant