Skip to content

Instantly share code, notes, and snippets.

@nomaddo
nomaddo / k-nearest.c
Last active October 17, 2019 15:36
k近傍法のプログラム gcc k-nearest.c -lm でコンパイル
/*
k近傍法のプログラム
gcc k-nearest.c -lm でコンパイル
下に書いてあるアドレスからwine.dataをダウンロードして同じファイル内で使って下さい
a.out の引数にはKの値と正規化するかどうか(0 or 1)の2つの引数を入力します
k-nearest neighbor algorithm for wine.data in ( http://archive.ics.uci.edu/ml/machine-learning-databases/wine/ )
how to compile :
@nomaddo
nomaddo / summaryToday.py
Last active December 20, 2015 20:29
pythonによるTwitterの一日まとめのためのプログラム。 TwitterAPIとYahooのテキスト解析・キーフレーズ抽出を利用している 外部のライブラリとしてtweepy, BeautifulSoupが必要だがpipで簡単にインストールできる。 ダウンロードしたディレクトリで、python ./summaryToday.pyで起動する。YahooのAPIキーとTwitterのコンシューマーキー・コンシューマーシークレットをファイルを編集して入力すること。 python2.7.4で動作を確認している。
import datetime
import tweepy
import urllib
import time
import os
from BeautifulSoup import BeautifulSoup
consumer_key=""
consumer_secret=""
@nomaddo
nomaddo / snake_checker.ml
Last active December 27, 2015 22:39
snake_sortのための回答が正しいかチェックするプログラム。 第一引数に、元々の最初の状態データ(Blog参照) 第二引数に、回答のデータ(同じくBlog参照) を渡すこと。エラーメッセージが出て動かなかったら教えて下さい。>友人
(*
使い方:
ocamlをインストールする。apt-getで簡単にインストール可能。
以下のコマンドでコンパイルする。
ocamlc -o snake_checker str.cma snake_checker.ml
*)
module Mylib = struct
(*
mylib requires Str module. In windows, -I option is required like a following command,
@nomaddo
nomaddo / nearest.ml
Created December 1, 2013 14:01
巡回セールスマン問題を解くシンプルなアルゴリズムを実装したプログラム。Mylibは気にしないでください。 コンパイルは ocamlopt str.cmxa graphics.cmxa nearest.ml
(*
- To compile, type following
ocamlopt str.cmxa graphics.cmxa nearest.ml
*)
module Mylib = struct
let valof = function
| None -> failwith "valof"
| Some x -> x
let get_matrix arr x y =
@nomaddo
nomaddo / output
Created January 5, 2014 14:02
This is output of Cmt_format.read_cmt "FILE". The File have only one fun def "let f x y z = x :: y".
{Cmt_format.cmt_modname = "One_level_prob";
cmt_annots =
Cmt_format.Implementation
{Typedtree.str_items =
[{Typedtree.str_desc =
Typedtree.Tstr_value (Asttypes.Nonrecursive,
[({Typedtree.pat_desc =
Typedtree.Tpat_var ({Ident.stamp = 1008; name = "f"; flags = 0},
{Asttypes.txt = "f";
loc =
@nomaddo
nomaddo / gist:8270242
Created January 5, 2014 16:22
プログラムlet f x = let g y = x::y in g [x] をコンパイルして出力されたcmtファイルに対するREPLの出力
utop[53]> Cmt_format.read_cmt "/home/tokuda/ocaml/cmt_test/s_question.cmt";;
- : Cmt_format.cmt_infos =
{Cmt_format.cmt_modname = "S_question";
cmt_annots =
Cmt_format.Implementation
{Typedtree.str_items =
[{Typedtree.str_desc =
Typedtree.Tstr_value (Asttypes.Nonrecursive,
[({Typedtree.pat_desc =
Typedtree.Tpat_var ({Ident.stamp = 1008; name = "f"; flags = 0},
@nomaddo
nomaddo / gist:8312577
Created January 8, 2014 06:15
REPLの出力
(* variable.ml
let f = fun x -> x
let g = f
*)
utop[0]> Cmt_format.read_cmt "/home/tokuda/ocaml/cmt_test/variable.cmt";;
- : Cmt_format.cmt_infos =
{Cmt_format.cmt_modname = "Variable";
cmt_annots =
@nomaddo
nomaddo / gist:8316647
Last active January 2, 2016 14:28
let f x = let g y = x::[] in let k = fun e -> g in k に対応するcmtファイルを読み込んだREPLの出力
let f x =
let g y = x::[] in
let k = fun e -> g in
k
utop[7]> Cmt_format.read_cmt "/home/tokuda/ocaml/cmt_test/final_case.cmt";;
- : Cmt_format.cmt_infos =
{Cmt_format.cmt_modname = "Final_case";
cmt_annots =
@nomaddo
nomaddo / f.ml
Created February 14, 2014 09:26
type annotation
(* これは通らない *)
let f x =
let (g:'a) = fun y -> y
g 1; g "str"
(* これは通る *)
let f x =
let g = fun y -> y
g 1; g "str"
@nomaddo
nomaddo / f.sml
Created October 12, 2014 15:30
description
fun f x = let ... x :: nil ...
... Array.update(a, i, x) ...
in (x, x) end
fun g y = f (y, 3.14)
(* f : 'a -> 'a * 'a *)
(* g : 'b -> (b * real) * ('b * real) *)