머리가 안 돈다... 빡친다... 프로그래밍을 하도 안해서 그런지, 논리나 수치적으로 100% 이해하고 코딩을 하는게 아니라, 그냥 대충 직관으로 끄적이는 느낌이 많이 든다.
무슨 문제인지는 알겠는데, 이 얕은 느낌,,, lv1인데 ㅋㅋㅋ
1차원적인 논리만 생각할 줄 알고, 여러개 축으로 시나리오로 생각할 줄 모르는 이 느낌은 여전하구나.
논리를 먼저 쌓고 코드를 쓰는게 아니라, "아, 대충 이런 시나리오겠구나"하고 직관을 먼저 써서 코드를 쓰고, 논리는 사후적으로 잡는 느낌 같다.. 이러다보니 논리적으로 완결성이 안갖춰지면 상당히 찝찝하다
사고의 가지치기, 구조화가 구석구석, 디테일하게, 적극적으로 증명이 안되는 느낌이 싫다.
def solution(video_len, pos, op_start, op_end, commands):
def time_to_sec(time):
m, s = map(int, time.split(":"))
sec = m*60+s
return sec
def sec_to_time(sec):
m = sec // 60
s = sec % 60
return f"{m}:{s}"
result = time_to_sec("00:00")
### binding
start = time_to_sec(op_start)
end = time_to_sec(op_end)
T = time_to_sec(video_len)
t = time_to_sec(pos)
for i in commands:
# 10초 전 이동
if i == "prev":
if t < 10:
result = time_to_sec("00:00")
else:
result = t-time_to_sec("00:10")
# 10초 후 이동
elif i == "next":
if T-t < time_to_sec("00:10"):
return T
else:
result = t+time_to_sec("00:10")
# 모든 명령을 실행했음에도 여전히 오프닝 구간이라면, opening skip 처리
elif start <= t <= end:
result = end
result = sec_to_time(result)
return result
가장 비슷한 접근법으로 풀이하신 분들을 참고해보면 아래와 같다
def time_to_seconds(time_str):
minutes, seconds = map(int, time_str.split(':'))
return minutes * 60 + seconds
def seconds_to_time(seconds):
minutes, seconds = divmod(seconds, 60)
return f"{minutes:02d}:{seconds:02d}"
def solution(video_len, pos, op_start, op_end, commands):
video_len = time_to_seconds(video_len)
current_pos = time_to_seconds(pos)
op_start = time_to_seconds(op_start)
op_end = time_to_seconds(op_end)
for command in commands:
if op_start <= current_pos <= op_end:
current_pos = op_end
if command == "prev":
current_pos = max(0, current_pos - 10)
elif command == "next":
current_pos = min(video_len, current_pos + 10)
# 마지막 명령 실행 후 한 번 더 오프닝 체크
if op_start <= current_pos <= op_end:
current_pos = op_end
return seconds_to_time(current_pos)
```