Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 |
Tags
- Numpy
- Linux
- C
- 핑거스타일
- mysql
- VS Code
- windows forms
- 오류
- ubuntu
- paramiko
- pip
- Visual Studio
- Python
- YOLO
- SSH
- pandas
- label
- 채보
- 기타 연주
- error
- Docker
- 컨테이너
- C#
- OpenCV
- Selenium
- nvidia-smi
- pytorch
- C++
- JSON
- 프로그래머스
Archives
- Today
- Total
기계는 거짓말하지 않는다
Python 순열 (Permutation) 구현 본문
Python에서 재귀함수를 이용한 순열 (Permutation)이다.
def swap(arr, i1, i2):
temp = arr[i1]
arr[i1] = arr[i2]
arr[i2] = temp
def permutation(arr, depth, n, r):
count = 0
if depth == r:
for i in arr:
print(i, end="")
print("")
return 1
for i in range(depth, n):
swap(arr, depth, i)
count += permutation(arr, depth + 1, n, r)
swap(arr, depth, i)
return count
arr = ["A", "B", "C", "D"]
count = permutation(arr, 0, 4, 2)
print(count)

'Python' 카테고리의 다른 글
| Python String u'\ufeff' (0) | 2023.04.21 |
|---|---|
| Python operator itemgetter, attrgetter (0) | 2023.04.15 |
| Python Module 'ffmpeg' has no attribute 'probe' 오류 (0) | 2023.04.09 |
| Python stacktrace 출력 traceback module (0) | 2023.04.09 |
| Python pymysql cursor DB 값 변경 인식 불가 (0) | 2023.04.01 |
Comments
