Skip to content

Instantly share code, notes, and snippets.

View foota's full-sized avatar

Noriyuki Futatsugi foota

View GitHub Profile
@foota
foota / gen_lattice.c
Created September 14, 2012 11:18
Generate lattice graphs.
/* Generate lattice graphs. */
#include "gb_graph.h"
#include "gb_basic.h"
#include "gb_save.h"
int main(int argc, char* argv[])
{
if (argc < 4) {
fprintf(stderr, "Usage %s N M outfile\n", argv[0]);
@foota
foota / prime.cpp
Created May 14, 2012 18:49
Prime (template metaprogramming)
#include <iostream>
template<int n, int d = 2, int r = 1, bool is_prime = false>
struct Prime {
Prime() { Prime<n, (d > 2) ? ((d + 2) % 3 ? d + 2 : d + 4) : d + 1, n % d, (n < d * d)>(); }
};
template<int n, int d>
struct Prime<n, d, 0, false> {};
@foota
foota / standard_time.py
Created May 14, 2012 18:43
Standard time
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""世界の標準時間を相互に変換"""
import sys, os, datetime
TIMEZONE_TABLE = {
"NZDT" : ["+13:00", u"ニュージーランド夏時間"],
"IDLE": ["+12:00", u"国際日付変更線の東側"],
"NZST": ["+12:00", u"ニュージーランド標準時間"],
@foota
foota / clusters_tbb.cpp
Created May 14, 2012 18:32
Hierarchical clustering
clusters_tbb.cpp
// hierarchical clustering using the TBB library
// by nox, 2009.07.02
//
// Linux - Intel C++
// icpc clusters_tbb.cpp -O3 -ltbb -o clusters_tbb
//
// Linux - GCC
// g++ clusters_tbb.cpp -O3 -ltbb -o clusters_tbb
@foota
foota / maze_solver.py
Created May 14, 2012 18:25
Maze solver
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os, math, heapq, Image, ImageDraw
# Connected Component Labeling - Label Equivalence method
class CCL:
def __init__(self, imagefile, threshold, area):
im = Image.open(imagefile)
im = im.convert("RGB")
@foota
foota / knight.cpp
Created May 14, 2012 18:17
Knight's Tour
// Solver of Knight's Tour using Warnsdorff's algorithm and Schwenk's theorem
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <utility>
#include <cmath>
#include <cstdlib>
@foota
foota / partitions.cpp
Created May 14, 2012 18:16
Integer partitions
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
void partitions(int n, int max_n, vector<int>& v, vector<vector<int> >& vv)
{
if (n == 0) {
@foota
foota / CellularAutomaton.as
Created May 14, 2012 18:10
Cellular Automaton
// CellularAutomaton.as
// by nox, 2010.7.9
// http://handasse.blogspot.com/
/*
1-9 : ルール設定 - セルの周りの生存セル数(0-8)に対応
: '.' 死亡, '&' 変化, '+' 誕生, '=' 維持
SPACE : 一時停止
ENTER : リセット
V : メッセージ表示/非表示
@foota
foota / sieve.cpp
Created May 14, 2012 18:07
Sieve of Eratosthenes
std::vector<int> primes;
for (int i = 3; i < 100; i += 2) primes.push_back(i);
auto end = primes.end();
for (auto x = primes.begin(); *x * *x <= *(end-1); ++x)
end = std::remove_if(x + 1, end, [&x](int p){ return p % *x == 0; });
primes.erase(end, primes.end());
for (auto p = primes.begin(); p != primes.end(); ++p) std::cout << *p << " ";
std::cout << std::endl;
@foota
foota / android_bbs.py
Created May 14, 2012 18:02
BBS on Android devices (SL4A)
# -*- coding: utf-8 -*-
import cgi,sqlite3,datetime
from wsgiref.simple_server import make_server
LIMIT=50 # 最大表示記事数.
DB_FILE='/sdcard/bbs.sqlite'
con=sqlite3.connect(DB_FILE)
cur=con.cursor()