Birthdays

Birthdays preview image

2 collaborators

Uri_dolphin3 Uri Wilensky (Author)
Dor Abrahamson (Author)

Tags

birthday 

Tagged by Ankita Thakkar over 10 years ago

mathematics 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 625 times • Downloaded 85 times • Run 1 time
Download the 'Birthdays' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


WHAT IS IT?

In a room of 23 people, what are the chances that some two of them will have the same birthday?

Make your best guess, then run the model and see how often it happens.

HOW IT WORKS

Each turtle is randomly assigned a birthday. If a turtle has the same birthday as another turtle in the room, it turns green.

The model doesn't take leap years into account (there are no February 29th birthdays).

HOW TO USE IT

Press SETUP to initialize the model.

Press GO ONCE to generate a single room full of people.

Press GO to repeatedly generate many rooms full of people. The SUCCESS RATE monitor will show what percentage of those rooms had at least one matching birthday.

THINGS TO NOTICE

Is the success rate higher or lower than you expected?

THINGS TO TRY

To try a room with more people in it, edit the view and increase max-pycor.

How many people need to be in the room before the chance of a matching birthday is at least 90%? (Is this higher or lower than you expected?)

Can you work out mathematically what the odds should be? (Hint: start by considering the odds when the number of people is small.)

EXTENDING THE MODEL

Include leap year birthdays in the list of possibilities.

NETLOGO FEATURES

This model uses lists a lot, including list primitives such as map, foreach, item, position, sentence, and sort-by. Lists are used mostly to make the model display actual day names, instead of just numbers from 0 to 364. Lists are also used when sorting the turtles by birthday.

RELATED MODELS

The ProbLab suite of models, in the Mathematics/Probability section, contains many explorations of basic questions about probability and statistics.

HOW TO CITE

If you mention this model in a publication, we ask that you include these citations for the model itself and for the NetLogo software:

  • Wilensky, U. (2004). NetLogo Birthdays model. http://ccl.northwestern.edu/netlogo/models/Birthdays. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.
  • Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern Institute on Complex Systems, Northwestern University, Evanston, IL.

COPYRIGHT AND LICENSE

Copyright 2004 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227.

Comments and Questions

Click to Run Model

globals [
  days            ;; a list of the dates of all 365 days in the year
  successes       ;; how many ticks had at least one duplicate birthday
]

turtles-own [
  birthday        ;; this turtle's birthday as a number from 0 to 364
]

to setup
  clear-all
  set successes 0
  ;; create lists of each month and the number of days in each month
  ;; then iterate through the two lists and expand into a single list
  ;; of every day of the year
  let months ["January" "February" "March" "April" "May" "June" "July"
              "August" "September" "October" "November" "December"]
  let month-lengths [31 28 31 30 31 30 31 31 30 31 30 31]
  ;; now build up the list of all the day names in the year
  set days []
  ;; sets ?1 equal each month name and ?2 to the number of days in that month
  (foreach months month-lengths
  [ ;; use "sentence" to repeatedly glue lists together, so we wind
    ;; up with one big list
    set days (sentence days make-month ?1 ?2)
  ])
  reset-ticks
end 

;; this procedure generates all of the day names within a month

to-report make-month [month month-length]
  ;; use n-values to generate a list of the numbers from 1 to
  ;; the end of the month
  let day-numbers n-values month-length [? + 1]
  ;; now glue onto the month name each number
  report map [(word month " " ?)] day-numbers
end 

to go
  ;; kill off the turtles from the last round
  clear-turtles
  ;; populate the room with new turtles
  make-turtles
  ;; arrange the turtles in order by birthday
  sort-turtles
  ;; turn turtles with matching birthdays green
  show-matches
  ;; keep track of cumulative results
  if any? turtles with [color = green]
    [ set successes successes + 1 ]
  tick
end 

to make-turtles
  ;; ask the patches along the right edge of the world
  ;; to each sprout a turtle
  ask patches with [pxcor = max-pxcor]
  [
    sprout 1
    [
      set heading 90
      set color blue + 3
      ;; pick a random birthday (a number from 0 to 364)
      set birthday random length days
      ;; we use "word" to add some spaces onto the end
      ;; of the turtle's labels, otherwise the label
      ;; would visually overlap the turtle.  ITEM
      ;; is used to look up our day name in the list
      ;; of all day names.
       set label word (item birthday days) "        "
     ]
   ]
end 

to sort-turtles
  ;; sort-by takes an agentset and returns a sorted list
  let sorted sort-on [birthday] turtles
  ;; finally, we position each turtle according to its position
  ;; in the sorted list
  ask turtles
    [ set ycor max-pycor - position self sorted ]
end 

to show-matches
  ;; if there are any turtles with the same birthday
  ;; show it.
  ask turtles
    [ if any? other turtles with [birthday = [birthday] of myself]
        [ set color green
          set label-color green ] ]
end 


; Copyright 2004 Uri Wilensky.
; See Info tab for full copyright and license.

There are 10 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky about 12 years ago Updated to version from NetLogo 5.0.3 distribution Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Birthdays Download this version

Attached files

File Type Description Last updated
Birthdays.png preview Preview for 'Birthdays' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.