This application is built to determine a user's chosen number in n
questions, by asking a sequence of binary-range questions. The user is prompted to choose a number range, then to think of a number within that range. The maximum number of questions it will take is a calculated as n
, with the formula 1 + Floor(log2( n ))
. Based on binary search laws, the it will never require more than the allotted guesses to determine the user's number.
I built this as an excuse to play around with binary search, as well as to hone my skills in AngularJS. It's a simple application, on which I didn't spend much time. It's a pure SPA, built with four view modes, displayed as a sequence of prompts. I wrote the binary search algorithm without referencing any other solutions. After much tweaking and manual testing, I believe it can always find your number within the allotted number of questions!
npm install --save
gulp
nodemon app.js
If you have feature suggestions, please contact me here or at efournier92@gmail.com. If you'd like to submit a pull request, please feel free to, and I'll review merge it at my earliest convenience!
This project is provided under the MIT
licence and I hereby grant rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software without limitation, provided the resulting software also carries the same open-source licensing statement.