Skip to content

Commit

Permalink
Fixes errors with some amount of number due to grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
asl97 committed Mar 19, 2024
1 parent 8a52127 commit 346f687
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1129,19 +1129,23 @@ <h1>Batch Card Printer</h1>
}

arr_group(arr, number_of_group){
// an extra array for number that exceed the grouping length
// grouping length is gotten by dividing the total number by 5
// and dropping the remainder.
// Grouping the numbers into group of numbers_of_group
// Used for grouping into B,I,N,G,O.
//
// eg: in normal bingo 76 would be outside of the b i n g o
// groups, it should overflow into group b
let groups = Array(number_of_group+1).fill().map(()=>[]);
let groups = Array(number_of_group).fill().map(()=>[]);
let group_range = Math.floor(arr.length/5);
arr.forEach((num, i)=>groups[Math.floor((num-1)/group_range)].push(num));
// excess numbers to be distributed
groups[number_of_group].forEach((num, i)=>groups[i].push(num));
for (let i=0; i<5; i++){
for (let l=0; l < group_range; l++){
groups[i].push(arr[l+i*group_range])
}
}
for (let i=group_range*5; i<arr.length; i++){
groups[i%5].push(arr[i])
}

return groups.slice(0,number_of_group);
return groups;
}

generator(arr){
Expand Down

0 comments on commit 346f687

Please sign in to comment.