C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[18823] Re:바이오 리듬 알고리즘을 누가 좀 갈쳐주세요.....
유영인.Chris [cuperido] 1814 읽음    2002-05-24 11:14
저두 잘 모르고.. 찾아보니 소스가 있어서.. 올려드립니다. 아마도 C++ Builder 소스가 아니라서 차이가 좀 있을껍니다.. 그대로 쓰시기에는 무리같구.. 여기에 있는 계산등의 이론을 분석하시는건 어떻까요..?



#!/usr/bin/env python
#
# Biorhythm calculator. Easier to program than to spell.
#
# Re-use of this code for any purpose is permitted, so long as this notice
# and the __author__ attribution are retained in the source file.
#

__author__  = "Steve Purcell (stephen_purcell at yahoo dot com)"

import string
import time
import math

SECS_IN_DAY = 24 * 60 * 60

class BiorhythmCalculator:
    EMOT_PERIOD = 28.0 * SECS_IN_DAY
    PHYS_PERIOD = 23.0 * SECS_IN_DAY
    INTL_PERIOD = 33.0 * SECS_IN_DAY
                                   
    def __init__(self, birthtime): 
        self.birthtime = birthtime
                                 
    def calculateFor(self, theTime):
        """Return tuple of percentages, (emotional,physical,intellectual)"""
        if theTime < self.birthtime:
            raise ValueError("that time is before the birthtime!")
        timeDiff = theTime - self.birthtime
        twoPi = math.pi * 2.0
        return (math.sin(twoPi * (timeDiff / self.EMOT_PERIOD)),
                math.sin(twoPi * (timeDiff / self.PHYS_PERIOD)),
                math.sin(twoPi * (timeDiff / self.INTL_PERIOD)))

def makeTimeFromDate(day, month, year):
    if day < 1 or month < 1 or year < 1:
        raise ValueError('negative day/month/year not allowed')
    return time.mktime((year,month,day,0,0,0,-1,-1,-1))       

if __debug__: # Test code
    birthtime = makeTimeFromDate(1,7,1974)
    calc = BiorhythmCalculator(birthtime)
    assert calc.calculateFor(birthtime) == (0,0,0)
    assert calc.calculateFor(birthtime + 28*SECS_IN_DAY)[0] < 0.001
    assert calc.calculateFor(birthtime + 23*SECS_IN_DAY)[1] < 0.001
    assert calc.calculateFor(birthtime + 33*SECS_IN_DAY)[2] < 0.001

if __name__ == '__main__':
    import sys
    args = sys.argv[1:]
    if len(args) != 3:
        print """\                 
Biorhythm calculator

usage: biorhythm.py day month year

Calculates today's biorhythms for the person born on the given day. """
sys.exit(2)

    day, month, year = map(string.atoi, args)
    birthtime = makeTimeFromDate(day,month,year)
    thistime = time.mktime(time.localtime(time.time())[0:3] +  
                           (0,0,0,-1,-1,-1))
    calc = BiorhythmCalculator(birthtime)
    emot,phys,intl = calc.calculateFor(thistime)
    print "Emotional: %7.1f %%" % (emot*100)
    print "Physical : %7.1f %%" % (phys*100)
    print "Mental   : %7.1f %%" % (intl*100)

    width = 60
    halfwidth = width / 2
    solidline = '=' * (width+10)
    print solidline
    print "Day(s)  |-100%" + (' ' * (width - 10)) + "+100%|"
    print solidline
    for dayDiff in range(-20,20):
        thatTime = thistime + dayDiff * SECS_IN_DAY
        emot,phys,intl = calc.calculateFor(thatTime)
        bar = [' -'[dayDiff==0]] * width           
        bar[halfwidth - 1] = bar[halfwidth] = '.'
        bar[halfwidth - 1 + int(emot * halfwidth)] = 'E'
        bar[halfwidth - 1 + int(phys * halfwidth)] = 'P'
        bar[halfwidth - 1 + int(intl * halfwidth)] = 'M'
        print "%4d    |%s|" % (dayDiff,string.join(bar,''))
    print solidline                                       


sado1028 님이 쓰신 글 :
: 님들 중에 아시는 분 있음 그 알고리즘 좀 갈쳐 주세요....
: 소스를 짤려구 하는데 그 알고리즘을 모르니까 짜증만 나구 밥맛두 없구 살맛도 안나구....
: 제가 씨빌더를 시작한지 별루 안되서 잘 모르는 왕초보여서요....

+ -

관련 글 리스트
18802 바이오 리듬 알고리즘을 누가 좀 갈쳐주세요..... sado1028 1931 2002/05/23
18823     Re:바이오 리듬 알고리즘을 누가 좀 갈쳐주세요..... 유영인.Chris 1814 2002/05/24
18828         감사 합니다.........너무 감동 sado1028 985 2002/05/24
18826         Re:Re: 와~~ 파이선이다. 최고의 스크립트 언어라죠... 이것도 언젠가 배워봐야 하는데...(내용無) 김백일 1110 2002/05/24
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.