▷ 오늘 학습 계획: 알고리즘 강의(문풀 4~5)
class NumsSum:
def __init__(self,n1,n2):
self.bigNum = 0
self.smallNum = 0
self.setN1N2(n1,n2)
def setN1N2(self,n1,n2):
self.bigNum = n1
self.smallNum = n2
if n1 < n2:
self.bigNum = n2
self.smallNum = n1
def addNum(self, n):
if n <= 1:
return n
return n+ self.addNum(n-1)
def getTotalResult(self):
return self.addNum(self.bigNum-1) - self.addNum(self.smallNum)

class Top5Players:
def __init__(self, cts, ns):
self.currentScores = cts
self.newScore = ns
def setAlignScore(self):
nearIdx = 0
minNum = 10.0
for i, s in enumerate(self.currentScores):
absNum = abs(self.newScore - s)
if absNum < minNum:
minNum = absNum
nearIdx = i
if self.newScore >= self.currentScores[nearIdx]:
for i in range(len(self.currentScores)-1, nearIdx, -1):
self.currentScores[i] = self.currentScores[i-1]
self.currentScores[nearIdx] = self.newScore
else:
for i in range(len(self.currentScores)-1, nearIdx + 1, -1):
self.currentScores[i] = self.currentScores[i-1]
self.currentScores[nearIdx + 1] = self.newScore
def getFinalScores(self):
return self.currentScores
📝 최댓값, 최솟값, 평균 알고리즘은 이해가 잘 됐다. 한 문제에서 여러 개의 알고리즘을 적용해야 될 때 모듈도 많아져서 복잡해 보였지만 차근차근 이해할 수 있었다. 강의 들으면서 함수, 클래스 생성을 자주 하다보니까 더 익숙해졌는데 그래도 알고리즘은 어렵다.
▷ 내일 학습 계획: 파이썬 프로그래밍 테스트