Last active
February 22, 2018 11:13
-
-
Save lagenorhynque/535408c713af48628799321e017dde75 to your computer and use it in GitHub Desktop.
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
| user> (defn f [n] | |
| (* 2 n)) | |
| #'user/f | |
| user> (map f (range (inc 5))) | |
| (0 2 4 6 8 10) | |
| user> (require '[clojure.math.numeric-tower :refer [expt]]) | |
| nil | |
| user> (defn g [n] | |
| (if (zero? n) | |
| 0 | |
| (expt 2 n))) | |
| #'user/g | |
| user> (map g (range (inc 5))) | |
| (0 2 4 8 16 32) | |
| user> (defn h [n] | |
| (case n | |
| 0 0 | |
| 1 2 | |
| (expt 2 (h (dec n))))) | |
| #'user/h | |
| user> (map h (range (inc 4))) | |
| (0 2 4 16 65536) | |
| user> (defn h' [n] ; condpによる==比較版(任意の数値型に対応) | |
| (condp == n | |
| 0 0 | |
| 1 2 | |
| (expt 2 (h' (dec n))))) | |
| #'user/h' | |
| user> (map h' (range (inc 4))) | |
| (0 2 4 16 65536) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment