분류 전체보기 726

대화형 모드의 진법(radix) 변환 예제 with OCaml

다음은 대화형 모드(interactive mode)에서 진법 변환(radix conversion)하는 OCaml 소스 코드이다. 주: 이 소스는 Python 용으로 만들어 둔 소스를 F# 언어로 바꾸고, 다시 이를 Ocaml 언어로 바꾸느라 OCaml 언어의 명령형 언어 특징을 위주로 짜여져 있다. 메뉴는 주메뉴 Command: (S)et radix, (A)bout, (Q)uit or E(x)it 와 부메뉴 SubCommand: 'main()' to goto Main menu, 'exit()' or 'quit()' to exit 로 구성되어 있으며, 진법 변환의 핵심은 소스 코드에 자체 작성된 함수 atoi 와 itoa 의 사용이다. let value = atoi str srcRdx let str = i..

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

다음은 이차방정식 x^2 - x - 1 = 0 의 양의 근 즉 황금비율(golden ratio)을 구하는 OCaml 소스이다. 황금비율을 구하는 비례방정식은 1 : x = x : (x+1) 이며, 이를 이차방정식으로 표현한 것이 x^2 - x - 1 = 0 이다. See: http://en.wikipedia.org/wiki/Golden_ratio (* * Filename: testGoldenRatio.ml * 황금률(즉, 이차방정식 x^2 - x - 1 = 0 의 양의 근)을 계산한다. * * Execute: ocaml testGoldenRatio.ml * * Compile: ocamlc -o testGoldenRatio.exe testGoldenRatio.ml * Execute: testGoldenRa..

현재 시각 알아내기 for OCaml

현재 시각을 컨솔에 보여주는 간단한 OCaml 언어 소스 코드이다. UTC란 1970년 1월 1일 0시 0분 0초를 기준으로 하여 경과된 초 단위의 총 시간을 의미한다. UTC(Universal Time Coordinated, 협정세계시, 協定世界時) (* * Filename: testCTimeApp.ml * * Execute: Uncomment the line (* #load "unix.cma" ;; *) * ocaml testCTimeApp.ml * * Compile: ocamlc -g -c testCTimeApp.ml * ocamlc -o testCTimeApp.exe unix.cma testCTimeApp.cmo * Execute: testCTimeApp *) (* #load "unix.cma" ..

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

F# 용 소스파일 testForFor.fs 를 OCaml 용으로 수정한 것이다. F# 언어는 if 구문, for 구문, 들여쓰기 규칙이 Python의 것과 닮았지만, OCam 언어는 (C 언어 처럼) 들여쓰기 규칙이 없다. 그 대신 구문의 끝을 한 개의 세미콜론(;)으로 끝낼지, 두 개의 세미콜론(;;)으로 끝낼지, 아니면 세미콜론을 안 붙일 것이지를 정확하게 지켜야 한다. OCam 언어는 let 으로 시작하는 구문에 세미콜론 없이 예약어 in 으로 (정의가) 계속 이어지는 구문도 많이 쓰인다. 두 개의 세미콜론(;;) 으로 끝나는 곳이 정의가 완전히 끝난 곳임을 알리는 구문이고, 한 개의 세미 콜론으로 끝나는 곳은 정의가 아직 완성 도지 않았으니 무시하라는 구문이다. 아래는 ocaml 을 실행시켜서서 ..

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

소스 파일명: TestNoWhile.ml (* * Filename: testNoWhile.ml * * Purpose: Example not using the while loop syntax * while .... * * Execute: ocaml testNoWhile.ml -200 300 * * Or * * Compile: ocamlc -o testNoWhile.exe testNoWhile.ml * Execute: testNoWhile -200 300 *) (* 사용법 표시 *) let printUsage() = Printf.printf "Using: testNoWhile.py [integer1] [integer2]\n"; Printf.printf "This finds the greatest common..

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

소스 파일명: testWhile.ml (* * Filename: testWhile.ml * * Purpose: Example using the while loop syntax * while .... * * Execute: ocaml testWhile.ml -200 300 * * Or * * Compile: ocamlc -o testWhile.exe testWhile.ml * Execute: testWhile -200 300 *) (* 사용법 표시 *) let printUsage() = Printf.printf "Using: testWhile.py [integer1] [integer2]\n"; Printf.printf "This finds the greatest common divisor of the gi..

구구단 출력 예제 for OCaml

OCaml 언어는 함수형 언어이면서도 명령형 언어의 특징을 대부분 가지고 잇다. 따라서 보통의 for 구문을 쓸 수도 있고, 재귀호출 함수릉 만들어 쓸 수도 있다. 아래의 소스에서 함수 printDan 은 보통의 for 구문을 쓴 것이고 함수 printAnotherDan 은 재귀호출 함수를 쓴 것이다. 소스 파일명: forTest.ml ------------------------------[소스 시작] (* Filename: forTest.ml Execute: ocaml forTest.ml Or Compile: ocamlc -o forTest forTest.ml Execute: ./forTest Or Compile: ocamlc -o forTest.exe forTest.ml Execute: forTest..

C# 에서 xmpir 사용하기

1. mpir 은 gmp 대신사용하는 (C/C++ 언어용) 긴 자리 수치 처리를 위한 기본 연산 라이브러리이다. 자리수가 매우 긴 정수, 유리수, 소수점수를 계산할 수 있다. 2. xmpir 은 (C 언어용 긴 자리 수치 라이브러리인) mpir 의 래퍼(wrapper) 이다. 3. xmpir 은 xmpir 다운로드 에서 구할 수 있다. (주의 사항. dl4windows.dll 파일이 존재하는 폴더의 경로명에 #문자가 있으면 컴파일은 되나 실행 시에 에러에 걸린다. 그 이유는 xmpir 이 dl4windows.dll 파일을 찾을 때 URL 주소를 적용해서 찾기 때문이다.) 실행에 필요한 *.dll 파일들은 (현재 경로 또는) 환경변수 PATH 에 결린 경로의 폴더에 존재해야 한다. dl4windows.dl..

프로그래밍/C# 2013.01.24