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


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


    網(wǎng)站導(dǎo)航:
     

    導(dǎo)航

    統(tǒng)計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 久久久久亚洲AV无码麻豆| 亚洲国产高清精品线久久| 亚洲AV午夜福利精品一区二区| 一级毛片大全免费播放| 波多野结衣一区二区免费视频| 亚洲国产美女精品久久久| 亚洲一级片在线观看| 天天影视色香欲综合免费| 亚洲AV综合色区无码二区偷拍| 久久久久久国产a免费观看黄色大片| 亚洲成电影在线观看青青| 欧美在线看片A免费观看| 亚洲国产成人精品无码区二本| 在线观看免费国产视频| sss在线观看免费高清| 久久精品国产精品亚洲人人| 91成人免费观看在线观看| 久久久久久久亚洲Av无码| 国产成人精品免费视频大全麻豆 | 免费无码一区二区| 久久精品国产亚洲7777| 国产无遮挡无码视频免费软件| 18gay台湾男同亚洲男同| 特级做A爰片毛片免费69| 国产成人综合亚洲绿色| 国产V亚洲V天堂A无码| 亚洲免费视频网址| 九九精品国产亚洲AV日韩| 亚洲精品无码久久久影院相关影片| 在线观看免费av网站| 亚洲av永久无码精品秋霞电影秋 | 在线观看亚洲AV日韩AV| 亚洲日韩精品无码专区网站 | 午夜免费福利影院| 国产视频精品免费视频| 中文字幕亚洲精品资源网| 全黄a免费一级毛片人人爱| 国产精品网站在线观看免费传媒 | 老司机午夜精品视频在线观看免费| 亚洲成av人影院| 日韩人妻无码免费视频一区二区三区 |