This gist has moved to https://gist.github.com/3937083 To be deleted near future
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
% ntmux 5000 irb | |
irb(main):001:0> |
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 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]]] |
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 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))) |
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
(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]} | |
) |
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
; 2012.03.23 境界の処理がイマイチだったので全面書き換え | |
; clojure.math.numeric-tower (https://github.com/clojure/math.numeric-tower) | |
; が必要. | |
; clojure 1.3 向け | |
(use '[clojure.math.numeric-tower :only (floor)]) | |
; 長さ w のベクタの, 長さ h のベクタとして与えられる | |
; 解像度 w * h の値マップ src を双線形補完を用いて | |
; 解像度 W * H に拡大縮小し, |
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 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)] |
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
#include <sys/types.h> /* read */ | |
#include <sys/socket.h> /* accept, bind, getsockname, listen, socket */ | |
#include <sys/uio.h> /* read */ | |
#include <sys/wait.h> /* waitpid */ | |
#include <arpa/inet.h> /* htons */ | |
#include <errno.h> /* errno */ | |
#include <fcntl.h> /* open */ | |
#include <signal.h> /* kill, sigaction */ | |
#include <stdio.h> /* BUFSIZ */ | |
#include <stdlib.h> /* daemon, exit */ |
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 dce.core | |
(:import java.net.URL clojure.lang.DynamicClassLoader) | |
(:gen-class)) | |
(defn -main [abs-path target-ns & args] | |
(let [ccl (.getContextClassLoader (Thread/currentThread)) | |
dcl (if (instance? DynamicClassLoader ccl) ccl | |
(let [l (DynamicClassLoader. ccl)] | |
(.setContextClassLoader (Thread/currentThread) l) | |
l))] |
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.set :refer (difference)]) | |
(defn sudoku-level0 [coll] | |
(let [ics (vec (map #(if % #{%} (set (range 1 10))) coll)) | |
cnb (fn [cs i] | |
(set | |
(keep #(if (= 1 (count %)) (first %)) | |
(concat | |
(map first (partition-all 1 9 (drop (mod i 9) cs))) | |
(take 9 (drop (* 9 (quot i 9)) cs)) |
OlderNewer