factorial: 階乗 (引数は非負整数)
gamma: ガンマ関数 (階乗の拡張. 引数 n が 1以上の整数ならば, n - 1 の階乗に等しい)
sum: 総和
sum-of-squares: 平方の総和
prod: 総積
An example client code to binary-communicate with a TCP server.
TCP サーバとバイナリ通信するクライアントコードの例です.
Give informations of a TCP server to the first argument as a map.
:host is a string representing an IP address or a hostname which can be forward-looked up and :port is an integer represents a port.
| (ns foo | |
| (:require [clojure.test :refer (with-test is are run-tests)])) | |
| (with-test | |
| (defn flatten-map [m kf vf] | |
| (into {} | |
| ((fn g [kv n] | |
| (if (map? n) | |
| (apply concat | |
| (keep (fn [[k v]] (g (conj kv k) v)) n)) |
| % ntmux 5000 irb | |
| irb(main):001:0> |
| (defn insertion-sort [ks] | |
| (reduce (fn [a x] | |
| (let [[h t] (split-with #(< % x) a)] | |
| (concat h [x] t))) | |
| [] ks)) | |
| (defn merge-sort [ks] | |
| (let [c (count ks)] | |
| (if (= c 1) ks | |
| ((fn m [[[ah & ar :as a] [bh & br :as b]]] |
| (defn fibs [a b] (cons a (lazy-seq (fibs b (+' a b))))) | |
| (defn fizzbuzz [x] | |
| (condp #(zero? (mod %2 %1)) x | |
| 15 "FizzBuzz" | |
| 5 "Buzz" | |
| 3 "Fizz" | |
| x)) | |
| (def fibbuzz-seq (map fizzbuzz (fibs 1 1))) |
| (defproject nltry "0.1" | |
| :dependencies [ | |
| [org.clojure/clojure "1.7.0"] | |
| [org.clojure/tools.nrepl "0.2.11"] | |
| [lein-light-nrepl "0.1.3"] | |
| ] | |
| :aot :all | |
| :main nltry.core | |
| :repl-options {:nrepl-middleware [lighttable.nrepl.handler/lighttable-ops]} | |
| ) |
| (def prime-numbers | |
| ((fn f [x] | |
| (cons x | |
| (lazy-seq | |
| (f (first | |
| (drop-while | |
| (fn [n] | |
| (some #(zero? (mod n %)) | |
| (take-while #(<= (* % %) n) prime-numbers))) | |
| (iterate inc (inc x)))))))) |
| (defn factorize [n] | |
| ((fn f [n [h & r :as ps]] | |
| (cond (< n 2) '() | |
| (zero? (mod n h)) (cons h (lazy-seq (f (quot n h) ps))) | |
| :else (recur n r))) | |
| n prime-numbers))) |
| (def sss | |
| (memoize | |
| (fn [s] | |
| (let [n (count s)] | |
| (cond | |
| (zero? n) '(()) | |
| (= n 1) `((~s)) | |
| :else (mapcat | |
| (fn [c] | |
| (let [[a b] (split-at c s)] |