This file contains hidden or 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
let bmi_check (name, height, weight) = | |
let bmi = weight /. (height *. height) in | |
if bmi < 18.5 then name ^ "さんはやせています" | |
else if bmi < 25.0 then name ^ "さんは標準です" | |
else if bmi < 30.0 then name ^ "さんは肥満です" | |
else name ^ "さんは肥満です" |
This file contains hidden or 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
let geo_mean x y = sqrt(x *. y) |
This file contains hidden or 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
let sum_and_diff (x, y) = (x + y, x - y) | |
let f (x, y) = ((x+y)/2,(x-y)/2) |
This file contains hidden or 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
let rec pow(x,n) = | |
if n <= 1 then x else x * pow(x,n-1) |
This file contains hidden or 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
let rec pow(x,n) = | |
if n <= 1 then x | |
else let stack = pow(x,n/2) in | |
if n mod 2 = 0 then stack*stack | |
else x*stack*stack |
This file contains hidden or 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
let rec iterpow(i,res,x,n) = | |
if i > n then res else iterpow(i+1,res *. x,x,n) |
This file contains hidden or 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
let rec gcd (m,n) = | |
if m mod n = 0 then n else gcd(n,m mod n) |
This file contains hidden or 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
let rec comb(n,m) = | |
if m = 0 || n = m then 1 | |
else comb(n-1,m) + comb(n-1,m-1) |
This file contains hidden or 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
let fib n = | |
let rec iterfib(i,pre2,pre1,res,n) = | |
if i >= n then res else iterfib(i+1,pre1,res,res+pre1,n) in | |
iterfib(1,0,0,1,n) |
This file contains hidden or 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
let max_ascii str = | |
let rec itermax(i,str,max,length) = | |
if i >= length then max | |
else if int_of_char(str.[i]) > max then itermax(i+1,str,int_of_char(str.[i]),length) | |
else itermax(i+1,str,max,length) in | |
itermax(0,str,0,String.length str) |