Thursday, March 17, 2011

Guessing a Number 1 to 100

Each month, my local housing community has a residence council meeting to talk about any updates in the community. I attend these meetings for three reasons,

  1. They keep me up-to-date about any news or events in the community I live in
  2. They provide free pizza
  3. They have a "drawing" for one lucky winner to win a $20 Trader Joe's gift card
The first two items keep me excited about this meeting each month, but this last one is an added bonus. For over a year now, I have tried to go last on the sign in sheet, studying the other numbers and guessing a number that has the widest spread. Looking through everyone else's numbers, you can see what numbers would give you the highest probability, since they allow for the closest number to win the gift card. Recently, however, it's been a game of cat and mouse with who will get the last signature (and guessing number) on the sign in sheet. Inspired by Watson, this made me take a more sure way of choosing a number. 
    Using the python programming language, I was able to code up a quick script to enter a given set of numbers between 1-100, and then have it spit out the optimum number to choose. It basically just looks at the maximum distance between all the entered numbers, and then chooses the middle number between that distance. The python code can be seen here (to be converted from a txt file to .py file).
     The code is free to use and modify without any permission. I'm sure it can be optimized to have fewer lines of code, but that's what you get for not being much of a computer programmer. So far the program was used once at a previous meeting, with a friend using the second highest probability number, and we both lost. I blame it on the council choosing a random number from their head (#2), and not a random number generator. Either way, stuff like this takes time, so well have to wait and see. I have a couple more try's to use the program, so well see if it can maximize my odds enough to obtain another gift card!!

No comments:

Post a Comment