Skip to content

Instantly share code, notes, and snippets.

View foota's full-sized avatar

Noriyuki Futatsugi foota

View GitHub Profile
@foota
foota / count_path_mp.cpp
Created September 14, 2012 11:21
Count paths on a lattice graph.
// Count paths on a lattice graph.
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <gmp.h>
@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 / edit_distance.cpp
Created May 14, 2012 18:41
Edit distance
#include <iostream>
#include <string>
#include <bitset>
#include <ctime>
using namespace std;
// dynamic programming
const int SIZE = 100;
@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 / simple_md_gpu.cu
Created May 14, 2012 18:24
Simple molecular dynamics using GPU devices
////////////////////////////////////////////////////////////////
// Simple Molecular Dynamics using GPU by nox, 2009.12.10.
//
// Perform molecular dynamics for pseudo-atoms without internal
// interactions, such as bonds, angles, dihedrals. Only vdW and
// Coulomb interactions.
#include <iostream>
#include <iomanip>
#include <fstream>
@foota
foota / Place.pde
Created May 14, 2012 18:22
Map of convenience stores
class Place {
int id;
String name;
float x, y;
public Place(int id, String name, float x, float y) {
this.id = id;
this.name = name;
this.x = x;
this.y = y;
@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>