Skip to content

Instantly share code, notes, and snippets.

View ikautak's full-sized avatar

Katsuaki Oshio ikautak

View GitHub Profile
@ikautak
ikautak / dijkstra.py
Created August 11, 2013 08:36
dijkstra's shortest path.
#!/usr/bin/env python
import sys
from altgraph import Graph
def read_graph(f):
g = Graph.Graph()
for l in file(f):
l = l.rstrip().split()
@ikautak
ikautak / grayscale.py
Created July 22, 2013 13:31
gray scale
#!/usr/bin/env python
import sys
import Image
def conv(f):
Image.open(f).convert('LA').save('output.png')
@ikautak
ikautak / ack.c
Created July 6, 2013 10:09
Ackermann function
int ack(int m, int n) {
if (m == 0) return n + 1;
if (n == 0) {
return ack(m - 1, 1);
} else {
return ack(m - 1, ack(m, n - 1));
}
}
@ikautak
ikautak / plus.cpp
Created June 22, 2013 09:15
1から10の間に+ or -を入れて11を作る
#include <iostream>
using namespace std;
// 符号と値を貰って足される数を返すわ
int calc( bool hugou, int num )
{
int ret = 0;
if( hugou )
{
@ikautak
ikautak / tarai.py
Created April 12, 2013 15:09
Python implementation of Tak.
#!/usr/bin/env python
def tarai(x, y, z):
if x <= y:
return y
else:
return tarai(
tarai(x-1, y, z),
tarai(y-1, z, x),
tarai(z-1, x, y))
@ikautak
ikautak / cmd_complete_decorator.py
Last active May 19, 2016 08:18
auto complete decorator for cmd module.
#!/usr/bin/env python
import os
import cmd
def file_auto_complete(text, line, begidx, endidx):
""" auto complete of file name.
"""
line = line.split()
@ikautak
ikautak / tumblr-theme.html
Last active December 14, 2015 04:39
tumblr theme based "Notations" theme.
<!doctype html>
<!--
"Notations" theme designed by Ben Delaney (http://bendelaney.me)
Available in the Tumblr theme garden: http://www.tumblr.com/theme/8631 -->
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
@ikautak
ikautak / simple_atoi.c
Created February 20, 2013 14:12
simple atoi implementation.
int simple_atoi(const char* a) {
int ans = 0;
while (*a != '\0') {
ans = ans * 10 + (*a++) - '0';
}
return ans;
}
@ikautak
ikautak / leastsq.py
Created February 14, 2013 14:16
scipy leastsq sample.
#!/usr/bin/env python
import numpy as np
from scipy.optimize import leastsq
def fit_func(parameter, x, y):
a = parameter[0]
b = parameter[1]
residual = y - (a*x*x + b)
@ikautak
ikautak / reverse_bit.c
Last active March 21, 2024 17:55
reverse MSB LSB bit.
unsigned char reverse_bit8(unsigned char x)
{
x = ((x & 0x55) << 1) | ((x & 0xAA) >> 1);
x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2);
return (x << 4) | (x >> 4);
}
unsigned short reverse_bit16(unsigned short x)
{