锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久福利毛片,亚洲精品成人久久久,欧美午夜精品久久久久久蜜http://www.aygfsteel.com/chaocai/category/45371.htmlzh-cnSun, 05 Aug 2012 21:12:00 GMTSun, 05 Aug 2012 21:12:00 GMT60The Clojure Program To solve N Queens Problemhttp://www.aygfsteel.com/chaocai/archive/2012/08/05/384844.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Sun, 05 Aug 2012 15:26:00 GMThttp://www.aygfsteel.com/chaocai/archive/2012/08/05/384844.htmlhttp://www.aygfsteel.com/chaocai/comments/384844.htmlhttp://www.aygfsteel.com/chaocai/archive/2012/08/05/384844.html#Feedback0http://www.aygfsteel.com/chaocai/comments/commentRss/384844.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/384844.htmlThe following program is about solving N-Queens problem (http://en.wikipedia.org/wiki/Eight_queens_puzzle) by Clojure. If you have the better solution in Clojure or Haskell, welcome to provide your solution.
(ns queens)
(defn conflictInRow? [queens newqueen]
  (some #(= newqueen %) queens)
)
(defn conflictInDia? [queens newqueen]
  (let [dia (count queens) 
        n1 (fn [queen] (Math/abs (- dia (.indexOf queens queen))))
        n2 (fn [queen] (Math/abs (- newqueen queen)))]
    (some #(= (n1 %) (n2 %)) queens)
   )
 )
(defn conflict? [queens newqueen]
  (or (conflictInRow? queens newqueen) (conflictInDia? queens newqueen))
 )
(def cnt (atom 0))
(defn put-queens [queens newqueen boardSize ]
  (if (= (count queens) boardSize)  
    (do
      (println queens)
      (reset! cnt (inc @cnt))
    )
    (do 
      ;(println queens)
      (if (> newqueen boardSize)
     
           (if (and (= (peek queens) boardSize) (= (count queens) 1))
               (throw (Exception. (str "That's all " @cnt)))
               (recur (pop queens) (inc (peek queens)) boardSize )
           )
     
        (if (conflict? queens newqueen)
            
             (recur queens (inc newqueen) boardSize )
             
          (do
             (put-queens (conj queens newqueen) 1 boardSize )
             (recur queens (inc newqueen) boardSize )
           )
        )
       )
      )
    )
    
)
(defn queens [boardSize] 
    (put-queens [] 1 boardSize)
 )


Chao Cai (钄¤秴錛?/div>

Sr. Software Dev Engineer 
Amazon.com

 


]]>TDD Tipshttp://www.aygfsteel.com/chaocai/archive/2011/01/09/342623.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Sun, 09 Jan 2011 08:55:00 GMThttp://www.aygfsteel.com/chaocai/archive/2011/01/09/342623.htmlhttp://www.aygfsteel.com/chaocai/comments/342623.htmlhttp://www.aygfsteel.com/chaocai/archive/2011/01/09/342623.html#Feedback1http://www.aygfsteel.com/chaocai/comments/commentRss/342623.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/342623.htmlHow to design the testable software? You may always find some best practices about designing for scalable, extensible or maintainable. To be testable, the best way should be TDD. Followings are some tips from my real practices on TDD.

1 TDD is design process; it let you design for testing, naturally

Write the test firstly, it does not only help you find the bugs; but the most important point is to let you design for test naturally.

Also you should keep in mind, tests not only help you find bugs, but also protect your codes; when some changes impact on your existing codes, the tests will be broken.

 

2 Keep the implementation simple

Keep your implementation simple, just let the test pass. The complex implementation may introduce the logics or codes not covered by the tests, even leads some codes not testable.

 

3 TDD in each scope.

You may get to know the concept ATDD (acceptance test driven development). TDD could be used in every phase of the development and by the different granularity.

To ATDD, you could consider on using some existing framework such as FIT, these frameworks will be bridge between business logic and implementation logic.

Recently, the concept BDD (behavior driven development) is introduced to the ATDD process, so the BDD frameworks such as JBehave is also the good choice.

 


Different TDD process could be nested and should be nested don’t let your step too large.

 

4 keep each step small enough

Always keep each step small to avoid introducing the untestable codes or logics and pass each test quickly.

 

 

6 Always refactor

This step is always overlooked in TDD process; however it is the very important step. Also, never forget refactor should involve all your tests.

 

Why can't write test firstly?

 1.not think how to meature the codes

2. The current step maybe too large, should separate into small ones

3. The codes with ugly dependencies


 http://blog.csdn.net/chaocai2004/archive/2011/01/09/6125479.aspx


Chao Cai (钄¤秴)

Sr. SDE

Amazon.com

 



]]>
綆楁硶鐨勬椂闂村鏉傚害http://www.aygfsteel.com/chaocai/archive/2010/06/18/323815.html瓚呰秺宸呭嘲瓚呰秺宸呭嘲Fri, 18 Jun 2010 07:26:00 GMThttp://www.aygfsteel.com/chaocai/archive/2010/06/18/323815.htmlhttp://www.aygfsteel.com/chaocai/comments/323815.htmlhttp://www.aygfsteel.com/chaocai/archive/2010/06/18/323815.html#Feedback1http://www.aygfsteel.com/chaocai/comments/commentRss/323815.htmlhttp://www.aygfsteel.com/chaocai/services/trackbacks/323815.html鐩鎬俊澶у瀵逛簬綆楁硶鐨勬椂闂村鏉傚害O閮戒笉浼氶檶鐢燂紝涓嶈繃浣犵煡閬撲竴涓畻娉曠殑鏃墮棿澶嶆潅搴︽槸濡備綍璁$畻鍑烘潵鐨勫悧錛?/span>

浠ュ墠鍦ㄥ涔犵畻娉曞拰鏁版嵁緇撴瀯鐨勬椂鍊欙紝瀵逛簬姣忕綆楁硶鐨勫鏉傚害閮芥槸姝昏鐨勫茍娌℃湁鐪熸鐨勫幓鐮旂┒浠栦滑鏄浣曡綆楀嚭鏉ワ紝鏈榪戠獊鐒跺綆楁硶浜х敓浜嗗叴瓚o紝榪嬌鑷繁鐮旂┒浜嗕竴涓嬬畻娉曞鏉傚害鐨勮綆楁柟娉曘?/span>

姒傚康

澶?/span>O琛ㄧず娉曡〃紺烘椂闂村鏉傛э紝娉ㄦ剰瀹冩槸鏌愪竴涓畻娉曠殑鏃墮棿澶嶆潅鎬с傚ぇO琛ㄧず鍙槸璇存湁涓婄晫錛岀敱瀹氫箟濡傛灉f(n)=O(n)錛岄偅鏄劇劧鎴愮珛f(n)=O(n^2)錛屽畠緇欎綘涓涓笂鐣岋紝浣嗗茍涓嶆槸涓婄‘鐣岋紝浣嗕漢浠湪琛ㄧず鐨勬椂鍊欎竴鑸兘涔犳儻琛ㄧず鍓嶈?/span>銆?/span>

鍙﹀闄や簡榪欎釜瀹樻柟姒傚康錛屼釜浜鴻涓哄ぇO琛ㄧず鐨勬槸闂瑙勬ān鍜岀畻娉曚腑璇彞鎵ц嬈℃暟鐨勫叧緋匯?/span>

浠ヤ簩鍒嗘煡鎵句負渚嬶紝鎴戜滑姹傝В瀹冪殑鏃墮棿澶嶆潅搴?/span>

1 璁捐妯′負n涓厓绱犳椂錛岃鎵цT(n)嬈?/span>

T(n)=T(n/2)+1

T(n)=[T(n/4)+1]+1

T(n)=T(n/2^m)+m

褰?/span>n=2^m

T(n)=T(1)+log2n

T(1)=1

鎵浠ュ叾綆楁硶澶嶆潅搴︿負O錛坙og2n錛?/span>



]]>
主站蜘蛛池模板: 湖北省| 海盐县| 浑源县| 韶关市| 镇坪县| 独山县| 浏阳市| 甘泉县| 鄱阳县| 洱源县| 渭南市| 徐水县| 定陶县| 清新县| 永宁县| 乌鲁木齐县| 连江县| 宝应县| 印江| 芷江| 昂仁县| 革吉县| 广水市| 宁陵县| 二连浩特市| 靖江市| 秀山| 原阳县| 台东县| 汝州市| 英超| 洛宁县| 镇宁| 友谊县| 衡东县| 楚雄市| 昌都县| 印江| 马公市| 托里县| 乌什县|