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


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


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

    導(dǎo)航

    統(tǒng)計(jì)

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊(cè)

    搜索

    積分與排名

    最新評(píng)論

    閱讀排行榜

    評(píng)論排行榜

    主站蜘蛛池模板: 亚洲色偷偷综合亚洲AV伊人蜜桃 | 亚洲短视频在线观看| 亚洲一区二区三区免费视频| 色天使亚洲综合在线观看| 免费人成视网站在线观看不卡| 叮咚影视在线观看免费完整版| 亚洲精品第一国产综合野| 国产精品冒白浆免费视频| 美女在线视频观看影院免费天天看 | 深夜A级毛片视频免费| 久久久久亚洲精品美女| 成年女人免费v片| 中文字幕无码免费久久| 亚洲日韩国产欧美一区二区三区| 亚洲日韩精品A∨片无码| 成人爽A毛片免费看| 免费视频精品一区二区三区| 亚洲AV无码一区二区一二区| 亚洲高清在线观看| 亚洲?V无码成人精品区日韩| 免费视频爱爱太爽了| 免费精品久久天干天干| 国产精品亚洲色图| 亚洲精品在线免费观看视频| 亚洲美女在线国产| 好男人视频社区精品免费| 人人揉揉香蕉大免费不卡| 美女黄色毛片免费看| 日韩亚洲国产综合高清| 亚洲综合在线观看视频| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 亚洲性线免费观看视频成熟| 亚洲成av人在线视| 亚洲人成无码久久电影网站| 女人被弄到高潮的免费视频| 久久久久免费看成人影片| 国产日韩精品无码区免费专区国产| 亚洲色一区二区三区四区| 亚洲av无码国产综合专区| 亚洲精选在线观看| 亚洲成AV人片在|