锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲视频精选,91精品国产综合久久香蕉,国产精品一区不卡http://www.aygfsteel.com/chaocai/category/52793.htmlzh-cnMon, 26 Nov 2012 07:17:44 GMTMon, 26 Nov 2012 07:17:44 GMT60The Clojure Program To solve N Queens Problem (Without back tracing)http://www.aygfsteel.com/chaocai/archive/2012/11/26/Clojure.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Mon, 26 Nov 2012 04:21:00 GMThttp://www.aygfsteel.com/chaocai/archive/2012/11/26/Clojure.htmlhttp://www.aygfsteel.com/chaocai/comments/391968.htmlhttp://www.aygfsteel.com/chaocai/archive/2012/11/26/Clojure.html#Feedback0http://www.aygfsteel.com/chaocai/comments/commentRss/391968.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/391968.htmlThe 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 (钄¤秴錛?br />Sr. SDE
Amazon


 

]]>
Clojure XPathhttp://www.aygfsteel.com/chaocai/archive/2012/10/15/ClojureXPath.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Mon, 15 Oct 2012 02:15:00 GMThttp://www.aygfsteel.com/chaocai/archive/2012/10/15/ClojureXPath.htmlhttp://www.aygfsteel.com/chaocai/comments/389555.htmlhttp://www.aygfsteel.com/chaocai/archive/2012/10/15/ClojureXPath.html#Feedback0http://www.aygfsteel.com/chaocai/comments/commentRss/389555.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/389555.html
The functions to support using XPath in Clojure.

Source Code

 1 ;The code was implemented by caichao@amazon.com
 2 ;You could use the code anyway, but should keep the comments
 3 ;Created 2012.10
 4 (ns clojure.ccsoft.xml
 5   (:require [clojure.xml :as xml]))
 6  
 7 (import '(java.io StringReader)
 8         '(java.io ByteArrayInputStream))
 9  
10 (defn xml-structure [xml-txt] 
11    [ (xml/parse (-> xml-txt
12               (.getBytes)
13               (ByteArrayInputStream.)
14      )
15     )]
16 )
17  
18 (defn node [tag xmlStruct]
19  
20   (first (filter #(= (:tag %) tag) (:content xmlStruct)))
21 )
22  
23 (defn node [path xml-txt]
24    (loop [path path 
25           xml-content (xml-structure xml-txt) 
26           ]
27       (let [current-tag (first path) current-elem (first xml-content)]
28         (if (= (:tag current-elem ) current-tag)
29  
30           (if (= (count path) 1)
31             current-elem 
32             (recur  (rest path) (:content current-elem ))
33           )
34           (if (> (count  xml-content) 1)
35            (recur path  (rest xml-content))
36           )
37         )
38      )
39     )
40  )

How to Use

(def cmd-example "<command>
                   <header>
                     
<type>script</type>
                     
<transaction_id>12345</transaction_id>
                   
</header>
                   
<body>
                      println 
3+4;
                   
</body>
                  
</command>")
 
 
(node [:command :header :transaction_id] cmd
-example)




]]>
主站蜘蛛池模板: 长岛县| 宾川县| 科尔| 南和县| 邻水| 马边| 广州市| 舟曲县| 宁海县| 万安县| 宜良县| 陈巴尔虎旗| 永济市| 南昌市| 嘉兴市| 曲周县| 遵化市| 鹿泉市| 福鼎市| 开原市| 乌拉特后旗| 清水河县| 孙吴县| 本溪市| 阜新| 石门县| 山东省| 精河县| 珠海市| 油尖旺区| 四川省| 祁东县| 密云县| 武夷山市| 乌苏市| 左权县| 休宁县| 社旗县| 德昌县| 会泽县| 普兰县|