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

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲AV成人无码久久WWW| 亚洲变态另类一区二区三区| 91精品国产免费久久国语蜜臀| 亚洲一级二级三级不卡| 亚洲av午夜成人片精品电影| 中文字幕无码免费久久9一区9| 亚洲成AV人影片在线观看| 亚洲综合小说久久另类区| 德国女人一级毛片免费| 国内成人精品亚洲日本语音| 久久亚洲国产精品123区| 国产大片91精品免费观看男同| 台湾一级毛片永久免费| 极品美女一级毛片免费| 亚洲精品无码中文久久字幕| 久久久久久A亚洲欧洲AV冫| 免费a级毛片永久免费| 日韩免费观看的一级毛片| 伊人免费在线观看高清版| 国产精品美女免费视频观看| 亚洲熟妇色自偷自拍另类| 亚洲综合视频在线| 亚洲国产天堂在线观看| 国产jizzjizz免费视频| 日韩免费一级毛片| 日本免费无遮挡吸乳视频电影| 好男人看视频免费2019中文| 成年女人免费视频播放77777| 两个人看的www高清免费视频| 永久免费无码网站在线观看个| 特级毛片A级毛片免费播放| 亚洲制服在线观看| 亚洲一区二区影视| 亚洲国产成人高清在线观看| 亚洲精品国产美女久久久| 久久亚洲国产成人亚| 亚洲成a人片在线观看久| 亚洲欧洲精品成人久久奇米网| 亚洲无码高清在线观看| 亚洲人成图片小说网站| 久久久久亚洲Av片无码v|