clojurescript 側でreplを実現するためのモジュールっぽい weasel をいじってみました。
weaselのディレクトリにある、 weasel-example はプロジェクトになってる ようなので、まずは、README.mdに従って動かしてみます。
このサンプルは、Webサーバー側は動かしてないので、ページは直接自分で 開く必要があります。(ちょっとはまった)
clojurescript 側でreplを実現するためのモジュールっぽい weasel をいじってみました。
weaselのディレクトリにある、 weasel-example はプロジェクトになってる ようなので、まずは、README.mdに従って動かしてみます。
このサンプルは、Webサーバー側は動かしてないので、ページは直接自分で 開く必要があります。(ちょっとはまった)
;; Prablem 101 | |
;;"Elapsed time: 14.696085 msecs" | |
;; 準備 | |
(defn exp [x n] | |
(reduce * (repeat n x))) | |
;; 題意の式の数列を返す関数 | |
(defn un-seq [] | |
(let [un (fn [n] |
(ns euler.pe-102) | |
;; Prablem 102 | |
;; "Elapsed time: 1107.975434 msecs" | |
(defn calc-alfa [[ax ay] [bx by] [cx cy] | |
[px py]] | |
(/ (+ (* (- by cy) (- px cx)) | |
(* (- cx bx) (- py cy))) | |
(+ (* (- by cy) (- ax cx)) | |
(* (- cx bx) (- ay cy))))) |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; create memoised func | |
;; | |
;; momoize in clojure 1.2 and after does not work as I expected. So, I created this macro. | |
(defmacro defn-memo | |
"Creates memoised function. | |
Also creates: | |
accessor of the memoized data which named <fname>-data. | |
resetter of the memoized data which named <fname>-crear." |
(require '[clojure.contrib.io :as io]) | |
(defn get-gcj-args-list [file-name] | |
(map list | |
(iterate inc 1) | |
(map (fn [line-dat] | |
(map (fn [s] (BigInteger. s)) | |
(.split line-dat " "))) | |
(drop 1 (io/read-lines file-name))))) |
(defn snapper [N K] | |
(if (= (repeat N \1) (take N (reverse (Integer/toBinaryString K)))) | |
"ON" | |
"OFF")) |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;;; prime nums | |
(defn sieve [n] | |
(let [n (int n)] | |
"Returns a list of all primes from 2 to n" | |
(let [root (int (Math/round (Math/floor (Math/sqrt n))))] | |
(loop [i (int 3) | |
a (int-array n) | |
result (list 2)] |
(defn jc-queue [one-set] | |
(flatten (repeat one-set))) | |
(defn run-jc [k q N] | |
"run jetcoaster once and returns revenue in euro" | |
(loop [seats k, rest k, queue q, revenue 0, group-num N] | |
(if (or | |
(< rest (first queue)) |
(require '[clojure.contrib.io :as io]) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Main funcs | |
;; step back | |
;; get previous position of the target card | |
(defn un-shuffle [W ab-list] | |
(let [[A B] ab-list] | |
(cond (<= W B) (+ W (- A 1)) |
(require '[clojure.contrib.io :as io]) | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
;; Main funcs | |
;; sort coffee data by | |
;; : in descending order with satisfaction | |
;; : and in accending order with expiry date. | |
(defn sort-coffee-data [dat-list] |