전체 글
-
프로그래머스 / 햄버거 만들기코딩 테스트/Level 1 2022. 10. 27. 23:25
https://school.programmers.co.kr/learn/courses/30/lessons/133502 파이썬 def solution(ingredient): stack = [] answer = 0 for each in ingredient: stack.append(each) if stack[-4:] == [1, 2, 3, 1]: answer += 1 del stack[-4:] return answer 코틀린 class Solution { fun solution(ingredient: IntArray): Int { var answer = 0 val bugger = listOf(1, 2, 3, 1) val stack = mutableListOf() for (each in ingredient) { s..
-
프로그래머스 / 옹알이 (2)코딩 테스트/Level 1 2022. 10. 27. 23:16
https://school.programmers.co.kr/learn/courses/30/lessons/133499 파이썬 def solution(babbling): answer = 0 for each in babbling: for index, text in enumerate(("aya", "ye", "woo", "ma")): each = each.replace(text, str(index)) if each.isdigit(): if '00' not in each: if '11' not in each: if '22' not in each: if '33' not in each: answer += 1 return answer 코틀린 class Solution { fun solution(babbling: Arr..
-
프로그래머스 / 콜라 문제코딩 테스트/Level 1 2022. 10. 27. 23:15
https://school.programmers.co.kr/learn/courses/30/lessons/132267 파이썬 def solution(a, b, n): answer = 0 while n >= a: quotient = n // a # 몫 new_bottle = quotient * b # 새 콜라 n -= a * quotient # 마트에 가져다 준 빈 병 answer += new_bottle n += new_bottle return answer import sys sys.setrecursionlimit(10000) def solution(a, b, n): if n < a: return 0 quotient = n // a new_bottle = quotient * b return new_bott..
-
프로그래머스 / 삼총사코딩 테스트/Level 1 2022. 10. 27. 23:14
https://school.programmers.co.kr/learn/courses/30/lessons/131705 파이썬 억지스럽게... from itertools import combinations solution = lambda number: sum(1 for each in combinations(number, 3) if sum(each) == 0) 정상적으로... from itertools import combinations def solution(number): return sum(1 for each in combinations(number, 3) if sum(each) == 0) 코틀린 class Solution { fun solution(number: IntArray): Int { var a..
-
프로그래머스 / 숫자 짝꿍코딩 테스트/Level 1 2022. 10. 27. 23:13
https://school.programmers.co.kr/learn/courses/30/lessons/131128 파이썬 억지스럽게... from collections import Counter solution = lambda num1, num2: ('0' if (result := ''.join(each * inter_n[each] for each in sorted(inter_n, reverse=True)))[0] == '0' else result) if (inter_n := Counter(list(num1)) & Counter(list(num2))) else "-1" 덜 억지스럽게... from collections import Counter def solution(num1, num2): return..
-
파이썬 초기 설정 저장 방식Python/이것저것 파이썬 2022. 10. 25. 13:20
저는 프로그램의 초기 설정들은 저장할 때, pickle을 많이 씁니다. 바이너리 파일이라 유저들이 수정하기 어렵고, 코드는 간결하죠. https://scshim.tistory.com/614 하지만 유저들이 수정하도록 열어두어야할 설정도 있습니다. 이럴 경우에는 ini, json, yaml, xml, toml, py 등을 사용합니다. 가장 많이 알려진 ini 같은 경우는 공식 문서(configparser - 구성 파일 구문 분석기)를 보는 것이 가장 좋습니다. https://docs.python.org/ko/3/library/configparser.html 전체적으론 이런 글을 참고해도 좋겠죠. https://emilkwak.github.io/python-setting-file-ext xml은 공식 문서를..
-
Lxpanel의 CPU 100% 사용Linux/Raspberry Pi OS 2022. 10. 25. 07:06
1. restart 해봅니다. lxpanelctl restart 2. lxpanel 태스크바의 오디오 관련 애플릿이 원인일 수 있습니다. 태스크바에서 오디오 관련 애플릿을 삭제합니다. 3. wifi를 감시하고 있는 lxpanel 태스크바의 Wifi/Network 모니터링 애플릿이 원인일 수 있습니다. 태스크바에서 wifi/네트워크 감시 애플릿을 삭제합니다. https://github.com/raspberrypi/linux/issues/2518
-
100명의 죄수 문제Python/이것저것 파이썬 2022. 10. 17. 12:38
https://www.youtube.com/watch?v=PE4vLbyOgw0 https://www.youtube.com/watch?v=OIi7FCmTtxc from random import shuffle def find_num(): # 죄수 번호가 들어갈 박스 boxes = {} # 죄수 번호(1~100)를 셔플. nums = [i for i in range(1, 101)] shuffle(nums) # 셔플된 죄수 번호를 하나씩 뽑아 박스에 넣는다. for i, num in enumerate(nums): boxes[i + 1] = num # 각 죄수가 방에 들어가 자신의 번호가 매겨진 박스부터 열어본다. for prisoner in range(1, 101): open_num = prisoner for ..