Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1.  
  2. (defn length-one [lst] (filter (fn [x] (= 1 (count x))) lst))
  3.  
  4. (defn delete-from-set [x lst] (set (filter (fn [n] (not (= n x))) lst)))
  5.  
  6. (defn delete-one-from-one-row [n lst] (into [] (map (fn [x] (if (= 1 (count x))
  7. x (delete-from-set n x))) lst)))
  8.  
  9. (defn delete-all-from-one-row
  10. ([lst] (delete-all-from-one-row lst (length-one lst)))
  11. ([lst acc]
  12. (if
  13. (empty? acc) lst
  14. (delete-all-from-one-row (delete-one-from-one-row (first (first acc)) lst) (rest acc)))))
  15.  
  16. (defn delete-all-from-all-rows [lst] (map (fn [x] (delete-all-from-one-row x)) lst))
  17.  
  18. (defn get-first-column [lst] (into [] (map (fn [x] (first x)) lst)))
  19.  
  20. (defn delete-first-column [lst] (map (fn [x] (rest x)) lst))
  21.  
  22. (defn transpose-matrix
  23. ([lst] (transpose-matrix lst ()))
  24. ([lst acc]
  25. (if
  26. (empty? (first lst)) (reverse acc)
  27. (transpose-matrix (delete-first-column lst) (cons (get-first-column lst) acc)))))
  28.  
  29. (defn delete-all-from-all-columns [lst] (transpose-matrix (delete-all-from-all-rows (transpose-matrix lst))))
  30.  
  31. (defn get-first-submatrix [lst]
  32. (into [] (apply concat (list (take 3 (first lst)) (take 3 (second lst)) (take 3 (second (rest lst)))))))
  33.  
  34. (defn delete-first-submatrix
  35. ([lst] (delete-first-submatrix lst () 0))
  36. ([lst acc n]
  37. (cond
  38. (empty? lst) (reverse acc)
  39. (>= n 3) (delete-first-submatrix (rest lst) (cons (first lst) acc) n)
  40. :else(delete-first-submatrix (rest lst) (cons (drop 3 (first lst)) acc) (inc n)))))
  41.  
  42. (defn without-zeros
  43. ([lst] (without-zeros lst ()))
  44. ([lst acc]
  45. (cond
  46. (empty? lst) (reverse acc)
  47. (empty? (first lst)) (without-zeros (rest lst) acc)
  48. :else(without-zeros (rest lst) (cons (first lst) acc)))))
  49.  
  50.  
  51. (defn submatrices-to-rows
  52. ([lst] (submatrices-to-rows lst ()))
  53. ([lst acc]
  54. (if
  55. (empty? lst) (reverse acc)
  56. (submatrices-to-rows (without-zeros (delete-first-submatrix lst)) (cons (get-first-submatrix lst) acc)))))
  57.  
  58.  
  59. (defn delete-from-rows-and-columns [lst] (delete-all-from-all-columns (delete-all-from-all-rows lst)))
  60.  
  61. (defn complete-delete [lst]
  62. (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