Skip to content

Instantly share code, notes, and snippets.

View ypsilon-takai's full-sized avatar
😊
taking care of things around myself

Ypsilon.takai ypsilon-takai

😊
taking care of things around myself
View GitHub Profile

clojurescript 側でreplを実現するためのモジュールっぽい weasel をいじってみました。

手始めにweaselのサンプル

weaselのディレクトリにある、 weasel-example はプロジェクトになってる ようなので、まずは、README.mdに従って動かしてみます。

このサンプルは、Webサーバー側は動かしてないので、ページは直接自分で 開く必要があります。(ちょっとはまった)

@ypsilon-takai
ypsilon-takai / pe_101.clj
Created June 20, 2015 16:40
Euler: Problem 101
;; Prablem 101
;;"Elapsed time: 14.696085 msecs"
;; 準備
(defn exp [x n]
(reduce * (repeat n x)))
;; 題意の式の数列を返す関数
(defn un-seq []
(let [un (fn [n]
@ypsilon-takai
ypsilon-takai / pe_102.clj
Created June 25, 2015 16:13
Euler: Problem 102
(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)))))
@ypsilon-takai
ypsilon-takai / defn-memo.clj
Created September 1, 2011 10:15
Creates memoised function.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 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."
@ypsilon-takai
ypsilon-takai / gcj_inout.clj
Created September 12, 2011 04:55
Support funcs for Google Code Jam
(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)))))
@ypsilon-takai
ypsilon-takai / gcj_prac1.clj
Created September 13, 2011 10:13
GCJJ Practice1
(defn snapper [N K]
(if (= (repeat N \1) (take N (reverse (Integer/toBinaryString K))))
"ON"
"OFF"))
@ypsilon-takai
ypsilon-takai / gcj_prac2.clj
Created September 13, 2011 10:14
GCJJ Practice2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; 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)]
@ypsilon-takai
ypsilon-takai / gcj_prac3.clj
Created September 13, 2011 10:15
GCJJ Practice3
(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))
@ypsilon-takai
ypsilon-takai / gcjj_pA.clj
Created October 1, 2011 14:31
Code Jam Japan Problem A
(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))
@ypsilon-takai
ypsilon-takai / gcjj_pB.clj
Created October 1, 2011 14:46
Code Jam Japan Problem B
(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]