I hereby claim:
- I am mavant on github.
- I am mavant (https://keybase.io/mavant) on keybase.
- I have a public key whose fingerprint is 6C6F D940 8D96 832D 6CDD 740B DD9B DC4A A11E 21D0
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
defn line->ints [line] | |
map | |
fn [l] | |
Integer/parseInt l | |
split line #"\s+" | |
defn solutions->outputs [solutions] | |
map | |
fn [n s] | |
str "Case #" |
(use '[clojure.string :as s]) | |
(defn remove-whitespace "Given a string representing some Clojure code as input, remove superfluous whitespace." [c] (s/replace c #"\s+" " ")) | |
(defn parens->indents "Given a list of lines in which each begins an expression, prepends a newline and the appropriate number of tabs to each line." [c] (map (fn [a b] (str "\n" (apply str (repeat a "\t")) b)) (indent-levels (match-parens c)) (split-on-all-parens c))) | |
(defn remove-empty-lines "Given a list of strings, filters out any string which contains no word characters." [l] (filter (fn [c] (< 0 (count (re-seq #"\w" c)))) l)) | |
(defn indent-levels "Given a list of lines of code, determine the appropriate number of tabs for each line." [l] (reduce (fn [a b] (conj a (+ (peek a) (if (= b ")") -1 1)))) [-1] l)) | |
(use '[clojure.string :as s]) | |
(defn remove-whitespace "Given a string representing some Clojure code as input, remove superfluous whitespace." [c] (s/replace c #"\s+" " ")) | |
(defn indent-levels "Given a list of lines of code, determine the appropriate number of tabs for each line." [l] (reduce (fn [a b] (conj a (+ (peek a) (if (= b ")") -1 1)))) [-1] l)) | |
(defn remove-empty-lines "Given a list of strings, filters out any string which contains no word characters." [l] (filter (fn [c] (< 0 (count (re-seq #"\w" c)))) l)) | |
(defn match-parens "Given a string of code, return a list of all the parentheses in the code, in the order in which they appear." [c] (re-seq #"[\)\(]" c)) |
use '[clojure.string :as s] | |
defn remove-whitespace "Given a string representing some Clojure code as input, remove superfluous whitespace." [c] | |
s/replace c #"\s+" " " | |
defn indent-levels "Given a list of lines of code, determine the appropriate number of tabs for each line." [l] | |
reduce | |
fn [a b] | |
conj a | |
peek a | |
if |
use '[clojure.string :as s] | |
defn remove-whitespace "Given a string representing some Clojure code as input, remove superfluous whitespace." [c] | |
s/replace c #"\s+" " " | |
defn indent-levels "Given a list of lines of code, determine the appropriate number of tabs for each line." [l] | |
reduce | |
fn [a b] | |
conj a | |
peek a | |
if | |
= b ")" |
(defmacro list-pythonize "Convert a list of expressions in Clojure to semantic-whitespace form." ([l] (macroexpand-1 `(list-pythonize ~l 0))) ([l n] (map (fn [x] (if (list? x) (concat (list "\n") (repeat n "\t") (macroexpand-1 `(list-pythonize ~x ~(+ n 1))) ) x)) l))) | |
(print (macroexpand-1 '(list-pythonize (defn tabs->parens [c] (map add-parens (rest (split-on-newlines c)) (list-deltas (code->numtabs c))))))) | |
;=> | |
;(defn tabs->parens [c] ( | |
; map add-parens ( | |
; rest ( | |
; split-on-newlines c)) ( | |
; list-deltas ( |
(defmacro s-expr->semantic-whitespace "Convert a list of expressions in Clojure to semantic-whitespace form." ([l] (apply str (macroexpand-1 `(s-expr->semantic-whitespace ~l 1)))) ([l n] (map (fn [x] (if (list? x) (apply str "\n" (apply str (repeat n "\t")) (interpose " "(macroexpand-1 `(s-expr->semantic-whitespace ~x ~(+ n 1)))) ) x)) l))) | |
(print (macroexpand-1 '(s-expr->semantic-whitespace (defn | |
tabs->parens [c] (map add-parens (rest | |
(split-on-newlines | |
c)) (list-deltas (code->numtabs c))))))) | |
;=> | |
;defntabs->parens[c] |
(defmacro s-expr->semantic-whitespace "Convert a list of expressions in Clojure to semantic-whitespace form." ([l] (apply str (interpose " "(macroexpand-1 `(s-expr->semantic-whitespace ~l 1))))) ([l n] (map (fn [x] (if (list? x) (apply str "\n" (apply str (repeat n "\t")) (interpose " "(macroexpand-1 `(s-expr->semantic-whitespace ~x ~(+ n 1)))) ) x)) l))) | |
(print (macroexpand-1 '(s-expr->semantic-whitespace (defn | |
tabs->parens [c] (map add-parens (rest | |
(split-on-newlines | |
c)) (list-deltas (code->numtabs c))))))) | |
;=> | |
;defntabs->parens[c] |
(defmacro s-expr->semantic-whitespace | |
"Convert a list of expressions in Clojure to semantic-whitespace form." | |
([l] (apply str (interpose " " (macroexpand-1 `(s-expr->semantic-whitespace ~l 1))))) | |
([l n] (map (fn [x] (if (list? x) (apply str "\n" (apply str (repeat n "\t")) (interpose " " (macroexpand-1 `(s-expr->semantic-whitespace ~x ~(+ n 1)))) ) x)) l))) | |
(defn split-on-newlines "Splits a string into a list of strings by any newline characters." [s] (clojure.string/split s #"\n")) | |
(defn indented? "Returns true if the string has at least one tab character, otherwise false." [s] (not (nil? (re-find #"\t" s)))) | |
(defn remove-first-tab "Removes the first tab character from a string." [x] (clojure.string/replace-first x #"\t" "")) |