Strict Standards: Non-static method Soojung::addReferer() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/settings.php on line 79

Warning: Cannot modify header information - headers already sent by (output started at /home/lifthrasiir/sites/sapzil.info/soojung/settings.php:79) in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Counter.class.php on line 63

Strict Standards: Non-static method Entry::getEntry() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/entry.php on line 51

Strict Standards: Non-static method Soojung::entryIdToFilename() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Entry.class.php on line 182

Strict Standards: Non-static method Soojung::queryFilenameMatch() should not be called statically in /home/lifthrasiir/sites/sapzil.info/soojung/classes/Soojung.class.php on line 55
TokigunStudio3 | 블로그: transdate in python

내용으로 바로 넘어 가기


TokigunStudio3

228 / 3282   


더 이상 이 블로그는 운영되지 않습니다. 새 블로그로 가 주세요.

transdate in python

2004/09/23 PM 02:56 | 개발/파이썬 | 3 comments | 0 trackbacks | AllBlog: vote, to pocket

...을 만들어 보자. -_-; (transdate: 양음력 변환 모듈)

- 클래스 형태로 transdate.solardate, transdate.lunardate 클래스를 지원한다. 기존의 datetime.date와 상호 변환이 가능하다.
- 당연히 datetime.timedelta와의 연산도 가능해야 함. datetime.date의 대부분의 기능을 끌어 올 수 있어야 한다.
- 엄청난 속도를 자랑한다! 이에 대해서는 아래 참고.

사용할 알고리즘은...

- 미리 리스트 형태로 날짜를 저장한다. table = [0, 31, 61, ...] 이런 식으로... 그리고 각 index가 음력 몇년 몇월에 해당하는 지도 기록한다. 별로 용량 많이 안 먹는다. (처음부터 이렇게 써 넣는 것도 나쁘지 않겠군.)
- 양력에서 음력 변환: bisect 모듈로 단박에 index를 찾아서 년월을 계산한다.
- 음력에서 양력 변환: 거꾸로 index에서 양력 날짜 수를 계산한 후 막바로 양력 날짜로 변환.

사실 이 짓은 자바스크립트 때 이미 binary search로 구현했어야 하는 것이었으나 귀차니즘에 빠져서 못 하고 있다가 파이썬으로 새로 하게 되는 군... 시간 남으면 자바스크립트도...

TrackBack URL: http://sapzil.info/soojung/trackback.php?blogid=21

Comment: 토끼군 (2004/09/23 PM 06:58)

앗 실수로 디토 님 코멘트 지웠습니다. OTL (list 대신 tuple로 저장하라는 거였나요...) 근데 bisect 쓸려면 아마 list여야 할 겁니다 -ㅂ-

Comment: 디토 (2004/09/23 PM 10:32)

차라리 dict를 (...)

Comment: 토끼군 (2004/09/23 PM 11:10)

디토: dictionary도 순서가 없는 mapping 타입이라서 (...) tuple에 bisect가 먹힐 지는 잘 모르겠군요.

Copyright (c) 1995-2005, Kang Seonghoon (Tokigun).