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
(defmacro condp-> | |
"Takes an expression and a set of predicate/form pairs. Threads expr (via ->) | |
through each form for which the corresponding predicate is true of expr. | |
Note that, unlike cond branching, condp-> threading does not short circuit | |
after the first true test expression." | |
[expr & clauses] | |
(assert (even? (count clauses))) | |
(let [g (gensym) | |
pstep (fn [[pred step]] `(if (~pred ~g) (-> ~g ~step) ~g))] | |
`(let [~g ~expr |
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 hackerrank.sequence-full-of-colors.core) | |
(defn count-color [codes color] | |
(->> codes | |
(filter #(= color %)) | |
(count))) | |
(defn eq [codes & colors] | |
(->> colors | |
(map #(count-color codes %)) |
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 comments.core | |
(:require [clojure.string :as str] | |
[clojure.zip :as z])) | |
(defn raw->comment-map [raw] | |
(->> (str/split raw #"\n") | |
(map #(str/trim %)) | |
rest | |
(map #(str/split % #" ")) | |
(map-indexed (fn [idx x] (apply vector (str (inc idx)) x))) |
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 my.solve) | |
(defn prepare-data-structure [arr] | |
(->> (map-indexed vector arr) | |
(mapcat | |
(fn [[i a]] | |
(map (fn [[j v]] {:val v :idx [i j]}) | |
(map-indexed vector a)))))) | |
(defn expand-adjacents [[i j]] |
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
(let [arr [[0, 0, 0, 2, 2], | |
[1, 1, 7, 4, 4], | |
[2, 2, 4, 2, 4], | |
[2, 1, 4, 4, 4], | |
[2, 7, 7, 4, 4], | |
[4, 6, 6, 0, 4], | |
[4, 4, 6, 4, 4], | |
[4, 4, 6, 4, 4]]] | |
(->> (flatten arr) | |
(partition-by identity) |
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
(def I (atom {:inventory1 1000 :inventory2 0})) ; สร้าง atom ที่เก็บ map ของ inventories แล้ว bind ไว้ที่ Var I | |
@I | |
=> {:inventory1 1000, :inventory2 0} ; deref ดูค่า atom I ในปัจจุบัน | |
; ประกาศฟังก์ชัน move-amount รับ 4 อาร์กิวเม้น inventories, from-key, to-key, n | |
(defn move-amount [inventories from-key to-key n] | |
(let [from-val (get inventories from-key) ; ใช้ค่าจาก from-key ที่เป็น keyword ไปดึงค่าออกจาก inventories ซึ่งเป็น map bind ไว้ที่ from-val | |
to-val (get inventories to-key)] ; ดึงค่าออกจาก map ด้วย to-key bind ไว้ที่ to-val | |
(assoc inventories from-key (- from-val n) ; ใส่ค่ากลับไปที่ inventories โดยใช้ from-key เป็น key ส่วน value คือ from-val - n |
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
; This line is commented out | |
(this-code-will-be-executed) ; (this-code-will-not-be-executed) | |
(defn developing-function [& _] ) | |
(comment ; Use this in development. Remove it when finish. | |
(developing-fuction 1 2 3 4)) ; Send inner expression to the repl | |
; #_ is use to comment out an expression quickly | |
(defn sameple-code | |
[api] |
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 .handler | |
(:require [compojure.api.sweet :refer [GET defapi context]] | |
[ring.util.http-response :refer [ok]] | |
[compojure.api.swagger :refer [swagger-routes]])) | |
(defapi app | |
(swagger-routes) | |
(GET "/events" [] | |
:query-params [name :- String] | |
(ok {:message (str "Hello, " name)}))) |
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 demo-are.core-test | |
(:require [clojure.test :refer :all] | |
[demo-are.core :refer [convert]])) | |
(deftest convert-test1 | |
(let [in {:user-name "tap" | |
:email1 "tap@pat.tap" | |
:email2 "pat@tap.pat" | |
:address {:steet "Rama 1"} | |
:latitude "123" |
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 a-namespace | |
(:require [clojure.string :refer [join]])) | |
(defn dashes [] | |
(->> (iterate dec 10) | |
(map #(repeat % "-")) | |
(map join))) | |
(defn draw [f] | |
(->> (map vector (dashes) (f)) |