<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    J2EE之巔

     

    2012年11月26日

    The Clojure Program To solve N Queens Problem (Without back tracing)

    Not like the previous solution here http://m.tkk7.com/chaocai/archive/2012/08/05/384844.html
    The following solution not using the back tracing way is more concise and readable, but for the searching space becomes huger, the performance is much worser then the previous one.

    (ns SICP.unit3)
    (defn conflictInCol? [s col]
      (some #(= col %) s)
    )

    (defn conflictInDia? [s col]
      (let [dia (count s)
            n1 (fn [c
    ] (Math/abs (- dia (.indexOf s c))))
            n2 (fn [c] (Math/abs (- col c)))]
        (some #(= (n1 %) (n2 %)) s)
      )
    )

    (defn safe? [s col] 
      (not (or (conflictInCol? s col) (conflictInDia? s col)))
    )
      
    (defn next-level-queens [solutions-for-prev-level board-size current-level]
      (let [solutions (atom [])]
        (doseq [s solutions-for-prev-level]
          (doseq [col (range 0 board-size)]
            (if (safe? s col)
              (reset! solutions (cons (conj s col) @solutions))
         
            )
           )
       
        )
       
          (if (< current-level (dec board-size))
            (recur @solutions board-size (inc current-level))
            (count @solutions)
          )
       )
    )

    (defn queens [board-size]
      (next-level-queens  (apply vector (map #(vector %) (range 0 board-size))) board-size 1)
    )

    Chao Cai (蔡超)
    Sr. SDE
    Amazon


     

    posted @ 2012-11-26 12:21 超越巔峰 閱讀(2837) | 評論 (0)編輯 收藏

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲人成免费电影| 黄桃AV无码免费一区二区三区| 久久久精品2019免费观看 | 久久久久亚洲国产AV麻豆| 亚洲成在人线aⅴ免费毛片| 久久精品国产亚洲AV蜜臀色欲 | 久久久久亚洲av无码专区| 97av免费视频| 亚洲综合综合在线| 日韩版码免费福利视频| 国产 亚洲 中文在线 字幕| 好爽…又高潮了毛片免费看| 亚洲av无码专区青青草原| 国产在线观看www鲁啊鲁免费| 黄色一级毛片免费看| 亚洲一区二区三区AV无码| 性无码免费一区二区三区在线| 亚洲精品视频在线| 99久久综合国产精品免费| 亚洲av无码一区二区三区天堂| 国产免费av一区二区三区| 一区免费在线观看| 亚洲专区在线视频| 24小时日本在线www免费的| 黄页网址在线免费观看| 久久精品国产精品亚洲艾| 无码乱肉视频免费大全合集| 亚洲精华国产精华精华液| 久久久久亚洲AV无码专区桃色| 久久久久久AV无码免费网站下载| 久久久亚洲裙底偷窥综合| 日本免费v片一二三区| 国产精品免费一区二区三区| 亚洲精品视频免费看| 国产成人综合久久精品免费 | 亚洲乱码一区av春药高潮| 免费日本黄色网址| 最近免费中文字幕大全免费| 久久亚洲精品无码gv| 亚洲一区二区在线免费观看| 德国女人一级毛片免费|