Skip to content

Instantly share code, notes, and snippets.

View ikautak's full-sized avatar

Katsuaki Oshio ikautak

View GitHub Profile
@ikautak
ikautak / pi_generator.py
Created May 14, 2011 01:53
calculate pi using python generator.
#!/usr/bin/env python
def pi():
# Wallis' product
numerator = 2.0
denominator = 1.0
while True:
yield numerator/denominator
if numerator < denominator:
numerator += 2
@ikautak
ikautak / pi.go
Created April 21, 2012 10:05
calculate pi using channel, goroutine.
package main
import "fmt"
const LOOP = 1000 * 1000
// Generate 1 term of Wallis product
func GenerateTerm(ch chan<- float64) {
numerator := 2.0
denominator := 1.0
@ikautak
ikautak / un.py
Created June 17, 2012 03:21
un.py
#!/usr/bin/env python
import fractions
# divisor list
def divisor(n):
first_half = []
second_half = [n]
end = n
@ikautak
ikautak / un_gen.py
Created June 17, 2012 03:23
un_gen.py
#!/usr/bin/env python
f = open("./input-gen", "w")
n = 1000*1000*10
f.write(str(n) + " " + "999\n")
for i in range(n):
f.write(str(i + 3) + " ")
@ikautak
ikautak / ln.py
Created June 17, 2012 08:02
ln.py
#!/usr/bin/env python
import sys
mul_map = [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
prime_map = [0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,
@ikautak
ikautak / gen-prime-map.py
Created June 17, 2012 08:03
gen-prime-map.py
#!/usr/bin/env python
prime_map = [0]
def isPrime(n):
if (n < 2):
return 0
elif n == 2:
return 1
@ikautak
ikautak / reptree2go.py
Created June 20, 2012 14:27
reptree2go.py
#!/usr/bin/env python
import sys
out = file("reptree.go", "w")
out.write("func reptree() {\n")
pre_indent = -1
for l in file(sys.argv[1]):
line = l.strip().split(" ")
@ikautak
ikautak / ml_contest2.go
Created June 20, 2012 14:29
ml_contest2.go
package main
import (
"os"
"syscall"
"fmt"
"strconv"
"encoding/csv"
)
@ikautak
ikautak / getopt_sample.c
Created June 24, 2012 12:25
getopt_sample.c
#include <stdio.h>
#include <unistd.h>
int main(int argc, char* argv[]) {
int opt;
while ((opt = getopt(argc, argv, "ab:")) != -1) {
switch (opt) {
case 'a':
printf("option a\n");
@ikautak
ikautak / reptree2py.py
Created July 1, 2012 13:50
reptree2py.py
#!/usr/bin/env python
import sys
out = file(sys.argv[1] + ".py", "w")
out.write(
"""#!/usr/bin/env python
# this file is auto-generated from Reptree output file.
import sys