Here is a simple scheme program to generate prime numbers in scheme.
;Written by Fakrudeen Ali Ahmed
;Date 9 January 2007
;primes above a bound
(define (primes-above n count)
(define (loop k count)
(if (= count 0) '()
(if (prime? k) (begin (display k) (newline) (loop (+ k 1) (- count 1))) (loop (+ k 1) count))))
(loop n count)
)
;primes less than n
(define (primes-less-than n)
(define (loop k)
(if (= k n) '()
(begin (if (prime? k) (begin (display k) (newline))) (loop (+ k 1)))))
(loop 2)
)
;whether n is prime?
(define (prime? n)
(cond
((or (= n 2) (= n 3)) true)
((or(= 0 (remainder n 2)) (= 0 (remainder n 3))) false)
(else (let ((limit (expt n (/ 1 2))))
(define (loop k)
(let* ( (j (- (* 6 k) 1) ) (l (+ j 2)) )
(cond
((< limit j) true)
((or(= 0 (remainder n j)) (= 0 (remainder n l))) false)
(else (loop (+ 1 k))))))
(loop 1)))))
Friday, December 29, 2006
Godel's theorem!
Godel proved there are true statements, whichever are unprovable!!
Isn't interesting?
That forever dashes the hope we can prove all mathematical facts.
http://en.wikipedia.org/wiki/Kurt_G%C3%B6del
It also has interesting consequences for what we can calculate algorithmically.
Isn't interesting?
That forever dashes the hope we can prove all mathematical facts.
http://en.wikipedia.org/wiki/Kurt_G%C3%B6del
It also has interesting consequences for what we can calculate algorithmically.
IBM developerworks!
If you are developer this site is a "must" see.
developerWorks : IBM's resource for developers [ http://www.ibm.com/developerworks/ ]
They also have a weekly newsletter.
developerWorks : IBM's resource for developers [ http://www.ibm.com/developerworks/ ]
They also have a weekly newsletter.
Wednesday, December 27, 2006
Wikipedia!
I love these folks!
http://wikipedia.org
This is the the first place I search to know about something!
http://wikipedia.org
This is the the first place I search to know about something!
Tuesday, December 26, 2006
style preview in word
New Microsoft word has a nice live preview of style. Select a block of text and just move the cursor over style boxes on top and see!
Monday, December 25, 2006
Perumazhakkalam (പെരുമഴക്കാലം)
If you like watching good movies in Malayalam, Perumazhakkalam (പെരുമഴക്കാലം) is surely one. Different story. Watch it yourself!
Sunday, December 24, 2006
Blank slate!
A very good book about biology/human nature.
It argues that root of most of our behaviours are due to our genes.
Makes you realistic [as opposed to optimist or romantic]!
It argues that root of most of our behaviours are due to our genes.
Makes you realistic [as opposed to optimist or romantic]!
Saturday, December 23, 2006
prefix vs postfix -- operator
I realized if I have a choice I should use prefix -- instead of postfix.
int findLength(const Node* list) {
int count = 0;
for(const Node* current = list; count++ < current =" current-">getNext()) {
}
return count--; //<-------------- bug
}
This is a bug [which compiler doesn't warn either] - what is the point of incrementing a local variable after it is returned!?
--count here works fine and is correct.
int findLength(const Node* list) {
int count = 0;
for(const Node* current = list; count++ < current =" current-">getNext()) {
}
return count--; //<-------------- bug
}
This is a bug [which compiler doesn't warn either] - what is the point of incrementing a local variable after it is returned!?
--count here works fine and is correct.
Friday, December 22, 2006
C runtime source!
C runtime source is available with visual studio installation. It is very useful say for checking how malloc is implemented.
It also has nice and tested algos. for strncpy etc.
It also has nice and tested algos. for strncpy etc.
Thursday, December 21, 2006
Clippool
It is a cool utility to copy from one computer and paste in another computer: http://support.microsoft.com/kb/318760
Tuesday, December 19, 2006
Google earth!
I love it - particularly look at its driving directions!
I just don't want to close this!
[Make sure you have hardware acceleration set to full for display to avoid directx problems]
I just don't want to close this!
[Make sure you have hardware acceleration set to full for display to avoid directx problems]
Monday, December 18, 2006
string comparisons in .NET
This article is very good for understanding ordinal vs invarint vs current cultures in .NET
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/StringsinNET20.asp
Saturday, December 16, 2006
Startup programs
Here is an interesting link I found about [disabling!] startup programs:
http://www.pacs-portal.co.uk/startup_index.htm
http://www.pacs-portal.co.uk/startup_index.htm
Sunday, December 3, 2006
edge
If you like to reflect [in the metaphysical sense] a bit, this is a nice site to do that:
http://www.edge.org/
Particularly have a look at world question center. It has answers for a "big" question from eminent people at the start of every year.
http://www.edge.org/
Particularly have a look at world question center. It has answers for a "big" question from eminent people at the start of every year.
Saturday, December 2, 2006
Thinking in Java!
One of the best books for learning Java is this: Thinking in Java.
What's more, its free from Bruce eckel's site.
http://www.mindview.net/Books/TIJ/
What's more, its free from Bruce eckel's site.
http://www.mindview.net/Books/TIJ/
Subscribe to:
Posts (Atom)