<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://www.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 超越巔峰 閱讀(2848) | 評論 (0)編輯 收藏

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 免费一级黄色毛片| 最近中文字幕mv免费高清视频7| 又粗又黄又猛又爽大片免费| 亚洲国产成+人+综合| 1区2区3区产品乱码免费| 亚洲精品综合一二三区在线| 99在线观看免费视频| 久久亚洲国产成人精品性色| 99re6热视频精品免费观看| 久久久无码精品亚洲日韩京东传媒| 特级无码毛片免费视频尤物| 亚洲韩国在线一卡二卡| 亚洲精品免费网站| 亚洲私人无码综合久久网| 国产老女人精品免费视频| 日韩在线一区二区三区免费视频| 久久夜色精品国产亚洲av| 妞干网在线免费视频| 亚洲精品久久久久无码AV片软件| 在线观看免费亚洲| 免费国产a理论片| 久久久久久a亚洲欧洲aⅴ| 99精品视频在线观看免费播放| 亚洲成年人电影网站| 在线视频免费国产成人| 又硬又粗又长又爽免费看 | 亚洲国产精品第一区二区三区| 黑人粗长大战亚洲女2021国产精品成人免费视频| 日韩免费三级电影| eeuss影院ss奇兵免费com| 久久久久无码精品亚洲日韩| 免费精品国产自产拍在 | 学生妹亚洲一区二区| 国产大片线上免费看| 国产午夜无码片免费| 亚洲无限乱码一二三四区| 国产色爽免费视频| 一区二区三区观看免费中文视频在线播放 | 少妇无码一区二区三区免费| 久久亚洲精品国产精品婷婷| 四虎永久免费影院在线|