View Single Post
Old 17-08-2009, 07:27   #62
Mr_love_monkey
Inactive
 
Mr_love_monkey's Avatar
 
Join Date: Jun 2003
Location: London way
Age: 49
Services: Sarcasm
Posts: 8,376
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
Mr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny starsMr_love_monkey has a pair of shiny stars
Re: Programming Challenges?

Quote:
Originally Posted by danielf View Post
Here's my Monty Hall. It's in LISP again, but nobody speaks LISP

Spoiler: 
(defun monty-hall (times)
(let ((change-hits 0)
(change-misses 0)
(no-change-hits 0)
(no-change-misses 0)
(n-change-trials 0)
(doors '(nil nil nil)))
(dotimes (n times)
(dotimes (x 3)
(setf (nth x doors) 0))
(setf (nth (random 3) doors) 1)
(let* ((choice (random 3))
(choice-set (remove choice '(0 1 2)))
(alternative nil)
(change-trial (random 2)))
(if (equal (nth choice doors) 1)
(setf alternative (nth (random 2) choice-set))
(progn
(if (equal (nth (first choice-set) doors) 0)
(setf alternative (second choice-set))
(setf alternative (first choice-set)))))
(if (equal change-trial 1)
(progn
(incf n-change-trials)
(if (equal (nth alternative doors) 1)
(incf change-hits)
(incf change-misses)))
(if (equal (nth choice doors) 1)
(incf no-change-hits)
(incf no-change-misses)))))
(format t "~% change-hits ~A ~A" change-hits (float (/ change-hits n-change-trials)))
(format t "~% no-change-hits ~A ~A" no-change-hits (float (/ no-change-hits (- times n-change-trials))))
))

ah..... lisp.....next thing we know we'll have code in Occam and Prolog

---------- Post added at 07:27 ---------- Previous post was at 07:25 ----------

Quote:
Originally Posted by Damien View Post
I find it's a space thing, if it's one line it's just ugly.

Code:
if (ProductType == ProductType.Software)
{
    // do something

}
else
{
   //do something else
}
or

Code:
if (ProductType == ProductType.Software)
     // do something
 else
    //do something else

well, again, Sun coding standards say that you should do :

Code:
 if (true) { 
   // something 
} else {
  //something else
}
which is slightly less bulky..
Mr_love_monkey is offline   Reply With Quote