Skip to content

Add baffling-birthdays exercice#779

Open
resu-xuniL wants to merge 4 commits into
exercism:mainfrom
resu-xuniL:baffling-birthdays
Open

Add baffling-birthdays exercice#779
resu-xuniL wants to merge 4 commits into
exercism:mainfrom
resu-xuniL:baffling-birthdays

Conversation

@resu-xuniL

Copy link
Copy Markdown
Contributor

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|13 and 50|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 :

   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file baffling_birthdays.bats, line 162)
     `assert_output $expect' failed
   
   -- output differs --
   expected : 11.694818
   actual   : 12.70
   --
   
 ✗ estimated probability of at least one shared birthday -> among twenty-three people
   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file baffling_birthdays.bats, line 170)
     `assert_output $expect' failed
   
   -- output differs --
   expected : 50.729723
   actual   : 51.10
   --
   
 ✗ estimated probability of at least one shared birthday -> among seventy people
   (from function `assert_output' in file bats-extra.bash, line 394,
    in test file baffling_birthdays.bats, line 178)
     `assert_output $expect' failed
   
   -- output differs --
   expected : 99.915958
   actual   : 99.90
   --```
---

Reviewer Resources:

[Track Policies](https://github.com/exercism/bash/blob/master/POLICIES.md)

Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
@resu-xuniL

resu-xuniL commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

23 persons test failed again...
I'll work on it. Any suggestions are welcome! ^^
it passed just before the this test ...

Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
@IsaacG

IsaacG commented Jun 12, 2026

Copy link
Copy Markdown
Member

Geez... 23 persons test failed again... I'll work on it tomorrow. Any suggestions are welcome! ^^ it passed just before the this test ...

You can try doubling your runs from 1k to 2k. You can try widening the acceptable probability range.

@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch from f401a42 to a95d347 Compare June 13, 2026 10:26
@resu-xuniL

resu-xuniL commented Jun 13, 2026

Copy link
Copy Markdown
Contributor Author

OK, it passes 6 times in a row (with this one) so far...
Thank you for your help!
(with runs at 1500)

@resu-xuniL resu-xuniL requested a review from IsaacG June 13, 2026 10:59
Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch from a95d347 to d01f64f Compare June 14, 2026 10:03
@resu-xuniL

resu-xuniL commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

It passed 4 times in a row before i push this, and now it failed for 10 and 23 people tests!
shall i increase back the tolerence (i decreased them)? or increase the runs to 3k ?

(in the php track, I ran it 10k ... but in bash it would take so much time !!)

@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch 6 times, most recently from b77a468 to 1d4dfd3 Compare June 14, 2026 12:08
@resu-xuniL

Copy link
Copy Markdown
Contributor Author

re-increased tolerance for 23 people test.

@IsaacG

IsaacG commented Jun 14, 2026

Copy link
Copy Markdown
Member

(in the php track, I ran it 10k ... but in bash it would take so much time !!)

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.

Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
@resu-xuniL

resu-xuniL commented Jun 14, 2026

Copy link
Copy Markdown
Contributor Author

(in the php track, I ran it 10k ... but in bash it would take so much time !!)

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...

@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch from 1d4dfd3 to f4268c2 Compare June 14, 2026 15:04
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
Comment thread exercises/practice/baffling-birthdays/baffling_birthdays.bats Outdated
@glennj

glennj commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Regarding the slowness, you'll get must faster performance by using the builtin $RANDOM variable instead of calling out to shuf

# 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.

Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
Comment thread exercises/practice/baffling-birthdays/.meta/example.sh Outdated
@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch 2 times, most recently from 284834a to 9a564dd Compare June 14, 2026 17:15
@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch 2 times, most recently from 11fe39c to 8bffcb9 Compare June 14, 2026 19:23
* Co-authored-by: IsaacG
* Co-authored-by: glennj
@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch from 8bffcb9 to ccc55d4 Compare June 14, 2026 19:30
@resu-xuniL

Copy link
Copy Markdown
Contributor Author

bf5b0d0

assert_between() {
  local -r start="${1}"
  local -r end="${2}"

  if (( start > end )); then
    return 1
  elif ! (( output >= "$1" && output <= "$2" )); then
    batslib_print_kv_single_or_multi 6 \
      'start'  "${start}" \
      'end'    "${end}" \
      'output' "${output}" \
    | batslib_decorate 'output falls outside the range defined by start and end' \
    | fail
  fi
}

on fail:

   (from function `assert_between' in file bats-extra.bash, line 651,
    in test file baffling_birthdays.bats, line 162)
     `assert_between 10 13' failed
   
   -- output falls outside the range defined by start and end --
   start  : 10
   end    : 13
   output : 14
   --

@glennj

glennj commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

OK, it passes 6 times in a row (with this one) so far... Thank you for your help! (with runs at 1500)

The "random" exercises are like that. Don't forget, once this PR is merged, it will also run for every subsequent merge (one of the GHA workflows tests all exercises). So we'd want it succeeding just about every time.

Comment thread exercises/practice/baffling-birthdays/bats-extra.bash Outdated
Comment thread exercises/practice/baffling-birthdays/bats-extra.bash Outdated
Comment thread exercises/practice/baffling-birthdays/bats-extra.bash Outdated
@resu-xuniL resu-xuniL force-pushed the baffling-birthdays branch from bf5b0d0 to f45a92f Compare June 15, 2026 17:37
@resu-xuniL

resu-xuniL commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

OK, it passes 6 times in a row (with this one) so far... Thank you for your help! (with runs at 1500)

The "random" exercises are like that. Don't forget, once this PR is merged, it will also run for every subsequent merge (one of the GHA workflows tests all exercises). So we'd want it succeeding just about every time.

I agree. I'll run many tests on 2 machines to see if it fails, and if it does, maybe we would increase the tolerance?

so far, 8 in a row with this one
From now on, I'm going to run the 10 and 23 people tests only. These were the only ones that were failing.
(and I'll won't waste (big) time with the 70 people test!)

Edit1: 25 runs and no fails....
26th fail : output 47 (for range 48-53)

stats:

output for test `10 people` : 
(assert_between is 10-13)
6x 10 | 13x 11 | 7x 12 | 0x 13 
none 13. Shall we 'risk' to decrease to 12?
output for test `23 people` :
(assert_between is 48-53)
2x 48 | 4x49 | 13x50 | 5x51 | 0x 52 | 1x 53 
+ 1x 47 !!! --> need to increase to 47-53

Edit2: I'll run with 3k runs (instead of 2k) to see results (with ranges: 10-12 and 48-52)
another fail at 53. need to keep 53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants