Skip to content

Instantly share code, notes, and snippets.

View sugitach's full-sized avatar
💭
(^^)

SUGITA, Toshinori sugitach

💭
(^^)
  • Netchart Inc. / JOCDN Inc.
  • Osaka, JAPAN
  • 03:08 (UTC +09:00)
View GitHub Profile
(* 目的:ふたつのリストを受け取って長さが同じかどうかを返す *)
(* equal_length : a' list -> b' list -> bool *)
let rec equal_length lst1 lst2 =
match lst1 with
[] -> (match lst2 with [] -> true | _::_ -> false)
| f1::r1 -> (match lst2 with [] -> false | f2::r2 -> equal_length r1 r2)
(* テスト *)
let test1 = equal_length [] [] = true
let test2 = equal_length [1; 2; 3] ["a";"b";"c"] = true
(* 型定義 *)
type date_t = {
month : int;
day : int;
}
type person_t = {
name : string;
height : float;
weight : float;
(* 型定義 *)
type date_t = {
month : int;
day : int;
}
type person_t = {
name : string;
height : float;
weight : float;
let rec gakusei_max_new lst = match lst with
[] -> { name = "void"; tensuu = 0; seiseki = "0"; }
| first :: rest -> let max = gakusei_max rest in
if (first.tensuu > max.tensuu)
then first
else max
(* 学生一人分のデータ *)
type gakusei_t = {name: string; tensuu: int; seiseki: string}
(*学生データのリスト*)
let gakusei1 = { name = "asai"; tensuu = 70; seiseki = "B"; }
let gakusei2 = { name = "kaneko"; tensuu = 85; seiseki = "A"; }
let gakusei3 = { name = "yoshida"; tensuu = 80; seiseki = "A"; }
let gakusei4 = { name = "x-asai"; tensuu = 70; seiseki = "B"; }
let gakusei5 = { name = "x-kaneko"; tensuu = 85; seiseki = "A"; }
let gakusei6 = { name = "x-yoshida"; tensuu = 80; seiseki = "A"; }
(* 10.2 目的:任意の整数のリストから昇順に整列したリストを返す *)
(* ins_sort : int list -> int list *)
let rec ins_sort lst = match lst with
[] -> []
| first :: rest -> insert (ins_sort rest) first
(* テスト *)
let test2_1 = ins_sort [] = []
let test2_2 = ins_sort [3;5;1] = [1;3;5]
let test2_3 = ins_sort [5;3;8;1;7;4] = [1;3;4;5;7;8]
(* おおもとのデータ *)
let src = [1;2;3;1;3]
(* 0〜max までのリスト *)
let rec nums_in m lst =
if m >= 0
then nums_in (m-1) (m::lst)
else lst
let nums m = nums_in m []
@sugitach
sugitach / ex-8.3.ml
Last active August 29, 2015 14:06
ex-8
(* ex 8.3 *)
type date_t = {
month: int;
day: int;
}
type person_t = {
height: float;
weight: float;
birthday: date_t;
@sugitach
sugitach / ex-5.3.ml
Last active August 29, 2015 14:06
Ocaml 勉強会
(* 月、日を入力して星座をもとめる *)
(*
牡羊座 Aries 3月21日から4月20生まれ
牡牛座 Taurus 4月21日から5月20生まれ
双子座 Gemini 5月21日から6月21日生まれ
蟹座 Cancer 6月22日から7月23日生まれ
獅子座 Leo 7月24日から8月23日生まれ
乙女座 Virgo 8月24日から9月23日生まれ
天秤座 Libra 9月24日から10月23日生まれ