Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jginsburgn/drichlet-box
A function that returns the hole index for the numbered pigeon (in Pigeonhole Principle lingo).
https://github.com/jginsburgn/drichlet-box
Last synced: 16 days ago
JSON representation
A function that returns the hole index for the numbered pigeon (in Pigeonhole Principle lingo).
- Host: GitHub
- URL: https://github.com/jginsburgn/drichlet-box
- Owner: jginsburgn
- License: mit
- Created: 2021-07-05T18:20:44.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-07-05T20:49:32.000Z (over 3 years ago)
- Last Synced: 2024-07-04T16:08:10.963Z (4 months ago)
- Language: JavaScript
- Size: 26.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Drichlet Box
_Context: [Pigeonhole Principle Wikipedia Article](https://en.wikipedia.org/wiki/Pigeonhole_principle)._
A function that maps the `(holesCount, pigeonsCount, pigeonIndex)` 3-tuple to the corresponding `holeIndex`, in constant time.
## Explanation
Given a wooden structure with `holesCount` pigeonholes and `pigeonsCount` pigeons, the `drichlet-box` function returns the zero-based hole index, `holeIndex`, in which a pigeon indicated by the zero-based integer `pigeonIndex` should go, so that the following holds:
1. There are at least `floor(pigeonsCount/holesCount)` pigeons in a hole (small hole).
1. There are at most `floor(pigeonsCount/holesCount)` pigeons in a hole (big hole).
1. `drichlet-box` is an [increasing function](https://mathworld.wolfram.com/IncreasingFunction.html) in regards to its `pigeonIndex` argument.
1. The big holes are the first ones. In other words, if `i` is an index of a big hole and `j` is an index of a small hole, `i < j`.