Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defn length-one [lst] (filter (fn [x] (= 1 (count x))) lst))
- (defn delete-from-set [x lst] (set (filter (fn [n] (not (= n x))) lst)))
- (defn delete-one-from-one-row [n lst] (into [] (map (fn [x] (if (= 1 (count x))
- x (delete-from-set n x))) lst)))
- (defn delete-all-from-one-row
- ([lst] (delete-all-from-one-row lst (length-one lst)))
- ([lst acc]
- (if
- (empty? acc) lst
- (delete-all-from-one-row (delete-one-from-one-row (first (first acc)) lst) (rest acc)))))
- (defn delete-all-from-all-rows [lst] (map (fn [x] (delete-all-from-one-row x)) lst))
- (defn get-first-column [lst] (into [] (map (fn [x] (first x)) lst)))
- (defn delete-first-column [lst] (map (fn [x] (rest x)) lst))
- (defn transpose-matrix
- ([lst] (transpose-matrix lst ()))
- ([lst acc]
- (if
- (empty? (first lst)) (reverse acc)
- (transpose-matrix (delete-first-column lst) (cons (get-first-column lst) acc)))))
- (defn delete-all-from-all-columns [lst] (transpose-matrix (delete-all-from-all-rows (transpose-matrix lst))))
- (defn get-first-submatrix [lst]
- (into [] (apply concat (list (take 3 (first lst)) (take 3 (second lst)) (take 3 (second (rest lst)))))))
- (defn delete-first-submatrix
- ([lst] (delete-first-submatrix lst () 0))
- ([lst acc n]
- (cond
- (empty? lst) (reverse acc)
- (>= n 3) (delete-first-submatrix (rest lst) (cons (first lst) acc) n)
- :else(delete-first-submatrix (rest lst) (cons (drop 3 (first lst)) acc) (inc n)))))
- (defn without-zeros
- ([lst] (without-zeros lst ()))
- ([lst acc]
- (cond
- (empty? lst) (reverse acc)
- (empty? (first lst)) (without-zeros (rest lst) acc)
- :else(without-zeros (rest lst) (cons (first lst) acc)))))
- (defn submatrices-to-rows
- ([lst] (submatrices-to-rows lst ()))
- ([lst acc]
- (if
- (empty? lst) (reverse acc)
- (submatrices-to-rows (without-zeros (delete-first-submatrix lst)) (cons (get-first-submatrix lst) acc)))))
- (defn delete-from-rows-and-columns [lst] (delete-all-from-all-columns (delete-all-from-all-rows lst)))
- (defn complete-delete [lst]
- (submatrices-to-rows (delete-all-from-all-rows (submatrices-to-rows (delete-from-rows-and-columns lst)))))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement