This file contains 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
(use '[clojure.contrib.combinatorics :only (permutations)]) | |
(defn- valid? [board] | |
{:pre [(vector? board)]} | |
(let [n (count board)] | |
(every? | |
#(let [[i j] %] (and (not= (board i) (board j)) | |
(not= (- i (board i)) (- j (board j))) | |
(not= (+ i (board i)) (+ j (board j))))) | |
(for [i (range n) j (range n) :when (not= i j)] (vector i j))))) |
This file contains 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
(use '[clojure.contrib.graph] | |
'[clojure.test]) | |
(def empty-graph (struct directed-graph #{} {})) | |
(def test-graph-1 | |
(struct directed-graph | |
#{:a :b :c :d :e} | |
{:a #{:b :c} | |
:b #{:a :c} |
This file contains 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
/* | |
* 共通鍵暗号化 | |
* 仕様: | |
* キー = {キーの長さ,左循環シフト回数,キー本体} | |
* 平文 = byte列 | |
* 暗号化操作 | |
* 1.平文を、キー本体のサイズごとに分割し、部分平文を作る | |
* 2.部分平文に対し、左循環シフト回数分、左循環シフトし、シフト文を作る | |
* 3.シフト文とキー本体のxorをとり、暗号化部分バイト列を作る | |
* 4.暗号化部分バイト列を結合し、暗号化文を作る |
This file contains 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
(use '[clojure.contrib.duck-streams :only (write-lines writer read-lines)]) | |
(use '[clojure.contrib.str-utils :only (re-split)]) | |
(in-ns 'clojure.contrib.duck-streams) | |
(def *default-encoding* "Shift_JIS") | |
(in-ns 'user) | |
(defmacro awk-print [input-file f] | |
`(map ~f (for [line# (read-lines ~input-file)] line#))) |
This file contains 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
Require Import List. | |
Check 1::2::nil. | |
Fixpoint suffixes{A:Set}(xs:list A):list (list A) := | |
match xs with | |
| nil => nil | |
| _::xs' => xs :: (suffixes xs') | |
end. |
This file contains 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
/** | |
* Example of AbstractFactory pattern | |
* | |
* create OS Specific GUIWidget with same operation. | |
* | |
*/ | |
trait Button { | |
def paint: String | |
} |
This file contains 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
abstract class Product | |
abstract class PizzaBuilder { | |
var dough: String | |
var sauce: String | |
var topping: String | |
def withDough(dough: String): PizzaBuilder | |
def withSauce(sauce: String): PizzaBuilder | |
def withTopping(topping: String): PizzaBuilder |
This file contains 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.designrecipe.jp/2011/01/03/factory-method-strategy/ | |
abstract class ListPrinter { | |
def printList(list: List[String]) { | |
val comparator = createComparator | |
list.sortWith(comparator).foreach(println) | |
} | |
protected def createComparator: (String, String) => Boolean | |
} |
This file contains 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
@cloneable | |
class Command(value: Int, name: String) { | |
override def clone = super.clone | |
override def toString = value + ": " + name | |
} | |
object Main { | |
def main(args: Array[String]) = { | |
val com1 = new Command(1, "Hoge") | |
val com2 = com1.clone |
This file contains 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 Singleton { | |
var name: String = "" | |
} | |
object Main { | |
def main(args: Array[String]) { | |
var s1 = Singleton | |
var s2 = Singleton | |
println (s1 eq s2) | |
s1.name = "First" |