Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Common Lisp
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Birthday paradox=== The following program calculates the smallest number of people in a room for whom the probability of unique birthdays is less than 50% (the [[birthday paradox]], where for 1 person the probability is obviously 100%, for 2 it is 364/365, etc.). The answer is 23. In Common Lisp, by convention, constants are enclosed with + characters. <syntaxhighlight lang="lisp"> (defconstant +year-size+ 365) (defun birthday-paradox (probability number-of-people) (let ((new-probability (* (/ (- +year-size+ number-of-people) +year-size+) probability))) (if (< new-probability 0.5) (1+ number-of-people) (birthday-paradox new-probability (1+ number-of-people))))) </syntaxhighlight> Calling the example function using the [[REPL]] (Read Eval Print Loop): <syntaxhighlight lang="text"> CL-USER > (birthday-paradox 1.0 1) 23 </syntaxhighlight>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)