검색 데이터 - 기본 코드 및 알고리즘 연습/Codewar (13) 썸네일형 리스트형 [Codewars] Kebabize Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com ▶ 문제 : ▶ 내 답안 : import re def kebabize(string): string = re.sub('[0-9]','',string) a = set([0]+[i for i in range(len(string)) if string[i] != string.lower()[i]]+[len(string)]) b = sorted(list(a)) c = [] for i.. [Codewars] Integers: Recreation One ▶ 문제 : ▶ 내 답안 : import math def list_squared(m, n): result = [] for i in range(m,n+1) : a = [ v for v in range(1, int(math.sqrt(i))+1) if i%v ==0 ] b = [ int(i/v) for v in range(1, int(math.sqrt(i))+1) if i%v ==0 ] c = list(set(a + b)) sq_sum = sum([math.pow(v,2) for v in c]) if math.sqrt(sq_sum) % 1 == 0 : result.append([i,int(sq_sum)]) return result - N의 모든 약수를 탐색하는 시간(이중 for문의 시간 복잡도) : O(N) .. [Codewars] Build Tower Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com ▶ 문제 : ▶ 내 답안 : def tower_builder(n_floors): b = [ '*' + '*'*(2*i) for i in range(n_floors)] for i, v in enumerate(b) : b[i] = ' '*int((len(b[-1])-len(v))/2) + v + ' '*int((len(b[-1])-len(v))/2) return b ▶ 모범.. [Codewars] A Rule of Divisibility by 13 Codewars: Achieve mastery through challenge Codewars is where developers achieve code mastery through challenge. Train on kata in the dojo and reach your highest potential. www.codewars.com ▶ 문제 : ▶ 내 답안 : def thirt(n): def sum_n(num) : return sum([int(v)*((10**i)%13) for i,v in enumerate(str(num)[::-1])]) while True : n = sum_n(n) if n == sum_n(n) : return n break ▶ 모범답안 : array = [1, 10, 9, 12.. [Codewars] String incrementer ▶ 문제 : ▶ 내 답안 : def increment_string(string): if string == "": return "1" try: if len(str(int(string)+1)) > len(string): return str(int(string) + 1) else: return "0"*(len(string) - len(str(int(string)+1))) + str(int(string)+1) except: for i, v in enumerate(string[::-1]): if v not in [str(x) for x in range(10)]: break org_str=string[:-i] if org_str == "" : return string + "1" else : org_num=strin.. 이전 1 2 다음