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
window.RTCPeerConnection = (window.webkitRTCPeerConnection || // Chrome | |
window.mozRTCPeerConnection); // Firefox | |
window.RTCSessionDescription = (window.RTCSessionDescription || | |
window.mozRTCSessionDescription); | |
window.RTCIceCandidate = (window.RTCIceCandidate || | |
window.mozRTCIceCandidate); |
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
; 2章データ型 | |
; コレクション | |
;; リスト | |
;;; 以下は同じ | |
'(1 2 3) | |
(list 1 2 3) | |
; 'はリーダーマクロで(list ...) に展開される | |
(first '(1 2 3 4)) | |
(rest '(1 2 3 4)) | |
(last '(1 2 3 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
(def won-pattern [2r111000000 2r000111000 2r000000111 2r100100100 2r010010010 2r001001001 2r100010001 2r001010100]) | |
(defn win? [prots] | |
(if (> 2 (count prots)) false | |
(let [current-bit (apply bit-or (map #(.intValue (Math/pow 2 (- % 1))) prots))] | |
(some (fn [x] (= x (bit-and current-bit x))) won-pattern)))) | |
(defn judge [a-prots b-prots f?] | |
(let [target (if f? a-prots b-prots) | |
enemy (if f? b-prots a-prots) |
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
(ns poker.core) | |
(defn to-pairs [coll] | |
(loop [pairs [] | |
ranks (set (map second coll))] | |
(let [t (first ranks)] | |
(if (nil? t) pairs | |
(recur (conj pairs (filter #(= t (second %)) coll)) (rest ranks)))))) | |
(defn is-4K? [pairs] | |
(not (empty? (filter #(= 4 (count %)) pairs)))) |
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
(ns poker2.core) | |
; http://qiita.com/Nabetani/items/cbc3af152ee3f50a822f | |
; http://qiita.com/cielavenir/items/d96889cbb7fd246c3ccb | |
(defn to-pairs [coll] | |
(loop [pairs [] | |
ranks (set (map second coll))] | |
(let [t (first ranks)] | |
(if (nil? t) pairs | |
(recur (conj pairs (filter #(= t (second %)) coll)) (rest ranks)))))) |
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
(ns image-rotation.core | |
(:require [clojure.string :as string])) | |
; http://qiita.com/Nabetani/items/9d80de41903775296ca6 | |
(defn take-by-nth [coll n step] | |
(reverse (take-nth n (concat (nthrest coll step) (take step coll))))) | |
(defn flip [f] | |
(fn [& args] (apply f (reverse args)))) |
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
// こういうメソッドがあったとして | |
int someMethod(int n) { | |
if (n < 1) { | |
return 1; | |
} else { | |
return n * someMethod(n - 1); | |
} | |
} | |
// コンパイラレベルでこういうコードや |
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
; 再帰について | |
; Clojureの再帰 | |
;; loopとrecur | |
(defn size [v] | |
(if (empty? v) | |
0 | |
(inc (size (rest v))))) | |
; (size [1 2 3]) |
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
(defn take | |
"Returns a lazy sequence of the first n items in coll, or all items if | |
there are fewer than n." | |
{:added "1.0" | |
:static true} | |
[n coll] | |
(lazy-seq | |
(when (pos? n) | |
(when-let [s (seq coll)] | |
(cons (first s) (take (dec n) (rest s))))))) |
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
; (sourcec ->) | |
(defmacro -> | |
"Threads the expr through the forms. Inserts x as the | |
second item in the first form, making a list of it if it is not a | |
list already. If there are more forms, inserts the first form as the | |
second item in second form, etc." | |
{:added "1.0"} | |
([x] x) | |
([x form] (if (seq? form) |
OlderNewer