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

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲最大在线视频| 亚洲av午夜福利精品一区| 91在线亚洲综合在线| 1000部免费啪啪十八未年禁止观看| 亚洲色成人中文字幕网站| 成年免费a级毛片免费看无码| 亚洲综合精品网站| 一级毛片免费在线| 久久久青草青青国产亚洲免观 | 激情内射亚洲一区二区三区爱妻| 91老湿机福利免费体验| 亚洲成aⅴ人片在线影院八| 性做久久久久久免费观看| 亚洲夂夂婷婷色拍WW47| 免费国产综合视频在线看 | 国产四虎免费精品视频| 亚洲综合小说另类图片动图| 免费看的黄色大片| 国产av无码专区亚洲av毛片搜| 亚洲国产精品自产在线播放| 国内精品免费久久影院| 亚洲福利视频网址| 精品久久免费视频| 亚洲高清免费视频| 亚洲男人的天堂在线播放| 一二三四影视在线看片免费 | 亚洲Av无码精品色午夜| 国产成人精品久久免费动漫| 亚洲国产精品美女久久久久| 亚洲国产综合精品中文字幕| 久久国产精品免费专区| 亚洲乱码在线卡一卡二卡新区| 亚洲 无码 在线 专区| 男人j进入女人j内部免费网站| 亚洲国产综合人成综合网站00| 国内自产拍自a免费毛片| 久久久久免费视频| 亚洲jizzjizz在线播放久| 无码欧精品亚洲日韩一区夜夜嗨| 一区二区三区观看免费中文视频在线播放| 中文字幕在线观看亚洲视频|