# 두 배열의 최댓값 구하기
def max_value(left_array, right_array);
new_list = list()
for i in left_array :
for j in right_array :
new_list.append(i*j)
#maxvalue = max(maxvalue, i*j)
#max 함수에 두가지 파라미터를 넣어서 두 값을 비교해 더 큰 값 구하기
return max(new_list)
#return maxvalue
print(max_value([9,-6,5],[-4,3,8])
#두 지점 사이의 최소 거리 구하기
#sqrt함수
from math import sqrt
def distance(store1, store2):
return sqrt((store1[0] - store2[0]) ** 2 + (store1[1] - store2[1]) ** 2)
def min_distance(my_location) :
min_value = distance(my_location[0], my_location[1])
min_list = [ my_location[0], my_location[1] ]
for i in my_location :
for j in my_location :
if distance(i,j) < min_value and distance(i,j) != 0 :
min_value = distance(i,j)
min_list = [ i,j ]
retrun min_list
my_location = [(2, 3), (12, 30), (40, 50), (5, 1), (12, 10), (3, 4)]
print(min_distance(my_location))
for i in range(len(my_location)-1)) :
for j in range( i+1, len(my_location ) :
if min_value > distance( my_location[i], my_location[j] ) :
my_list = [ my_location[i], my_location[j] ]
< sqrt 함수 >
math 라이브러리를 import 해줘야 사용가능
math.sqrt(a) : a의 제곱급을 반환 ( 루트a )
* sqrt 함수의 반환타입은 float
* a의 값이 음수일 경우 에러
'Python > 알고리즘' 카테고리의 다른 글
| [ Python_알고리즘 ] 분할정복법 ② 퀵 정렬 (0) | 2021.12.21 |
|---|---|
| [ Python_알고리즘 ] 분할정복법 ① 합병 정렬 (0) | 2021.12.20 |
| [ Python_알고리즘 ] 이진 탐색 재귀 함수 (0) | 2021.12.18 |
| [ Python_알고리즘 ] 리스트 뒤집기 (0) | 2021.12.18 |
| [ Python_알고리즘 ] 자릿 수 합 (0) | 2021.12.17 |