Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
20
Task/Sierpinski-carpet/Clojure/sierpinski-carpet.clj
Normal file
20
Task/Sierpinski-carpet/Clojure/sierpinski-carpet.clj
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
(ns example
|
||||
(:require [clojure.contrib.math :as math]))
|
||||
|
||||
(defn in-carpet? [x y]
|
||||
(loop [x x, y y]
|
||||
(cond
|
||||
(or (zero? x) (zero? y)) true
|
||||
(and (= 1 (mod x 3)) (= 1 (mod y 3))) false
|
||||
:else (recur (quot x 3) (quot y 3)))))
|
||||
|
||||
(defn carpet [n]
|
||||
(apply str
|
||||
(interpose
|
||||
\newline
|
||||
(for [x (range (math/expt 3 n))]
|
||||
(apply str
|
||||
(for [y (range (math/expt 3 n))]
|
||||
(if (in-carpet? x y) "*" " ")))))))
|
||||
|
||||
(println (carpet 3))
|
||||
Loading…
Add table
Add a link
Reference in a new issue