Created
March 1, 2015 16:01
-
-
Save akimacho/c8ea63568ff5d2e44b38 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* --- 問題4.1 --- *) | |
# let baito_kyuyo years hours = (850 + 100 * years) * hours ;; | |
val baito_kyuyo : int -> int -> int = <fun> | |
# baito_kyuyo 0 25 ;; | |
- : int = 21250 | |
# baito_kyuyo 3 25 ;; | |
- : int = 28750 | |
(* --- 問題4.2 --- *) | |
# let jikoshokai name = "こんにちは,私は" ^ name ^ "です." ;; | |
val jikoshokai : string -> string = <fun> | |
# jikoshokai "ジョン" ;; | |
- : string = "こんにちは,私はジョンです." | |
(* --- 問題4.3 --- *) | |
# let hyojun_taiju height = height ** 2.0 *. 22.0 ;; | |
val hyojun_taiju : float -> float = <fun> | |
# hyojun_taiju 170.0 ;; | |
- : float = 635800. | |
(* --- 問題4.4 --- *) | |
# let bmi height weight = weight /. height ** 2.0 ;; | |
val bmi : float -> float -> float = <fun> | |
# bmi 170.0 60.0 ;; | |
- : float = 0.00207612456747404859 | |
(* --- 問題4.5 --- *) | |
(* 問題4.5の通り *) | |
(* --- 問題4.6 --- *) | |
(* 目的:鶴の数xから鶴の足の本数を計算する *) | |
(* tsuru_no_ashi : int -> int *) | |
let tsuru_no_ashi x = x * 2 | |
(* テスト *) | |
let test1 = tsuru_no_ashi 0 = 0 | |
let test2 = tsuru_no_ashi 3 = 6 | |
let test3 = tsuru_no_ashi 14 = 28 | |
# #use "tsuru.ml" ;; | |
val tsuru_no_ashi : int -> int = <fun> | |
val test1 : bool = true | |
val test2 : bool = true | |
val test3 : bool = true | |
(* 目的:亀の数xから亀の足の本数を計算する *) | |
(* kame_no_ashi : int -> int *) | |
let kame_no_ashi x = 4 * x | |
(* テスト *) | |
let test1 = kame_no_ashi 0 = 0 | |
let test2 = kame_no_ashi 3 = 12 | |
let test3 = kame_no_ashi 14 = 56 | |
# #use "kame.ml" ;; | |
val kame_no_ashi : int -> int = <fun> | |
val test1 : bool = true | |
val test2 : bool = true | |
val test3 : bool = true | |
(* --- 問題4.7 --- *) | |
(* 目的:鶴の数xと亀の数yから鶴の足と亀の足の合計を計算する *) | |
(* kame_no_ashi : int -> int -> int *) | |
let kame_no_ashi x y = 2 * x + 4 * y | |
(* テスト *) | |
let test1 = kame_no_ashi 0 0 = 0 | |
let test2 = kame_no_ashi 3 3 = 18 | |
let test3 = kame_no_ashi 14 9 = 64 | |
# #use "tsurukame_no_ashi.ml" ;; | |
val kame_no_ashi : int -> int -> int = <fun> | |
val test1 : bool = true | |
val test2 : bool = true | |
val test3 : bool = true | |
(* --- 問題4.8 --- *) | |
(* テストケースは問題4.7を参考にした *) | |
(* 目的:鶴と亀の数の合計xと足の数の合計yから鶴の数を計算する *) | |
(* tsurukame : int -> int -> int *) | |
let tsurukame x y = (4 * x - y) / 2 | |
(* テスト *) | |
let test1 = tsurukame 0 0 = 0 | |
let test2 = tsurukame 6 18 = 3 | |
let test3 = tsurukame 23 64 = 14 | |
# #use "tk.ml" ;; | |
val tsurukame : int -> int -> int = <fun> | |
val test1 : bool = true | |
val test2 : bool = true | |
val test3 : bool = true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment