- 博客(51)
- 资源 (1)
- 收藏
- 关注

原创 用clojure实现《实用Common Lisp编程》中的单元测试框架
(ns simple-test-frame.core)(def ^:dynamic *test-name* nil)(defn report-result [result form] (if result (println "pass ... " *test-name* ":" form) (println "fail ... " *test-name* ":" f
2013-03-01 13:38:30
794
原创 jsoup在jre6和jre7的不同表现
jsoup在jre7下能自动根据Content-Type转成utf-8, jsoup下则不会,需要自己动手转换。因此在jre6下能正常运行的程序,在jre7下不能正常运行了。
2013-08-31 21:17:48
1478
原创 用 clojure实现【白话经典算法系列之十四】腾讯2012年实习生笔试加分题
昨天见 【白话经典算法系列之十四】腾讯2012年实习生笔试加分题, 作为一个clojure爱好者,实现了一个clojure版本的。题目:给定一数组a[N],我们希望构造数组b [N],其中b[j]=a[0]*a[1]…a[N-1] / a[j],在构造过程中,不允许使用除法:要求O(1)空间复杂度和O(n)的时间复杂度;除遍历计数器与a[N] b[N]外,不可使用新
2013-04-02 17:05:35
1102
原创 nrepl emacs ac-nrepl 绝配
用了Ideal的clojure插件以后,发现repl中没办法自动补全,这个问题很麻烦,因为在学习写clojure代码的过程中,很需要repl测试想法,函数等等。有emacs的nrepl之后,一切都变得美妙了。真的喜欢上nrepl了,一切都简单了。
2013-03-14 20:59:38
845
原创 4clojure第65个问题:黑盒测试序列类型
(ns for-clojure.problem65)(defn black-box-testing "黑盒测试:根据序列的特点判断序列的类型,不能使用类型判断等函数" [v] (cond (:a (conj v [:a 1])) :map (< (- (count (conj v 1 1)) (count v)) 2) :set
2013-03-14 20:53:31
850
原创 4clojure第118个问题:自己的map函数
(fn m [f v] (cons (f (first v)) (lazy-seq (if (empty? (rest v)) [] (m f (rest v))))))这里在lazy-seq里面必须做(rest v)是否为空的判断,不
2013-03-13 21:58:47
724
原创 4clojure第54个问题:拆分序列
(ns for-clojure.problem54)(defn partition-a-sequence-1 "拆分序列,把一个序列拆分成每部分x个元素,最后不足x元素的丢弃" [x v] (loop [r [];最终结果 m [];中间结果保存 v v] (if (= (count m) x) (if (empty? v
2013-03-13 20:03:01
1150
原创 4clojure第135个问题:中缀计算器
(ns for-clojure.problem135)(defn infix-calculator "前缀计算机,从左到右执行,不论优先级" [& xs] (loop [r (first xs) xs (rest xs)] (if (empty? xs) r (recur ((first xs) r (second xs)) (nt
2013-03-13 19:31:32
676
原创 4clojure第97个问题:杨辉三角
(ns for-clojure.problem97)(defn pascals-triangle-1 "杨辉三角" [n] (if (= n 1) [1] (loop [m 2 r [1]] (let [next-r (into [] (map #(apply + %) (partition 2 1(concat [0] r [0]))))]
2013-03-13 13:02:04
646
原创 4clojure第59个问题:创建自己的juxt
(ns for-clojure.problem59)(defn juxtaposition [& fns] (fn [& xs] (into [] (map #(apply % xs) fns))))(= [21 6 1] ((juxtaposition + max min) 2 3 5 1 6 4))(= ["HELLO" 5] ((juxtaposition #(
2013-03-13 12:25:54
819
原创 4clojure第58个问题:组合函数
(ns for-clojure.problem58)(defn fn-comp-1 "创建一个函数的组合函数,此函数接受任何个数的函数,从右到左执行函数" [& fns] (fn [& init-paramters] (let [fns (reverse fns) result (apply (first fns) init-paramters)]
2013-03-13 11:57:33
880
原创 4clojure第56个问题从序列中找出不同的项并保持次序
(ns for-clojure.problem56)(defn find-distinct-items "找出序列中不同的元素,并且要保持原来的次序不变" [v] (reduce #(if (some #{%2} %1) %1 (conj %1 %2)) [] v))(find-distinct-items [:a :a :b :b :c :c])这里需要注意的是为什么用so
2013-03-13 10:38:47
650
原创 4clojure第55个问题:实现自己的序列频率统计函数
(ns for-clojure.problem50)(defn my-frequencies-1 "尾递归序列统计频率" [v] (loop [v v r {}] (if (empty? v) r (let [ele (first v) rest-v (rest v)] (if (get r ele)
2013-03-13 10:11:44
695
原创 4clojure第50个问题根据类型拆分序列
;Split by Type ;Difficulty: Medium;Topics: seqs;Write a function which takes a sequence consisting of items with different types and splits them up into a set of homogeneous sub-sequences. The in
2013-03-13 00:04:44
1165
原创 4clojure第43个问题逆向交错(Reverse Interleave)
Reverse Interleave Difficulty:MediumTopics:seqsWrite a function which reverses the interleave process into x number of subsequences.(= (__ [1 2 3 4
2013-03-12 21:04:08
1056
原创 compojure ring 笔记
compojure.handler/site 要放在middleware的最外层 不然使用session验证时会出现 404错误(session middleware需要site导入)。compojure.handler/site包含了一般网站所需要的中间件site(site routes & [opts])Create a handler suitable for
2013-03-07 08:07:56
1535
原创 用clojure实现《实用Common Lisp编程》中的简单数据库:CD数据库
(ns simple-cd-database.core)(defn make-cd [title artist rating ripped] {:title title :artist artist :rating rating :ripped ripped})(def db (atom []))(defn add-record [cd] (swap! db conj cd))
2013-02-27 17:38:30
1085
原创 编写像Ruby的代码
一, Ruby编程风格的核心思想:1, The first is that code should be crystal clear—good code tells the reader exactly whatit is trying to do. Great code shouts its intent.十分清楚 :好的代码准备无误地告诉读者它要做什么。伟大的代码的叫喊出它的意图。
2012-12-27 12:52:27
1346
原创 Io语言updateSlot、setSlot和newSlot的区别
newSlot(slotName, aValue)Creates a getter and setter for the slot with the name slotName and sets its default value to aValue. Returns self. For example, newSlot("foo", 1) would create slot na
2012-10-31 15:22:59
1013
原创 用clojure解决euler problem 12
问题描述:The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be:1, 3, 6, 10,
2012-07-13 21:00:01
580
原创 用clojure解决 euler problem 11
问题描述:In the 2020 grid below, four numbers along a diagonal line have been marked in red.08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 0849 49 99 40 17 81 18 57 60 87 17 40 98 43 6
2012-07-12 10:16:18
671
原创 用clojure解决euler problem 10
问题描述:The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.Find the sum of all the primes below two million.解决方案:(ns euler-problem-10.core (:use [clojure.contrib.math]))(defn prime? [
2012-07-09 21:01:00
549
原创 用clojure解决euler problem 9
问题描述:A Pythagorean triplet is a set of three natural numbers, a b c, for which,a2 + b2 = c2For example, 32 + 42 = 9 + 16 = 25 = 52.There exists exactly one Pythagorean triplet for whic
2012-07-08 22:25:31
563
原创 用clojure解决euler problem 8
问题描述:Find the greatest product of five consecutive digits in the 1000-digit number.73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156
2012-07-08 21:06:08
481
原创 用clojure解决euler problem 7
问题描述:By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.What is the 10 001st prime number?解决方案:(ns euler-problem-7.core (:use [clojure.cont
2012-07-08 20:39:47
436
原创 用clojure解决 euler problem 6
问题描述:The sum of the squares of the first ten natural numbers is,12 + 22 + ... + 102 = 385The square of the sum of the first ten natural numbers is,(1 + 2 + ... + 10)2 = 552 = 3025Hence
2012-07-08 13:37:15
478
原创 用clojure解决euler problem 5
问题描述:2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.What is the smallest positive number that is evenly divisible by all of the numbe
2012-07-08 10:43:12
504
原创 用clojure解决 euler problem 4
问题描述:A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 99.Find the largest palindrome made from the product of two
2012-07-07 21:12:39
616
原创 用clojure解决euler problem 3
问题描述:The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number 600851475143 ?(ns euler-problem-3.core)(defn largest-prime-factor [number] (loop [
2012-07-06 20:47:25
496
原创 用clojure解决 euler problem 2
问题描述: Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...By con
2012-07-06 12:47:45
497
原创 用clojure解决 euler problem 1
问题描述:If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.Find the sum of all the multiples of 3 or 5 below 1000.解决方案1
2012-07-05 22:10:43
1242
原创 java动态代理机制原理
Proxy的public static Object newProxyInstance(ClassLoader loader,Class[] interfaces,InvocationHandler h),首先通过getProxyClass 创建一个新的Class 对象,//(Class cl = getProxyClass(loader, interfaces);)getProxyCla
2009-10-13 11:37:00
5133
原创 并发的多面性
并发解决的问题:速度和设计可管理性。 更快的执行 : 并发用于多处理器系统中可以吞吐量,但是并发通常却用来提高单处理器上的程序性能。如果但处理器没有阻塞,那么多线程需要线程上下文的转换,程序性能反而会更差,因此之所以在但处理器中需要多线程,是因为程序控制范围之外的阻塞引起的,如果没有任务阻塞,那么在但处理器上使用并发就没有任何意义。 单处理
2009-08-27 17:34:00
905
原创 c语言中-x的实现原理
c语言中,-x实现是用取反+1实现,因此x>0||-x#includeint main(){ int x=0x80000000; printf("x=%d/n",x); if(x>0||-x>=0) printf("x>0||-x>=0"); else printf("x<0&&-x<0"); return 0;} 运行结果为:x
2009-07-25 12:21:00
2098
原创 算法导论思考题:6-3Young 矩阵
三.Young 氏矩阵的相关算法.题:一个 m*n 的 Young 氏矩阵(Young tableau) 是一个 m*n 的矩阵,其中每一行的数据都从左到右排序,第一列的数据都从上到下排序.Young 氏矩阵中可能会有一些 ∞ 数据项,表示不存在的元素.所以,Young 氏矩阵可以用来存放 ra).画一个包含{9,16,3,2,4,8,5,14,12} 的4*4 的Young 氏矩阵.
2008-10-30 21:41:00
875
原创 算法导论习题2.3-7
题目:请给出一个时间复杂度为nlogn的算法,使之能够在给定一个由n个整数的构成的整合S和另一个整数x时,判断出S中是否存在有两个其和等于x的元素。解答:首先对S进行排序,使用合并算法进行排序,排序算法的时间复杂度为nlogn。然后对排序的S从左到右(即从大到小)进行算法,首先锁定一个数i,这个数小于x的一半,然后从这个数的右边开始查找x-i,使用2分法查找,算法的时间复杂度小于nlo
2008-10-25 15:36:00
1905
原创 在nlgn时间内实现逆序对数的计算
数组中逆序对的数量是同运行插入排序产生的移动的数量是相同的,但是选择排序的最差的时间复杂度是n的平方次,但是合并排序最差的是nlogn的时间复杂度。所以应该修改合并排序来计算逆序对数量。在L和R合并的过程中,如果没有移动的话,序列是L+R,所以计算移动的数量就是元素没有移动过R与L与R合并后的位置之间的差值就是移动的数量。 以下代码是实现的算法:#in
2008-10-25 11:05:00
929
原创 类MFC实现无参数函数指针保存有参数函数指针
#include using namespace std;class A;typedef void ( A:: * PFN)(void); class A{public: void FunA(int num) { cout }};union MM{ PFN pfn; void (A:: * pfn_vi)(int);};int main(void){ PFN pfn; A a; pf
2008-08-01 16:49:00
572
spring2 in action
2009-10-11
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人