Skip to content

Instantly share code, notes, and snippets.

@faust45
Created January 11, 2020 12:33
Show Gist options
  • Save faust45/eaf59f33b90ace6256b3c872d222abac to your computer and use it in GitHub Desktop.
Save faust45/eaf59f33b90ace6256b3c872d222abac to your computer and use it in GitHub Desktop.
Valid Parentheses
(ns app
(:require [clojure.string :refer [replace]]))
(def s1 "[[][{]]")
(def s2 "[[]][][{]}[]")
(def s3 "[[{}][]]")
(def s4 "([)]")
(def pattern #"\[\]|\{\}|\(\)")
(defn is-valid?
[s]
(let [has-patterns (->> s (re-find pattern))]
(if has-patterns
(-> s (replace pattern "") process)
(if (empty? s)
[:valid]
[:in-valid s]))))
(is-valid? s4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment