Vandrico application

So I’ve been applying to jobs and I’ve found that I get pretty interested in jobs that have coding challenges. Mainly because it gives me something to focus on for a little bit, instead of just droning away trying to make my cover letter interesting. One recent coding question involved making a POST request and then guessing a number.

It seemed like a harmless enough question and since I don’t come from a software background, it seemed fun to me. To tackle the problem, I used the requests module in python, and then implemented a binary search to reduce the amount of time to guess the number. Binary search is a divide and conquer algorithm, so you are recursively adjusting the range in which you are searching for the number.

def binarysearch(num, low, high):
   numguesses = num 
   theguess = (low + high)/2
   guess = {“guess”:theguess}
   r = requests.post(url, json = guess)
   if high < low:
      return -1 #lol high isn’t less than low
      mid = (low + high)/2
   if “correct” in r.text:
      return (mid, numguesses)
      if “high” in r.text:
         numguesses = numguesses + 1
         return binarysearch(numguesses, low, mid-1)
         numguesses = numguesses + 1
         return binarysearch(numguesses,mid+1, high)

I never heard back so this means either my solution isn’t complete or they just don’t like my solution. I suppose it would be beneficial to write unit tests for it?

comments powered by Disqus