Skip to content

Instantly share code, notes, and snippets.

@zerokarmaleft
Created October 5, 2012 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zerokarmaleft/3837554 to your computer and use it in GitHub Desktop.
Save zerokarmaleft/3837554 to your computer and use it in GitHub Desktop.
reducing into a 2d matrix
;; matrix M
;; 0 1 2 3
;; ==========
;; 0: 1 0 0 1
;; 1: 0 0 1 0
;; 2: 0 1 0 1
;; 3: 1 0 1 1
;; 4: 0 0 1 0
;; index correspond to checking rows of M
(def sigs [[1 1] [2 4] [3 2] [4 0] [0 3]])
;; check row for bits flipped to 1
;; corresponding columns in sig-M have the minimum of the new sig values and existing sig values
;; row 0, columns 0 and 3 are flipped
;; since there are no entries, the sig vector [1 1] is assoc'd into the corresponding columns
;; sig-M [[1 1] nil nil [1 1]]
;; row 1, column 2 is flipped
;; since there are no entries, the sig vector [2 4] is assoc'd, the other don't change
;; sig-M [[1 1] nil [2 4] [1 1]]
;; row 2, column 1 and 3 are flipped
;; column 3 doesn't change
;; sig-M [[1 1] [3 2] [2 4] [1 1]]
;; row 3, column 0, 1, and 3 are flipped
;; assoc the minimum of the existing value and the new sig vector values
;; sig-M [[1 0] [3 2] [2 0] [1 0]]
...
;; expected result
(def sig-M [[1 0] [3 2] [0 0] [1 0]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment