Skip to content

Instantly share code, notes, and snippets.

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

SUGITA, Toshinori sugitach

💭
(^^)
  • Netchart Inc. / JOCDN Inc.
  • Osaka, JAPAN
View GitHub Profile
@sugitach
sugitach / init.el
Last active February 18, 2019 00:58
~/.emacs/init.el のサンプル (ほぼキーバインドの説明)
;; 基本的なキーバインド
;;
;; 基本
;; C-x C-c kill-emacs emacs終了
;; C-g quit 直前のキー操作をキャンセル
;; M-x <XXXX><ENTER> lisp-command の直接実行
;; C-h m describe-mode 現在のバッファのキーマップ一覧を表示
;; ファイル操作
@sugitach
sugitach / Q1.ml
Last active August 29, 2015 14:22
1時間以内に解けなければプログラマ失格となってしまう5つの問題
let rec _sum lst ret = match lst with
[] -> ret
| first :: rest -> _sum rest (ret + first)
let sum lst = _sum lst 0
let x = sum [1;2;3]
let x = sum [10;2;31]
(* 13.5 *)
let twice f = let g x = f (f x) in g
let f = twice twice
(* できあがった関数は渡された関数を4回繰り返したものになる *)
(* val f : ('_a -> '_a) -> '_a -> '_a = <fun> *)
(* 'a -> 'a *)
let func1 a = a
(* 'a -> 'b -> 'a *)
let func2 a b = a
(* 'a -> 'b -> 'b *)
let func3 a b = b
(* 'a -> ('a -> 'b) -> 'b *)
(* データ読み込み *)
#use "person_t.ml"
(* 目的:person_t のリストから指定された血液型の人数を返す *)
(* count_ketsueki : string -> person_t list -> int *)
let rec count_ketsueki bld lst =
match lst with
[] -> 0
| first :: rest -> count_ketsueki bld rest +
if (first.blood = bld)
type date_t = {
month : int;
day : int;
}
type person_t = {
name : string;
height : float;
weight : float;
birthday : date_t;
#use "metro.ml"
(* 問題12.1 eki_t 型 *)
type eki_t = {
namae: string; (* 駅名 *)
saitan_kyori: float; (* 最短距離 *)
temae_list: string list; (* 通過した駅名のリスト *)
}
(* 問題12.2 ekimei_t list を受け取って、駅名から eki_t list を作る
(* s から e までの整数のリストを作成する *)
let rec makeListSub s e lst =
match e - s with
0 -> e::lst
| _ -> makeListSub s (e-1) (e::lst)
let makeList s e =
if s < e
then makeListSub s e []
else makeListSub e s []
#use "metro.ml"
(* 目的:ふたつの駅の漢字の駅名とリストを受け取って2駅間の距離を返す *)
(* get_ekikan_kyori : string -> string -> ekikan_t list -> float *)
let rec get_ekikan_kyori s1 s2 lst =
if s1 = s2
then 0.
else match lst with
[] -> infinity
| first::rest -> if (first.kiten = s1 && first.shuten = s2) ||
#use "metro.ml"
(* 目的:ローマ字の駅名と駅名リストから漢字の駅名を返す *)
(* romaji_to_kanji : string -> ekimei_t list -> string *)
let rec romaji_to_kanji romaji lst =
match lst with
[] -> ""
| first::rest -> if first.romaji = romaji
then first.kanji
else romaji_to_kanji romaji rest