Skip to content

Commit 1799950

Browse files
ErikSchierboomBNAndrasIsaacGtasxatzial
authored
Add baffling-birthdays exercise (#2539)
* Add `baffling-birthdays` exercise * Update exercises/baffling-birthdays/introduction.md Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> * Update exercises/baffling-birthdays/introduction.md Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> * Consistency * Update instructions.md Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> * Update instructions.md Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com> * Update introduction.md Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com> * Update introduction.md Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update introduction.md Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com> * Lowercase birthday paradox * Use estimate * Out of college * Change birthday to birthdates * Add leap year note * Change quantity * Update exercises/baffling-birthdays/canonical-data.json Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update exercises/baffling-birthdays/canonical-data.json Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update exercises/baffling-birthdays/canonical-data.json Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Use collection instead of set * Estimate * Simplify instructions * Simplify canonical data * Update instructions.md Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update instructions.md Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Another attempt * Tweaks * Update canonical-data.json Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update canonical-data.json Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Use nesting and improve naming * More work * Merge properties * Update exercises/baffling-birthdays/canonical-data.json Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update exercises/baffling-birthdays/introduction.md Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> * Update exercises/baffling-birthdays/instructions.md Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com> --------- Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com> Co-authored-by: Isaac Good <IsaacG@users.noreply.github.com> Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
1 parent 6766d1b commit 1799950

File tree

4 files changed

+260
-0
lines changed

4 files changed

+260
-0
lines changed
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
{
2+
"exercise": "baffling-birthdays",
3+
"comments": [
4+
"Dates are formatted as 'YYYY-MM-DD'.",
5+
"",
6+
"To increase the likelihood of consistent result, the tests should run the code returning random results many times.",
7+
"",
8+
"The expected probability values should be compared using some tolerance to allow for small deviations."
9+
],
10+
"cases": [
11+
{
12+
"description": "shared birthday",
13+
"cases": [
14+
{
15+
"uuid": "716dcc2b-8fe4-4fc9-8c48-cbe70d8e6b67",
16+
"description": "one birthdate",
17+
"property": "sharedBirthday",
18+
"input": {
19+
"birthdates": ["2000-01-01"]
20+
},
21+
"expected": false
22+
},
23+
{
24+
"uuid": "f7b3eb26-bcfc-4c1e-a2de-af07afc33f45",
25+
"description": "two birthdates with same year, month, and day",
26+
"property": "sharedBirthday",
27+
"input": {
28+
"birthdates": ["2000-01-01", "2000-01-01"]
29+
},
30+
"expected": true
31+
},
32+
{
33+
"uuid": "7193409a-6e16-4bcb-b4cc-9ffe55f79b25",
34+
"description": "two birthdates with same year and month, but different day",
35+
"property": "sharedBirthday",
36+
"input": {
37+
"birthdates": ["2012-05-09", "2012-05-17"]
38+
},
39+
"expected": false
40+
},
41+
{
42+
"uuid": "d04db648-121b-4b72-93e8-d7d2dced4495",
43+
"description": "two birthdates with same month and day, but different year",
44+
"property": "sharedBirthday",
45+
"input": {
46+
"birthdates": ["1999-10-23", "1988-10-23"]
47+
},
48+
"expected": true
49+
},
50+
{
51+
"uuid": "3c8bd0f0-14c6-4d4c-975a-4c636bfdc233",
52+
"description": "two birthdates with same year, but different month and day",
53+
"property": "sharedBirthday",
54+
"input": {
55+
"birthdates": ["2007-12-19", "2007-04-27"]
56+
},
57+
"expected": false
58+
},
59+
{
60+
"uuid": "df5daba6-0879-4480-883c-e855c99cdaa3",
61+
"description": "two birthdates with different year, month, and day",
62+
"property": "sharedBirthday",
63+
"input": {
64+
"birthdates": ["1997-08-04", "1963-11-23"]
65+
},
66+
"expected": false
67+
},
68+
{
69+
"uuid": "0c17b220-cbb9-4bd7-872f-373044c7b406",
70+
"description": "multiple birthdates without shared birthday",
71+
"property": "sharedBirthday",
72+
"input": {
73+
"birthdates": [
74+
"1966-07-29",
75+
"1977-02-12",
76+
"2001-12-25",
77+
"1980-11-10"
78+
]
79+
},
80+
"expected": false
81+
},
82+
{
83+
"uuid": "966d6b0b-5c0a-4b8c-bc2d-64939ada49f8",
84+
"description": "multiple birthdates with one shared birthday",
85+
"property": "sharedBirthday",
86+
"input": {
87+
"birthdates": [
88+
"1966-07-29",
89+
"1977-02-12",
90+
"2001-07-29",
91+
"1980-11-10"
92+
]
93+
},
94+
"expected": true
95+
},
96+
{
97+
"uuid": "b7937d28-403b-4500-acce-4d9fe3a9620d",
98+
"description": "multiple birthdates with more than one shared birthday",
99+
"property": "sharedBirthday",
100+
"input": {
101+
"birthdates": [
102+
"1966-07-29",
103+
"1977-02-12",
104+
"2001-12-25",
105+
"1980-07-29",
106+
"2019-02-12"
107+
]
108+
},
109+
"expected": true
110+
}
111+
]
112+
},
113+
{
114+
"description": "random birthdates",
115+
"cases": [
116+
{
117+
"uuid": "70b38cea-d234-4697-b146-7d130cd4ee12",
118+
"description": "generate requested number of birthdates",
119+
"scenarios": ["random"],
120+
"property": "randomBirthdates",
121+
"input": {},
122+
"expected": "length == groupsize"
123+
},
124+
{
125+
"uuid": "d9d5b7d3-5fea-4752-b9c1-3fcd176d1b03",
126+
"description": "years are not leap years",
127+
"scenarios": ["random"],
128+
"property": "randomBirthdates",
129+
"input": {},
130+
"expected": {
131+
"years": {
132+
"leapYear": false
133+
}
134+
}
135+
},
136+
{
137+
"uuid": "d1074327-f68c-4c8a-b0ff-e3730d0f0521",
138+
"description": "months are random",
139+
"scenarios": ["random"],
140+
"property": "randomBirthdates",
141+
"input": {},
142+
"expected": {
143+
"months": {
144+
"random": true
145+
}
146+
}
147+
},
148+
{
149+
"uuid": "7df706b3-c3f5-471d-9563-23a4d0577940",
150+
"description": "days are random",
151+
"scenarios": ["random"],
152+
"property": "randomBirthdates",
153+
"input": {},
154+
"expected": {
155+
"days": {
156+
"random": true
157+
}
158+
}
159+
}
160+
]
161+
},
162+
{
163+
"description": "estimated probability of at least one shared birthday",
164+
"cases": [
165+
{
166+
"uuid": "89a462a4-4265-4912-9506-fb027913f221",
167+
"description": "for one person",
168+
"scenarios": ["random"],
169+
"property": "estimatedProbabilityOfSharedBirthday",
170+
"input": {
171+
"groupSize": 1
172+
},
173+
"expected": 0.0
174+
},
175+
{
176+
"uuid": "ec31c787-0ebb-4548-970c-5dcb4eadfb5f",
177+
"description": "among ten people",
178+
"scenarios": ["random"],
179+
"property": "estimatedProbabilityOfSharedBirthday",
180+
"input": {
181+
"groupSize": 10
182+
},
183+
"expected": 11.694818
184+
},
185+
{
186+
"uuid": "b548afac-a451-46a3-9bb0-cb1f60c48e2f",
187+
"description": "among twenty-three people",
188+
"scenarios": ["random"],
189+
"property": "estimatedProbabilityOfSharedBirthday",
190+
"input": {
191+
"groupSize": 23
192+
},
193+
"expected": 50.729723
194+
},
195+
{
196+
"uuid": "e43e6b9d-d77b-4f6c-a960-0fc0129a0bc5",
197+
"description": "among seventy people",
198+
"scenarios": ["random"],
199+
"property": "estimatedProbabilityOfSharedBirthday",
200+
"input": {
201+
"groupSize": 70
202+
},
203+
"expected": 99.915958
204+
}
205+
]
206+
}
207+
]
208+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Instructions
2+
3+
Your task is to estimate the birthday paradox's probabilities.
4+
5+
To do this, you need to:
6+
7+
- Generate random birthdates.
8+
- Check if a collection of randomly generated birthdates contains at least two with the same birthday.
9+
- Estimate the probability that at least two people in a group share the same birthday for different group sizes.
10+
11+
~~~~exercism/note
12+
A birthdate includes the full date of birth (year, month, and day), whereas a birthday refers only to the month and day, which repeat each year.
13+
Two birthdates with the same month and day correspond to the same birthday.
14+
~~~~
15+
16+
~~~~exercism/caution
17+
The birthday paradox assumes that:
18+
19+
- There are 365 possible birthdays (no leap years).
20+
- Each birthday is equally likely (uniform distribution).
21+
22+
Your implementation must follow these assumptions.
23+
~~~~
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Introduction
2+
3+
Fresh out of college, you're throwing a huge party to celebrate with friends and family.
4+
Over 70 people have shown up, including your mildly eccentric Uncle Ted.
5+
6+
In one of his usual antics, he bets you £100 that at least two people in the room share the same birthday.
7+
That sounds ridiculous — there are many more possible birthdays than there are guests, so you confidently accept.
8+
9+
To your astonishment, after collecting the birthdays of just 32 guests, you've already found two guests that share the same birthday.
10+
Accepting your loss, you hand Uncle Ted his £100, but something feels off.
11+
12+
The next day, curiosity gets the better of you.
13+
A quick web search leads you to the [birthday paradox][birthday-problem], which reveals that with just 23 people, the probability of a shared birthday exceeds 50%.
14+
15+
Ah. So _that's_ why Uncle Ted was so confident.
16+
17+
Determined to turn the tables, you start looking up other paradoxes; next time, _you'll_ be the one making the bets.
18+
19+
~~~~exercism/note
20+
The birthday paradox is a [veridical paradox][veridical-paradox]: even though it feels wrong, it is actually true.
21+
22+
[veridical-paradox]: https://en.wikipedia.org/wiki/Paradox#Quine's_classification
23+
~~~~
24+
25+
[birthday-problem]: https://en.wikipedia.org/wiki/Birthday_problem
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
title = "Baffling Birthdays"
2+
blurb = "Estimate the birthday paradox's probabilities."
3+
source = "Erik Schierboom"
4+
source_url = "https://github.com/exercism/problem-specifications/pull/2539"

0 commit comments

Comments
 (0)