- Hubot: GitHub製ボットフレームワーク(CoffeeScript)
- アダプター: ボットを動かすサービスの差を吸収するレイヤー
- スクリプト: コマンドに対するアクションを規定
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 a&b [n] | |
(loop [n n, a (/ 1.0 (* 2 (Math/pow 3 0.5))), b (/ 1.0 3)] | |
(if (= n 0) | |
[a b] | |
(let [a' (/ (+ a b) 2)] | |
(recur (dec n) a' (Math/pow (* a' b) 0.5)))))) | |
;; => (time (/ 1 (first (a&b 100)))) | |
;; "Elapsed time: 0.04547 msecs" | |
;; 3.141592653589795 |
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 '[clojure.core.async :as a] | |
'[kitchen-async.promise :as p] | |
'[kitchen-async.promise.from-channel]) | |
(comment | |
;; cf. https://gist.github.com/swannodette/5888989 | |
(defn debounce | |
([c ms] (debounce (a/chan) c ms)) |
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 repeating-decimal) | |
(defn repeating-decimal [n] | |
(loop [rem 1 rems #{} divs [] i 0] | |
(let [div (int (/ (* rem 10) n)) | |
rem (mod (* rem 10) n)] | |
(if (and (not= rem 0) (contains? rems rem)) | |
[n divs] | |
(when (not= rem 0) | |
(recur rem (conj rems rem) (conj divs div) (inc i))))))) |
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 six-length.core | |
(:require [clojure.core.reducers :as r] | |
[clojure.string :as s]) | |
(:import [java.security MessageDigest] | |
[javax.xml.bind DatatypeConverter])) | |
(set! *warn-on-reflection* true) | |
(def hexdigest | |
(let [digester (MessageDigest/getInstance "MD5")] |
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 sig Digit {} | |
one sig One, Two, Three, Four, Five, Six, Seven, Eight, Nine extends Digit {} | |
sig Cell {content: Digit} | |
abstract sig Group { | |
cells: set Cell | |
} { | |
no disj c, c': cells | c.content = c'.content | |
} |
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 gauche.partcont) | |
(use util.queue) | |
(define-class <channel> (buf takes puts)) | |
(define (chan) | |
(make <channel> (make-queue) (make-queue) (make-queue))) | |
(define-syntax go | |
(syntax-rules () |
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 with-retry [n f] | |
(letfn [(try-once [i] | |
(try | |
(f) | |
(catch Exception e | |
(if (pos? i) | |
#(try-once (dec i)) | |
(throw e)))))] | |
(trampoline try-once n))) |
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 apply-ctor | |
(import [java.lang.reflect Constructor])) | |
(defn- acceptable-types? [ptypes atypes] | |
(and (= (count ptypes) (count atypes)) | |
(every? (fn [[ptype atype]] | |
(or (= ptype atype) | |
((ancestors atype) ptype))) | |
(map vector ptypes atypes)))) |
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 actions | |
(repeatedly (read) (fn [] [(read) (read)]))) | |
(defn step [[[[t op] & as' :as as] temp temps] time] | |
(let [temp' (+ temp (if (= time t) (get '{out 3 in 5} op) 0))] | |
[(if (= time t) as' as), (max (dec temp') 0), (conj temps temp')])) | |
(defn calc [actions] | |
(let [zs (count (filter zero? (last (reduce step [actions 0 []] (range 24)))))] | |
(+ zs (* 2 (- 24 zs))))) |