[ 알고리즘 ]/Brute Force

    [백준] 1759. 암호 만들기

    📌문제 https://www.acmicpc.net/problem/1759 🎖️난이도 ✔️풀이 from itertools import combinations L, _ = map(int, input().split()) str_list = input().split() result_list = [] def isPossible(comb): if len(set(comb) & set(('a', 'e', 'i', 'o', 'u')))!= 0 and len(set(comb) - set(('a', 'e', 'i', 'o', 'u')))>=2: return True return False for comb in combinations(str_list, L): if isPossible(comb): result_list.appe..

    [프로그래머스] 두 개 뽑아서 더하기

    📌문제 https://programmers.co.kr/learn/courses/30/lessons/68644 🎖️난이도 Level 1 ✔️풀이 # sol1 from itertools import combinations def solution(numbers): arr = set() for comb in combinations(numbers, 2): arr.add(comb[0] + comb[1]) return sorted(list(arr)) solution([2,1,3,4,1]) # [2, 3, 4, 5, 6, 7] # sol2 def solution(numbers): arr = set() for i in range(len(numbers)): for j in range(i+1, len(numbers)): a..

    [프로그래머스] 카펫

    📌문제 https://programmers.co.kr/learn/courses/30/lessons/42842 🎖️난이도 Level 2 ✔️풀이 # sol1 def solution(brown, yellow): import math t = brown + yellow m = math.ceil(math.sqrt(t)) for i in range(m, t+1): if t % i != 0: continue tmp = [i, t//i] # [w, h] if brown == (i + t//i) * 2 - 4: return tmp # sol2) 근의 공식 이용 (2차 방정식의 해) def solution(brown, yellow): import math w = ((brown+4)/2 + math.sqrt(((brown+..

    [프로그래머스] 소수 찾기

    📌문제 https://programmers.co.kr/learn/courses/30/lessons/42839 🎖️난이도 Level 2 ✔️풀이 # sol1 def isPrime(a): if(a {} : dic 초기화! for i in range(l): per_set.update(set(map(int, map(''.join, itertools.permutations(numbers_list, i+1))))) print(per_set) cnt = 0 for item in per_set: if (isPrime(item)): cnt += 1 return cnt # sol2) math.ceil(), math.sqrt() 이용 => 시간 단축! import itertools import math def isPrime..

    [프로그래머스] 모의고사

    📌문제 https://programmers.co.kr/learn/courses/30/lessons/42840 🎖️난이도 Level 1 ✔️풀이 # sol1 def solution(answers): one = [1,2,3,4,5] * 2000 two = [2,1,2,3,2,4,2,5] * 1250 three = [3,3,1,1,2,2,4,4,5,5] * 1000 scores = [0, 0, 0] l = len(answers) for i in range(l): if answers[i] == one[i]: scores[0] += 1 if answers[i] == two[i]: scores[1] += 1 if answers[i] == three[i]: scores[2] += 1 tmp_max = max(scor..