EMuller_Leap_Year

No preview image

1 collaborator

Default-person Eric Muller (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.2.1 • Viewed 164 times • Downloaded 17 times • Run 0 times
Download the 'EMuller_Leap_Year' 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.

REFLECTION

The change that I was able to make from exploring the model was that I was able to get the program to keep track of the rate at which someone in a room of 24 people will have a birthday on the 60th day of the year, if every year was a leap year. What I learned from exploring this model that conditional probability is hard to program when taken outside of a purely math context. Applying it physically within the realm of this program was much more difficult that I thought it would be, but it also allowed me to look at the step by step process through which conditional probabilities are calculated. I also thought it was an interesting representation of a phenomenon that most people would not think to be as common as it actually is. However, in my exprience this "birthday" phenomenon has happened on more than one occasion and probably more often than I will ever know.

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 or the NetLogo software in a publication, we ask that you include the citations below.

For the model itself:

Please cite the NetLogo software as:

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 https://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

Please start the discussion about this model! (You'll first need to log in.)

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
  lysuccesses
]

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

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 

to leapyear
    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 29 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 ]
  if any? turtles with [color = red]
    [ set lysuccesses lysuccesses + 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) "        "
      set lybirthday 60
     ]
   ]
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 ] ]
  ask turtles
    [ if any? other turtles with [birthday = [lybirthday] of myself]
        [ set color red
          set label-color red ] ]
end 


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

There is only one version of this model, created over 8 years ago by Eric Muller.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.