👫 “Chase The Pair” challenge solution from HackEPS
Given a number (number A) get the closest pair of numbers (number B and number C) from two sets consisting of random numbers. When there are two numbers from the same set that are at the same distance from the result you can return either.
Given two sets of numerical values (SetA and SetB)
SetA: [1,23,45,66,84,113,145,178,205,210,221,250,264,300]
SetB: [5,31,40,52,73,103,126,162,195,214,225,241,256,267]
Given a random numerical value (toChase) contained within the two sets (It does not have to exist within these)
toChase: 231
WHERE toChase >= min(SetA, SetB) && toChase <= max(SetA, SetB)
Find that pair of numerical values closest to toChase
Result: [221, 225]
resources/setsGenerator
Use Python Lambdas with each set and get the closest number of to_chase
number given the set:
return min(set_[a|b], key=lambda x: abs(x - to_chase))
This project is using Python3.7. No external libraries needed.
Usage of virtualenv is recommended for package library / runtime isolation.
To run this script, please execute the following from the root directory:
Setup virtual environment
Run the script with the default values
python3 -m src [--set_size INT]
MIT © Albert Suarez