2010/07/13 5

황금비율(golden ratio) 구하기 with F#

다음은 이차방정식 x^2 - x - 1 = 0 의 양의 근 즉 황금비율(golden ratio)을 구하는 F# 소스이다. 황금비율을 구하는 비례방정식은 1 : x = x : (x+1) 이며, 이를 이차방정식으로 표현한 것이 x^2 - x - 1 = 0 이다. See: http://en.wikipedia.org/wiki/Golden_ratio (* * Filename: TestGoldenRatio.fs * 황금률(즉, 이차방정식 x^2 - x - 1 = 0 의 양의 근)을 계산한다. * * Compile: fsc testGoldenRatio.fs * Execute: testGoldenRatio * * Date: 2010/07/13 * Author: PH Kim [ pkim (AT) scripts.pe.kr..

프로그래밍/F# 2010.07.13

현재 시각 알아내기 for F#

현재 시각을 컨솔에 보여주는 간단한 F# 언어 소스 코드이다. UTC란 1970년 1월 1일 0시 0분 0초를 기준으로 하여 경과된 초 단위의 총 시간을 의미한다. * UTC(Universal Time Coordinated, 협정세계시, 協定世界時) (* * Filename: TestCTimeApp.fs * * Compile: fsc --codepage:949 TestCTimeApp.fs * * Execute: TestCTimeApp *) // namespace MyTestApp1 open System let weekNames = [| "일"; "월"; "화"; "수"; "목"; "금"; "토" |] let now = System.DateTime.Now let startOfEpoch = new DateT..

프로그래밍/F# 2010.07.13

80컬럼 컨솔에 19단표 출력하기 예제 for F#

Python용 소스파일 testForFor.py를 F# 용으로 수정한 것이다. F#의 if 구문과 for 구문이 Python의 것과 (들여쓰기하는 것 까지) 많이 닮았다. F#은 함수형 언어기도 하고 명령형 언어이기도 하므로, 여기서는 가급적 F#의 명령형 언어의 특징을 위주로 작성하였다. (* * Filename: TestForFor.fs * * Compile: fsc TestForFor.fs * Execute: TestForFor * * Date: 2010. 7. 13 *) # light let getDan dan = let t = [| for i in 1..19 -> "" |] for j in 0..(19 - 1) do let mutable sa = sprintf "%d" dan if (String..

프로그래밍/F# 2010.07.13

(최대공약수 구하기) while 반복문 없는 예제 for F#

소스 파일명: TestNoWhile.fs (* * Filename: TestNoWhile.fs * * Purpose: Example using the while loop syntax * while .... * * Compile: fsc --codepage:949 TestNoWhile.fs * Execute: TestNoWhile -200 300 *) #light // 사용법 표시 let printUsage x = printfn "Using: TestNoWhile [integer1] [integer2]" printfn "This finds the greatest common divisor of the given two integers." let cmdArgs = System.Environment.GetCo..

프로그래밍/F# 2010.07.13

(최대공약수 구하기) while... 반복문 예제 for F#

소스 파일명: TestWhile.fs (* * Filename: TestWhile.fs * * Purpose: Example using the while loop syntax * while .... * * Compile: fsc --codepage:949 TestWhile.fs * Execute: TestWhile -200 300 *) #light // 사용법 표시 let printUsage x = printfn "Using: TestWhile.py [integer1] [integer2]" printfn "This finds the greatest common divisor of the given two integers." let cmdArgs = System.Environment.GetCommandLi..

프로그래밍/F# 2010.07.13