This file contains hidden or 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 parallel-download "1.0.0-SNAPSHOT" | |
;; :description "FIXME: write description" | |
;; :dependencies [[org.clojure/clojure "1.3.0"] | |
;; [clj-http "0.2.7"] | |
;; [enlive "1.0.0-SNAPSHOT"]] | |
;; :dev-dependencies [[swank-clojure "1.3.4"]] | |
;; :main parallel-download.core) | |
(ns parallel-download.core | |
(:use [clojure.string :only (join split)] |
This file contains hidden or 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
type figure = | |
Point | |
| Circle of float | |
| Rectangle of float * float | |
| Square of float;; | |
type 'a with_location = { loc_x: float; loc_y: float; body: 'a };; | |
let diff x y = abs_float (x -. y) |
This file contains hidden or 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 'evil) | |
(setq evil-move-defun-alist | |
'((ruby-mode . (ruby-beginning-of-defun . ruby-end-of-defun)) | |
(c-mode . (c-beginning-of-defun . c-end-of-defun)) | |
(js2-mode . (js2-beginning-of-defun . js2-end-of-defun)))) | |
(defun evil-move-defun (count &optional begin-defun end-defun) | |
"Move by defun" | |
(let ((count (or count 1)) |
This file contains hidden or 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 'elscreen) | |
(defun elscreen-cycle (count &optional previous) | |
"Switch the next/previous screen cyclically by count." | |
(cond | |
((elscreen-one-screen-p) | |
(elscreen-message | |
(format "You cannot escape from screen %d!" | |
(elscreen-get-current-screen)))) | |
(t |
This file contains hidden or 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
# 安直にやる | |
doors1 = (1..100).inject([false] * 100) {|a,p| | |
a.each_with_index.map {|st,i| (i+1) % p == 0 ? !st : st } | |
}.map {|b| b ? :open : :close } | |
# 平方数だけが最終的 open になる、という性質を使う | |
doors2 = (1..100).map {|i| | |
root = Math.sqrt(i) | |
root == root.to_i ? :open : :close | |
} |
This file contains hidden or 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
;; hyone's solution to Pascal's Triangle | |
;; https://4clojure.com/problem/97 | |
(fn [n] (nth (iterate #(vec (map + (conj % 0) (cons 0 %))) '[1]) (dec n))) |
This file contains hidden or 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
;; hyone's solution to Symmetric Difference | |
;; https://4clojure.com/problem/88 | |
#(cond | |
(empty? %1) %2 | |
(empty? %2) %1 | |
:else (apply disj (apply conj %1 %2) (filter %1 %2))) |
This file contains hidden or 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
;; hyone's solution to Merge with a Function | |
;; https://4clojure.com/problem/69 | |
(fn my-merge-with [f & maps] | |
(reduce | |
(fn [a b] | |
(reduce | |
(fn [x [k v]] | |
(assoc x k (if (b k) (f v (b k)) v))) | |
b a)) |
This file contains hidden or 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
;; hyone's solution to Black Box Testing | |
;; https://4clojure.com/problem/65 | |
(defn seq-type [coll] | |
(let [base (empty coll)] | |
(cond | |
(= base {}) :map | |
(= base #{}) :set | |
(= base '()) (if (reversible? coll) :vector :list)))) |
This file contains hidden or 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
;; hyone's solution to Group a Sequence | |
;; https://4clojure.com/problem/63 | |
(fn my-group-by [pred coll] | |
(reduce | |
(fn [dict m] | |
(let [ret (pred m)] | |
(assoc dict ret (conj (or (dict ret) []) m)))) | |
{} coll)) |