Lisp(y) A* search implementation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AceKnocks
    New Member
    • Jan 2008
    • 14

    Lisp(y) A* search implementation

    Thanks Jos for that encouragement. :)

    Let's see if you really allowed your Lisp(y) knowledge to fade away in midst of those C's and Java's.. Here goes,

    If we have following array

    Code:
    (setf *possible-die-combinations* (make-array '(20 6)
    :initial-contents
    '((1 3 2 4 5 6)
    (1 2 4 5 3 6)
    (1 4 5 3 2 6)
    (1 5 3 2 4 6)
    (2 3 6 4 1 5)
    (2 6 4 1 3 5)
    (2 4 1 3 6 5)
    (2 1 3 6 4 5)
    (3 5 6 2 1 4)
    (3 6 2 1 5 4)
    (3 2 1 5 6 4)
    (3 1 5 6 2 4)
    (4 6 5 1 2 3)
    (4 5 1 2 6 3)
    (4 1 2 6 5 3)
    (4 2 6 5 1 3)
    (5 3 1 4 6 2)
    (5 1 4 6 3 2)
    (5 4 6 3 1 2)
    (5 6 3 1 4 2))))
    If you would notice, in every row the set of first and second elements together is unique. For e.g. the first row has (1, 3) and the second row has (1, 2).
    Now I want to retrieve a specific row based on this given combination of first and second element. How do I do it?
    Last edited by acoder; Apr 8 '08, 11:05 AM. Reason: Added code tags
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    hrmph, I only noticed this thread today ...

    If those first two numbers are both in a very narrow interval, e.g. [1,6] you can
    synthesize a numerical index out of them, e.g 6*(i-1)+j-1 and use that as an index
    in another array that stores the original arrays. A nil value would indicate no
    array. For 20 arrays out of a possible 36 that isn't too bad.

    Otherwise just a Java HashMap comes to mind where the first two numbers
    form the key and the array itself forms the value in the Map.

    kind regards,

    Jos

    Comment

    Working...