# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(X, Y, D):
# write your code in Python 3.6
# step 1 - 방정식 문제로 풀 수 있겠다
########################
# frog X >= frog Y
# a를 구하면 되는 문제
# X+a*D >= Y
# a*D >= Y - X
# a >= (Y - X)/D
# ex) (85 - 10)/30
# ex) (75)/30 = 2.5
########################
a = (Y - X) / D
# 딱 맞아떨어지면, int() 내장 함수를 써서, 2.0 -> 2로 변환 후 반환해줌
if a % 1 == 0:
return int(a)
# 2.4 이렇게 소수로 떨어지면 int()를 통해 정수로 변환하는 '버림'을 하고 2로 만든 후 +1 해서 반환
else:
return int(tmp) + 1
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A):
# write your code in Python 3.6
# step 1 - make a dictionary
dict_= {}
# step 2 - fill the dictionary
for i in A:
try:
dict_[i] += 1
except:
dict_[i] =1
# step 3 - find the odd value
for i in dict_:
if dict_[i] % 2 == 1:
return i
pass
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, K):
# write your code in Python 3.6
# step 1 - take input A,K
# already succeed
# step 2 - create new array
arr_ = list(range(len(A)))
# step 3 - take iteration to solve the prob
for i in range(len(A)):
arr_[(i+K)%len(A)] = A[i]
return arr_
pass
def solution(N):
# write your code in Python 3.6
binary_num = bin(N)
arr_ = []
for i in range(2,len(binary_num)):
if binary_num[i] == '1':
arr_.append(i)
arr2_ = []
for i in range(0,len(arr_)):
if i != len(arr_) - 1:
tmp = arr_[i+1] - arr_[i]
tmp = tmp - 1
arr2_.append(tmp)
if len(arr2_) == 0:
return 0
else:
return max(arr2_)
pass
# 신경망 학습하기
- 이제 재미있는 부분이 시작됩니다. 단순히 데이터를 반복해서 신경망에 입력으로 제공하고, 최적화(Optimize)만 하면 됩니다.
a = 0 for epoch in range(1): # 데이터셋을 수차례 반복합니다.
running_loss = 0.0
for i, data in enumerate(train_loader, 0):
# [inputs, labels]의 목록인 data로부터 입력을 받은 후;
inputs, labels = data
# 변화도(Gradient) 매개변수를 0으로 만들고
optimizer.zero_grad()
# 순전파 + 역전파 + 최적화를 한 후
outputs = net(inputs)
loss = criterion(outputs, labels)
loss.backward()
optimizer.step()
# 통계를 출력합니다.
running_loss += loss.item()
if i % 1000 == 999: # print every 2000 mini-batches
print('[%d, %5d] loss: %.3f' %
(epoch + 1, i + 1, running_loss / 1000))
running_loss = 0.0
a = a + 1
if a == 30000:
break