<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) 評論(0)  編輯  收藏 所屬分類: Clojure


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


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

    導(dǎo)航

    統(tǒng)計

    常用鏈接

    留言簿(12)

    隨筆分類(54)

    隨筆檔案(59)

    文章分類(2)

    文章檔案(1)

    相冊

    搜索

    積分與排名

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 亚洲va国产va天堂va久久| 国产精品免费_区二区三区观看| 精品国产人成亚洲区| 天天综合亚洲色在线精品| 四虎成人免费观看在线网址| 亚洲另类视频在线观看| 国产免费女女脚奴视频网| 亚洲国产日韩在线成人蜜芽| 1000部拍拍拍18勿入免费视频软件 | 亚洲中文字幕一二三四区| 久久WWW免费人成人片| 亚洲乱码在线卡一卡二卡新区| 久久精品免费全国观看国产| 亚洲一线产品二线产品| 国产成人无码a区在线观看视频免费 | 亚洲视频在线观看免费视频| 免费国产成人18在线观看| 亚洲乱码国产乱码精品精| 少妇无码一区二区三区免费| 亚洲伊人久久大香线蕉苏妲己| 99精品视频在线视频免费观看| 亚洲最大的视频网站| 成年女人视频网站免费m| 国产午夜亚洲精品不卡电影| 国产亚洲精午夜久久久久久| 免费网站看av片| 亚洲首页国产精品丝袜| 国产免费av一区二区三区| 一个人看的hd免费视频| 午夜影视日本亚洲欧洲精品一区| 性短视频在线观看免费不卡流畅 | 高h视频在线免费观看| 久久久久亚洲精品无码网址 | 手机永久免费的AV在线电影网| 亚洲中文字幕无码一久久区| 91短视频在线免费观看| 亚洲另类无码一区二区三区| 国产精品亚洲综合专区片高清久久久 | 亚洲国产成人精品激情| 可以免费观看一级毛片黄a| 两个人看的www高清免费观看|