This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Check if the graph is bipartite. | |
""" | |
import collections | |
class Graph(object): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Combinatorial Optimization - B.Korte, J.Vygen | |
Algorithm 1.2 | |
Merge-Sort Algorithm | |
""" | |
def merge_sort(a): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Combinatorial Optimization - B.Korte, J.Vygen | |
Algorithm 1.1 | |
Path Enumeration Algorithm | |
""" | |
def back_track(n): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import struct | |
from bitarray import bitarray | |
def double_to_bitstring(d): | |
b = bitarray() | |
b.frombytes(struct.pack('!d', d)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FizzBuzz { | |
private val divs = List((3, "Fizz"), (5, "Buzz")) | |
def fizzBuzz(n: Int): String = { | |
val ret = (divs map {case (i, s) => if (n % i == 0) s else ""}).mkString | |
if (ret.isEmpty) n.toString else ret | |
} | |
def main(args: Array[String]) { | |
def printAll(n: Int) { (1 to n) foreach {n => println(fizzBuzz(n))} } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 行列累乗を使ってフィボナッチ数列を求めてみる | |
// 参考 | |
// http://blog.scala4java.com/2011/12/matrix-multiplication-in-scala-single.html | |
import annotation.tailrec | |
import scala.util.control.Exception._ | |
object FibonacciMatrix { | |
type Matrix = Array[Array[BigInt]] | |
def mul(m1: Matrix, m2: Matrix) = { |
NewerOlder