theclapp

Search theclapp.blog-city.com

 

Chapter 3, ex 7

posted Wednesday, 8-Jan-2003
20:16 -- Starting 3.7, Java version
20:24 -- done
---
// ch03_ex07.java

class ch03_ex07 {
public static void main( String[] args ) {
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:24 -- Starting 3.7, Lisp version
20:28 -- done

---
;;;; Chapter 3, ex 7
(defun ch03-ex07 ()
(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