| [ QuizWit ] in KIDS 글 쓴 이(By): pomp (위풍당당) 날 짜 (Date): 2000년 1월 14일 금요일 오후 09시 22분 42초 제 목(Title): Re: [질문] 연월일 입력하면 요일이 나오 45 byte짜리 C 프로그램도 있어요! I once set myself the following problem: Given an arbitrary month (m= 1 to 12), day (d= 1 to 31), and year, find the simplest possible formula (entirely self-contained, with no recourse to tables of "magic numbers") that correctly calculates the day of the week D (0 = Sunday, 1 = Monday, ... 6 = Saturday). What does "simplest possible formula" mean? Well, here's a way to quantify it: make it an expression in the C programming language that's a few characters long as possible. Given the complications involved, it's quite surprising how short an expression will do. I believe that the following formula, a mere 45 characters, is the best that can be done: (d+=m<3?y--:y-2,23*m/9+d+4+y/4-y/100+y/400)%7 http://users.aol.com/s6sj7gt/mikecal.htm 에서... ----- Do you like Elgar? |