hackeps-chasethepair

Chase The Pair Challenge by HackEPS2019

HitCount GitHub stars GitHub forks GitHub repo size in bytes GitHub contributors GitHub license

👫 “Chase The Pair” challenge solution from HackEPS

Problem

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]

Description

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

Information

Requirements

This project is using Python3.7. No external libraries needed.

Recommendations

Usage of virtualenv is recommended for package library / runtime isolation.

Usage

To run this script, please execute the following from the root directory:

  1. Setup virtual environment

  2. Run the script with the default values

  python3 -m src [--set_size INT]

Authors

License

MIT © Albert Suarez