theclapp

Search theclapp.blog-city.com

 

Chapter 3, ex 8

posted Wednesday, 8-Jan-2003
20:33 -- starting 3.8, Java version
20:35 -- done
---
// ch03_ex08.java

class ch03_ex08 {
public static void main( String[] args ) {
while (true) {
int pivot = (int)(Math.random() * 25);
for (int i = 0; i < 25; i++) {
int r = (int)(Math.random() * 25);
if (r < pivot)
System.out.println( r + " < " + pivot );
else if (r > pivot)
System.out.println( r + " > " + pivot );
else
System.out.println( r + " = " + pivot );
}
}
}
}
---

20:35 -- starting 3.8, Lisp version
20:36 -- done

---
;;;; Chapter 3, ex 8
(defun ch03-ex08 ()
(loop
(let ((pivot (random 25)))
(dotimes (i 25)
(let ((r (random 25)))
(cond ((< r pivot) (format t "~a < ~a~%" r pivot))
((> r pivot) (format t "~a > ~a~%" r pivot))
(t (format t "~a = ~a~%" r pivot))))))))
---

links: digg this    del.icio.us    technorati    reddit