Upgrade to PRO for Only $50/Yearβ€”Limited-Time Offer! πŸ”₯

Doku - David Grayson

Avatar for Las Vegas Ruby Group Las Vegas Ruby Group
April 18, 2012
84

Doku - DavidΒ Grayson

Avatar for Las Vegas Ruby Group

Las Vegas Ruby Group

April 18, 2012
Tweet

Transcript

  1. About Doku ξ€Š Written purely in Ruby ξ€Š Short methods

    ξ€Š Well-defined objects and classes ξ€Š Complete documentation ξ€Š Fully functional classes ξ€Š Test-driven development ξ€Š Lots of time refactoring ξ€Š Plus, it can generate SVGs!
  2. Puzzle class is general ξ€Š Every subclass has these attributes:

    ξ€Š glyphs (e.g. 1,2,3,4,5,6,7,8,9) ξ€Š squares (every spot on the puzzle) ξ€Š groups (sets of squares) ξ€Š Every instance has: ξ€Š glyph_state: Hash associating squares to glyphs. ξ€Š Squares and glyphs can be any ruby object.
  3. Solving a Puzzle ξ€Š Solution is a set of glyph

    assignments ξ€Š e.g. write 6 in the square at (3,4) ξ€Š Solution achieves certain goals exactly once: I. For each square, assign ONE glyph to it. II.Assign every glyph to every group ONCE. ξ€Š Each glyph assignment achieve a subset of these goals.
  4. Exact cover problem ξ€Š Given: universe set ξ€Š Given: several

    of subsets of the universe ξ€Š Problem: Choose some of those subsets so that every element in the universe set appears exactly once.
  5. Exact cover example Universe: [A,B,C,D,E,F,G] Subsets: [ C, E,F ]

    [A, D, G] [ B,C, F ] [A, D ] [ B, G] [ D,E, G] Solution: [ B, G] [A, D ] [ C, E,F ]
  6. Algorithm X [ C, E,F ] [A, D, G] [

    B,C, F ] [A, D ] [ B, G] [ D,E, G] 0 0 1 0 1 1 0 1 0 0 1 0 0 1 0 1 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 1 1 0 1 Subsets Matrix
  7. Algorithm X Demo A B C D E F G

    p 0 0 1 0 1 1 0 q 1 0 0 1 0 0 1 r 0 1 1 0 0 1 0 s 1 0 0 1 0 0 0 t 0 1 0 0 0 0 1 u 0 0 0 1 1 0 1 B C E F p 0 1 1 1 r 1 1 0 1 E
  8. Algorithm X Demo A B C D E F G

    p 0 0 1 0 1 1 0 q 1 0 0 1 0 0 1 r 0 1 1 0 0 1 0 s 1 0 0 1 0 0 0 t 0 1 0 0 0 0 1 u 0 0 0 1 1 0 1 B C E F p 0 1 1 1 r 1 1 0 1
  9. Algorithm X Demo B C E F G p 0

    1 1 1 0 r 1 1 0 1 0 t 1 0 0 0 1 Empty matrix = success! A B C D E F G p 0 0 1 0 1 1 0 q 1 0 0 1 0 0 1 r 0 1 1 0 0 1 0 s 1 0 0 1 0 0 0 t 0 1 0 0 0 0 1 u 0 0 0 1 1 0 1 C E F p 1 1 1
  10. Efficient Algorithm X ξ€Š Data type for a large matrix

    ξ€Š Finding 1s in a given column or row quickly ξ€Š Removing columns and rows quickly ξ€Š Quick reinserting
  11. Also easy reinsertion! class Node attr_accessor :left, :right def remove

    left.right = right right.left = left end def reinsert left.right = right.left = self end end No arguments For reinsert!
  12. A B C D E F G 2D doubly-linked list

    Column headers Root node Ruby's default #inspect can NOT handle this!