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
;; 第1回 Scheme コードバトン | |
;; | |
;; ■ これは何か? | |
;; Scheme のコードをバトンのように回していき面白い物ができあがるのを楽しむ遊びです。 | |
;; 次回 Shibuya.lisp で成果を発表します。 | |
;; Scheme 初心者のコードを書くきっかけに、中級者には他人のコードを読む機会になればと思います。 | |
;; | |
;; ■ 2 つのルール | |
;; | |
;; (1)自分がこれだと思える変更をコードに加えて2日以内に次の人にまわしてください。 |
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
;; The First Edition Of Scheme Code Baton | |
;; | |
;; * What Is This? | |
;; This is a recreation that we pass Scheme codes as a baton and enjoy it | |
;; changed to something interesting. | |
;; Results are make public at Shibuya.lisp (event about Lisp held in Shibuya, | |
;; Japan). | |
;; We want code baton being a chance to write codes for beginner and to read | |
;; others codes for middles. | |
;; |
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 | |
^{:author "OGINO Masanori" | |
:see-also [["http://www.cs.nott.ac.uk/~gmh/book.html" "Programming in Haskell"]] | |
:doc "A library to make certain number from some numbers. | |
This library solves a well-known problem called \"Ten Puzzle\" or \"Countdown | |
Problem\", but the target number is not limited to 10. You can get any integer | |
or rational number. Also, the number of source numbers is not limited to 4. | |
Note that source numbers are *not always* used once, but never or once. |
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- diff-seq | |
"Returns a lazy seq of numbers in s1 but not in s2. | |
Both of s1 and s2 must be increasing monotonically." | |
[s1 s2] | |
(when-let [x1 (first s1)] | |
(if-let [x2 (first s2)] | |
(cond | |
(= x1 x2) (recur (rest s1) (rest s2)) | |
(> x1 x2) (recur s1 (drop-while (partial > x1) s2)) | |
(< x1 x2) (let [[s11 s12] (split-with (partial > x2) s1)] |