Skip to content

Instantly share code, notes, and snippets.

@deltam
Created August 19, 2010 14:32
Show Gist options
  • Save deltam/538018 to your computer and use it in GitHub Desktop.
Save deltam/538018 to your computer and use it in GitHub Desktop.
(ns mathew12
(:use [clojure.contrib.seq-utils :only (includes? indexed)]))
(def m12 [0 1 2 3 4 5 6 7 8 9 10 11])
; 実験
(comment
(map (fn [m i] (vector m i)) m12 (vec (range 0 11)))
(indexed m12)
(let [v [3,4]] (nth v (inc (.indexOf v 3))))
(let [v [3,4]] (first (drop-while #(= % 3) v)))
(let [v [3,4]] (first (filter #(not (= % 3)) v)))
(let [v [3,4]] (take (inc (count v)) (cycle v)))
)
(defn chikan-next
"置換配列kan内のnの置換先の値を返す"
[kan n]
(second
(drop-while #(not (= % n))
(cycle kan))))
(defn junkan
"mに対してjの循環置換を作用させる"
[m j]
(map #(if (includes? j (first %))
(nth m (chikan-next j (first %)))
(second %))
(indexed m)))
; 実行例
(comment
(junkan m12 [1, 0])
(1 0 2 3 4 5 6 7 8 9 10 11)
(junkan m12 [1, 0, 4])
(4 0 2 3 1 5 6 7 8 9 10 11)
(reduce junkan [m12 [0 1] [1 0]])
(0 1 2 3 4 5 6 7 8 9 10 11)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment