Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (ns test)
- "Welcome to the Getting Started REPL! 💜"
- (comment
- (+ (* 2 2)
- 2)
- (Math/abs -1)
- (hello "Calva REPL")
- (defn hello [s]
- (str "Hello " s))
- (range 10)
- "I ♥️ Clojure")
- (defn dada [x, y]
- (* x y))
- (dada 2 3)
- (dada `5 5)
- (defn teq [x]
- x)
- (teq 2)
- ;; peek - get first
- ;; rest - all except first
- (defn mix [a, n]
- (conj (rest a) (peek a)))
- (mix (list 1 2 3) 2)
- (defn nth-2 [a, n]
- (nth a n))
- (defn mix-2 [a, n]
- (repeat n a))
- (mix-2 "x" 5)
- (repeat (count (list 1 2 3 4)) "x")
- (for [x [0 1 2 3 4 5]]
- (* 2 x))
- (defn mix-3 [a, n]
- (repeat n a))
- (defn shuffle [a]
- (if (= (count a) 2)
- (list a (cons (peek a) (rest a)))
- "net"))
- (shuffle (list 1 2))
- (shuffle (list 1 2 3))
- (use '[clojure.string :only (join)])
- (defn ins-str [string substring index]
- (join (list (subs string 0 index) substring (subs string (inc index)))))
- (ins-str "abcd" "ab" 0)
- (defn permutations [s]
- (if (= (count s) 1)
- (list s)
- (for [head s rest (permutations (rest s))]
- (cons head rest))))
- (permutations (list 1 2 3))
- (concat (list 1 2 3) (list 5 4))
- (defn mix-3 [s]
- (for [head s rest (remove #{head} s)]
- rest))
- (mix-3 "abc")
- (cons 4 (list 1 2 3))
- (concat (list 1 2 3) (list 4))
- (reduce str '(1 2 3))
- (defn shuffle-2 [a]
- (if (= (count a) 2)
- (list (concat a (cons (peek a) (rest a))))
- (concat
- (cons (first a) (shuffle-2 (rest a)))
- (conj (shuffle-2 (rest a)) (first a)))))
- (shuffle-2 (list 1 2 3))
- (defn sum [x]
- (if (= (count x) 2)
- (+ (nth x 0) (nth x 1))
- (+ (first x) (sum (rest x)))))
- (sum (list 1 2))
- (sum `(1 2 3))
- (defn sample-c [a]
- (if (= (count a) 1)
- (list (list (+ (first a) 1) 2 3) (list 1 2 0))
- (concat
- (sample-c (list (first a)))
- (sample-c (rest a)))))
- (sample-c `(1))
- (sample-c `(1 2 3))
- (apply str (list "The" " " "Brown" " " "asdasd"))
- (if (= "aa" "bb") "da" "net")
- (get "abc" 1)
- (defn join-2 [& args]
- (apply str args))
- (apply str (apply str (list 'a 'b 'c)) "ab" "assa")
- ;; ------- ;;
- (join-2 "a" "b" "AA")
- (join-2 (get "aqa" 1) "b" "AA")
- (defn tqd [a, n]
- a)
- (tqd "abcd" 3)
- (defn permutations-2 [s]
- (if (= (count s) 1)
- (list s)
- (for [head s rest (permutations (rest s))]
- (cons head rest))))
- (permutations-2 (list 1 2 3))
- ;; p - prefix to add
- ;; a - list of elements
- ;; n - number of elements (count a)
- ;; ex - exclude
- (defn per_add [p, a, n]
- (if (= n 0)
- nil
- (if (= (nth a (- n 1)) (last p))
- (per_add p a (- n 1) )
- (concat
- (conj (per_add p a (- n 1) )
- (concat p (list (nth a (- n 1)))))))))
- (per_add `(0 1 2) (list 1 2 3) 3)
- (defn perm_of_len [a, n]
- (if (= n 0)
- nil
- (per_add (first (perm_of_len a (- n 1))) a n)))
- (perm_of_len `(0 1 2 3) 4)
- (defn per_list [a, n]
- (if (= n 0)
- nil
- (concat
- (conj (per_list a (- n 1))
- a))))
- (per_list (list 1 2 3) 3)
- (subs "aa" 0 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement