diff --git a/argorithm/balanced_array.py b/argorithm/balanced_array.py new file mode 100644 index 0000000..4a383e8 --- /dev/null +++ b/argorithm/balanced_array.py @@ -0,0 +1,12 @@ +def balanced_sum(arr): + size = arr.pop(0) + for i in range(size): + # print('arr[:i+1]: ', arr[:i+1]) + # print('arr[-(len(arr)-i):]: ', arr[-(len(arr)-i):]) + if sum(arr[:i+1]) == sum(arr[-(len(arr)-i):]): + return i + + +if __name__ == '__main__': + real_answer = balanced_sum([4, 1, 2, 3, 3]) + print(real_answer) diff --git a/argorithm/last_and_second-last.py b/argorithm/last_and_second-last.py new file mode 100644 index 0000000..b2b630d --- /dev/null +++ b/argorithm/last_and_second-last.py @@ -0,0 +1,8 @@ +def lastLetters(word): + str_to_list = list(word)[-2:] + return ' '.join(str_to_list[::-1]) + + +if __name__ == '__main__': + real_answer = lastLetters('bat') + print(real_answer) diff --git a/argorithm/prime_or_not.py b/argorithm/prime_or_not.py new file mode 100644 index 0000000..0a7b6ad --- /dev/null +++ b/argorithm/prime_or_not.py @@ -0,0 +1,22 @@ +''' +문제 : +주어진 숫자가 소수 일 경우 1을 return +소수가 아닐 경우 약수 중 1을 제외한 가장 작은 숫자 return + +아직 푸는중임!~!!!! +''' + +def is_prime(n): + answer = [] + for i in range(2, n): + if n % i == 0: + answer.append(i) + n = n//i + else: + return 1 + return min(answer) + + +if __name__ == '__main__': + real_answer = is_prime(24) + print(real_answer)