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

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

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

    J2EE之巔

     

    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 on 2012-11-26 12:21 超越巔峰 閱讀(2848) 評論(0)  編輯  收藏 所屬分類: Clojure


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲色偷偷偷综合网| 亚洲精品午夜无码专区| 在线观看亚洲网站| 亚洲aⅴ无码专区在线观看| 国产精品视频免费观看| 国产伦一区二区三区免费| 国精无码欧精品亚洲一区| 国产免费A∨在线播放| 久久精品亚洲福利| 亚洲婷婷天堂在线综合| 美女内射毛片在线看免费人动物| 亚洲一区二区三区电影| 国产天堂亚洲精品| mm1313亚洲精品无码又大又粗| 婷婷亚洲久悠悠色悠在线播放| 毛片在线全部免费观看| 欧洲美熟女乱又伦免费视频| 亚洲无av在线中文字幕| 叮咚影视在线观看免费完整版| 亚洲成人在线电影| 99久久久精品免费观看国产 | 亚洲丰满熟女一区二区v| 2021国产精品成人免费视频| 亚洲一区二区三区乱码在线欧洲| 中文字幕在线视频免费观看| 日韩精品视频免费观看| 美女扒开尿口给男人爽免费视频| 久久久亚洲精品蜜桃臀| 久久成人免费播放网站| 亚洲国产中文v高清在线观看| 中文字幕在线日亚洲9| 国产免费观看黄AV片| 国产日韩精品无码区免费专区国产 | 亚洲最大在线视频| 国产免费观看黄AV片| 东方aⅴ免费观看久久av| 亚洲AV无码专区在线亚| 国产一级大片免费看| 国产高清不卡免费视频| 亚洲啪AV永久无码精品放毛片| 国产a视频精品免费观看|