锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久久亚洲精品视频,一区二区久久,尤物yw午夜国产精品视频明星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)




]]>
主站蜘蛛池模板: 六枝特区| 沈丘县| 江达县| 广丰县| 高碑店市| 通河县| 夏河县| 阜阳市| 青川县| 高陵县| 镇坪县| 宁波市| 益阳市| 澄城县| 松潘县| 南溪县| 祁阳县| 宜良县| 南阳市| 福清市| 阿瓦提县| 卓尼县| 海南省| 丘北县| 政和县| 卢龙县| 汽车| 隆回县| 南投县| 措美县| 法库县| 伽师县| 紫金县| 喀什市| 郑州市| 攀枝花市| 巩留县| 青冈县| 白水县| 舟曲县| 新和县|