<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 超越巔峰 閱讀(2849) 評論(0)  編輯  收藏 所屬分類: Clojure


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


    網站導航:
     

    導航

    統計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久99精品免费视频| 亚洲youjizz| 人禽伦免费交视频播放| 国产成人免费ā片在线观看| 亚洲看片无码在线视频| 最近中文字幕无吗高清免费视频| 亚洲国产综合在线| 毛片免费在线观看网址| 亚洲精品国产首次亮相| 免费国产成人高清视频网站| 男男gay做爽爽免费视频| 亚洲国产精品人人做人人爽| 国产精品无码永久免费888 | 老司机69精品成免费视频| 亚洲AV无码乱码国产麻豆穿越 | 18禁美女裸体免费网站| 亚洲日本在线观看网址| 成人av免费电影| 无套内谢孕妇毛片免费看看 | 无码国产精品一区二区免费式影视| 亚洲中文字幕在线无码一区二区| 无限动漫网在线观看免费| 国产精品亚洲一区二区在线观看| 亚洲第一永久AV网站久久精品男人的天堂AV | 亚洲综合久久1区2区3区 | 18禁美女裸体免费网站| 亚洲色欲啪啪久久WWW综合网| 四虎永久免费地址在线观看| 中文字幕在线视频免费观看| 老司机亚洲精品影院无码| 拍拍拍又黄又爽无挡视频免费| 看全免费的一级毛片| 亚洲国产精品久久久久网站| 一本无码人妻在中文字幕免费| 九九久久国产精品免费热6| 亚洲成年人在线观看| 色吊丝永久在线观看最新免费| 国产精品无码免费专区午夜 | 在线观看亚洲精品福利片| 成年人免费的视频| 一级毛片免费播放试看60分钟|