[python] 나눗셈 구현 (divide operator with bit-operations)
Data/Text/Knowledge Analysis & Mining/Python 2013. 3. 22. 15:37나눗셈을 구현하기: 몫과 나머지를 구하는 함수를 직접 구현해 본다.
1) 느린 방법: for loop 이용하기
--> 아주 큰 숫자에 대해 너무 느린 문제가 있다.
2) 빠른 방법: bit operation (shift) 이용하여 빠른 버전을 구현할 수 있다.
아래의 두 함수를 비교해 볼 수 있다.
divAndMod( y, x, debug=0) 으로 실행하면 디버그 메시지 없이 볼 수 있습니다.
divAndMod()를 더 최적화할 수 있는 방법을 제시해 주시면 대환영입니다 ^^.
'Data/Text/Knowledge Analysis & Mining > Python' 카테고리의 다른 글
[python] proxy 설정, urllib2 (0) | 2013.04.18 |
---|---|
[python] gzip 압축 파일 읽기/쓰기 (utf-8 인코딩) (0) | 2013.03.22 |
Damerau-Levenshtein Distance (Edit distance) 구하기 (0) | 2013.03.18 |
[python] utf-8로 stdin 및 stdout 입출력 하기 (0) | 2013.03.18 |
[python] dict merge (0) | 2013.03.11 |
WRITTEN BY
- manager@
Data Analysis, Text/Knowledge Mining, Python, Cloud Computing, Platform
,