Skip to content

Instantly share code, notes, and snippets.

View spaghetti-source's full-sized avatar

Takanori MAEHARA spaghetti-source

View GitHub Profile
@spaghetti-source
spaghetti-source / loadeddice.cc
Last active August 29, 2015 14:07
Draw a number [0...n) from a loaded dice (Vose's alias method)
//
// Draw a number [0...n) from a loaded dice (Vose's alias method)
//
#include <iostream>
#include <vector>
using namespace std;
unsigned int xor32() {
static unsigned long y = 2463534242UL;
#include <iostream>
#include <vector>
#include <deque>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
@spaghetti-source
spaghetti-source / iitomo.txt
Created March 31, 2014 06:47
waratte iitomo telephone shocking dataset
1982/10/4 桜田淳子
1982/10/5 土居甫
1982/10/6 増田恵子
1982/10/7 うつみ宮土理
1982/10/8 和田アキ子
1982/10/11 ガッツ石松
1982/10/12 加藤芳郎
1982/10/13 富永一朗
1982/10/14 鈴木義司
1982/10/15 三波豊和
@spaghetti-source
spaghetti-source / animatedbar.py
Created March 22, 2014 02:27
animated bar graph
# -*- coding: UTF-8 -*-
#
# source: http://www.mext.go.jp/b_menu/toukei/001/022/2003.htm
#
import random
import matplotlib
import matplotlib.pyplot as plt
import math
y = [53.14, 52.44, 54.13, 54.63, 54.40, 54.85, 51.04, 50.35, 49.29, 47.95, 47.05, 45.28, 42.62, 39.70, 36.86]
@spaghetti-source
spaghetti-source / knapsack.cc
Last active August 29, 2015 13:57
knapsack
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <ctime>
#include <functional>
#include <algorithm>
#include <numeric>
using namespace std;
% --- testcase: grid network ---
% A: adjacency matrix
inf = 999999;
w = 4;
h = 4;
A = inf*ones(w*h);
n = size(D,1);
for x = 1 : w
for y = 1 : h
if x < w
@spaghetti-source
spaghetti-source / mds_ghcn.cc
Last active January 4, 2016 05:49
MDS for GHCN dataset
//
// http://www.ncdc.noaa.gov/ghcnm/v3.php
//
#include <iostream>
#include <vector>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
@spaghetti-source
spaghetti-source / nlcg.cc
Last active January 3, 2016 00:29
Nonlinear Conjugate Gradient Descent (Polak-Ribiere)
// nonlinear conjugate gradient
#include <iostream>
#include <vector>
#include <deque>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
#include <cstring>
@spaghetti-source
spaghetti-source / lbfgs.cc
Last active January 3, 2016 00:19
Limited Memory Broyden-Fletcher-Goldfarb-Shanno (LBFGS)
#include <iostream>
#include <vector>
#include <deque>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
@spaghetti-source
spaghetti-source / tpack.cc
Created December 26, 2013 21:52
T-Packing
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
#define fst first
#define snd second