Add baffling-birthdays exercise - #779
Conversation
|
|
You can try doubling your runs from 1k to 2k. You can try widening the acceptable probability range. |
f401a42 to
a95d347
Compare
|
OK, it passes 6 times in a row (with this one) so far... |
a95d347 to
d01f64f
Compare
|
It passed 4 times in a row before i push this, and now it failed for 10 and 23 people tests! (in the php track, I ran it 10k ... but in bash it would take so much time !!) |
b77a468 to
1d4dfd3
Compare
|
re-increased tolerance for |
How much time is too much time? How slow is 3k? 4k? If it takes more than, say, 5 seconds, we probably want to widen the tolerance. |
it was about 20+ minutes for 2k - 3k before modifications... |
1d4dfd3 to
f4268c2
Compare
|
Regarding the slowness, you'll get must faster performance by using the builtin # return a random number in the range 0 <= n < $1
random_int() {
echo $(( RANDOM % $1 ))
}
february_days=$(( 1 + $(random_int 28) ))With group_size = 10 and runs = 5000, you're calling shuf 150,000 times and date 50,000 times. |
11fe39c to
8bffcb9
Compare
|
Results so far (runs are set at very rare are the -- To prevent the failure, maybe we could add this condition in the .bats file (this would be very unlucky if the run fails twice in a row!) I'm testing this ATM, and it seems to work good. |
|
Note, the tests need to run in under 20s max. I'd recommend trying to get them in under 5s. |
|
well, then, I can't see how to do... unless removing the tests which check for "estimated probability of at least one shared birthday" |
|
This is a bit of a hacky solution, but it is valid and fast. Roughly 0.9s to run 5000 checks, each check looking for a collision with up to 70 random values. #!/bin/bash
check () {
local -a hit
for (( j = 0; j < $1; j++ )); do
day=$((RANDOM % 365))
(( hit[day]++ == 0 )) || return 1
done
}
for (( i = 0; i < 5000; i++ )); do
check 70 || (( hit++ ))
done
echo $hit $(( hit / 50 ))It bypasses the whole "generate 70 dates" and goes straight to the math side: generate 70 values from a space of 365 and look for a collision. |
|
edit: Isn't the point to test the whole "generated 70 dates" ? |
|
I conclude that bash cannot be used to solve this with nested loops. It's just too slow. You might want to investigate https://en.wikipedia.org/wiki/Birthday_problem#Approximations |
|
I had a conversation with Claude about it. Turns out the bottlenecks are the number of subshells. (The "200 subshells" you see are while I had reduced
Here's a version that uses "private" functions to write global variables as the data-passing mechanism: https://gist.github.com/glennj/4e8a3ab4a9942b798ace0f8dba0bb30b The test suite runs in about 7 seconds on my machine. |
|
If this exercise requires hoops to solve in under 5s, I propose we add it to the foregone list. |
|
I don't think this is 'hoops', this is just that I need learning more and more :) |
|
new stats with runs=2k |
|
The fact that this requires so much work and learning to get working in a reasonable amount of time indicates to me that this may not be a great fit for the bash track 😄 Thoughts on marking this foregone, @glennj ? |
We have:
I think we can proceed. We'll probably see monstly 1 and 3 submitted. An instructions.append.md file would be useful to gently steer people along. Approaches articles might help too. |
Solutions that take long to run will fail the test runner. The approaches article can only be viewed after passing tests. We'd want to provide a fair bit of guidance in the append file to help students get this to pass on the test runner. |
|
How about this approach:
|
baffling-birthdays exercicebaffling-birthdays exercise
|
What's the status on this PR? |
* Co-authored-by: IsaacG * Co-authored-by: glennj
* Co-authored-by: IsaacG
…cism#784) update comments in bats-extra.bash files author: glennj
Safe tolerance adjustment for 2k runs
12cba5f to
9eca3bd
Compare
Co-authored-by: Glenn Jackman <glenn.jackman@gmail.com>
Add baffling-birthdays exercice to track.
I change difficulty from 1 to 4.
Hope everything is correct.
float with bash !
I increase the tolerance for the exercice with 10 and 23 people because, after multiple runs (many time consuming), sometimes one or the other fail when checking only respectively
11|12|13and50|51|52.or might be another way to do it more precisely ?
The other option is to increase the number of runs, but this is very time consuming in bash! (set now at 1000)
maybe I can try to parallelize the computings? or creating a file would help?
I got these result while debbuging :