Comment detail

文字列で+を表示する (Nested Flatten)
clojure に挑戦してみました。
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
(defn plus [st]
  (let [len (.length st)
        line-w (inc (* len 3))
        coll (apply concat
               (interleave
                 (partition len (range 1 line-w))
                 (list (repeat len len)(repeat len (* len 2))'())))
        coll-y (concat (repeat (inc len) 0) coll
                 (repeat (dec len) (* len 3))(reverse coll))
        coll-x (apply concat (reverse (split-at (* len 3) coll-y)))
        matrix (map (fn [x y] (vector x y)) coll-x coll-y)
        str-12 (apply concat (repeat 12 (seq st)))
        ms-map (apply hash-map (interleave matrix str-12))]
    (apply str
      (map #(apply str %)
        (interpose "\n"
          (partition (inc line-w)
            (for [y (range 0 line-w) x (range 0 (inc line-w))]
              (format "%s" (get ms-map (vector x y) " ")))))))))

(println (plus "doukaku"))

Index

Feed

Other

Link

Pathtraq

loading...