This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def is_prime_num(num) : | |
for i in range(2, int(num**0.5) + 1): | |
if num % i==0: | |
return False | |
return True | |
def sum_prime_nums(range_to) : | |
prime_sum = 2+3+5+7 | |
for num in range(7, range_to+1) : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def classify_nums(nums) : | |
arr = [0]*20*20 | |
i = 1 | |
while i < len(nums) : | |
for j in range(0, len(arr)) : | |
arr[j] = nums[i : i+2] | |
i += 3 | |
return arr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
import time | |
#def cal_triangle_num(seq) : | |
# triangle_num = int((seq*(seq+1))/2) | |
# return triangle_num | |
#def cal_factors(triangle_num) : | |
# arr = [1, triangle_num] | |
# for i in range(1, triangle_num+1) : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def plus_all_num(str_num) : | |
sum = 0 | |
for i in range(1, 101): | |
sum += int(str_num.split('\n')[i]) | |
return sum | |
a = """ | |
37107287533902102798797998220837590246510135740250 | |
46376937677490009712648124896970078050417018260538 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def cal_hailstone_sequence(num) : | |
seq = 0 | |
while num > 1 : | |
if num % 2 == 0 : | |
num = num / 2 | |
else : | |
num = 3*num + 1 | |
seq += 1 | |
return seq+1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def cal_number_of_case(range_to) : | |
pre_case = [1]*range_to | |
next_case = [1]*range_to | |
while pre_case[1] < range_to : | |
for i in range(1, range_to) : | |
next_case[i] = next_case[i-1] + pre_case[i] | |
pre_case = next_case | |
return next_case[-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
import math | |
def cal_digit(x, y) : | |
num = pow(x, y) | |
digit_sum = 0 | |
for i in list(str(num)) : | |
digit_sum += int(i) | |
return digit_sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
import re | |
def make_arr(triangle_nums) : | |
arr = triangle_nums.split('\n') | |
new_arr = [] | |
for i in range(len(arr)) : | |
new_arr.append(re.findall("\d+", arr[i])) | |
return new_arr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
import math | |
def sum_factorial(num) : | |
facto = math.factorial(num) | |
facto_arr = list(str(facto)) | |
facto_sum = sum(int(i) for i in facto_arr) | |
return facto_sum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python3 | |
def d(num) : | |
factors = set([1, num]) | |
for i in range(2, num) : | |
if i in factors : | |
return int(sum(factors)-num) | |
elif num % i == 0 : | |
factors.add(i) | |
factors.add(num/i) | |
return int(sum(factors)-num) |