Functions for finding numbers using higher/lower
Project description
higher-lower
Functions for finding numbers using higher/lower
Installation
Install this library using pip
:
$ pip install higher-lower
higher_lower(min_value, max_value, callback)
The higher_lower()
function searches for a value between min_value
and max_value
, calling callback()
for each candidate value to see if the target is higher or lower.
min_value
- the lowest possible valuemax_value
- the highest possible valuecallback(candidate)
- a callback function that takes a single integer argument and returnsActualIs.MATCH
,ActualIs.HIGHER
orActualIs.LOWER
For example:
from higher_lower import ActualIs
def callback(candidate):
if candidate == 7:
return ActualIs.MATCH
elif candidate > 7:
return ActualIs.LOWER
else:
return ActualIs.HIGHER
Given the above callback function, a search can be made for the number between 0 and 100 like so:
from higher_lower import higher_lower
number = higher_lower(0, 100, callback)
# number is now 7
Development
To contribute to this library, first checkout the code. Then create a new virtual environment:
cd higher-lower
python -mvenv venv
source venv/bin/activate
Or if you are using pipenv
:
pipenv shell
Now install the dependencies and tests:
pip install -e '.[test]'
To run the tests:
pytest
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
higher-lower-0.1.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for higher_lower-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b140cf347e0a414d8c90762923ea246beef1b9130c91dacf7b4144b02a91652b |
|
MD5 | 100d7f71ffa66bacc86ae7cbed7738ee |
|
BLAKE2b-256 | c64cbe7831ea3d5f4afd234b837a7324983096d3543e5cd5ee287296ca169f59 |