QM Guess Game :) TheVig Posting Freak Posts: 988 Threads: 248 Joined: Feb 2008 11-26-2009, 05:19 PM Happy American Thanksgiving everyone!!! Here's a QM Guessing game I whipped up for the holidays!! Function QM_Guessing_Game Code: ```;NewNumber str s.RandomString(1 2 "0-9") int i=val(s) , int guesses=0 str message="Make an Attempt, guess a number 1-100" ;Guess str guess if(!inp(guess message "QM Guess Game" "" int'test)) ret int iguess=val(guess) if iguess=i ,message.format("Yes, the number was %i. You are a winner![]Would you like to play again?" i) ,if(mes(message "QM Guessing Game" "YN?") = 'Y') mac "QM_Guessing_Game" ,ret else ,guesses+1 ,if guesses=8 ,,message.format("You lose! The number was %i[]Would you like to play again?" i) ,,if(mes(message "QM Guessing Game" "YN?") = 'Y') mac "QM_Guessing_Game" ,,ret ,if iguessi ,,message="Too Big, guess again" ,if guesses=7 ,,message.from(message ", LAST CHANCE!!") ,goto Guess``` Funny how much this shows how to do things with QM!! I am thankful for Gintaras! Thank you! jimmy vig Reply Reply Gintaras Administrator Posts: 10,951 Threads: 125 Joined: Dec 2002 11-26-2009, 05:44 PM Something like this often is used in programming, for example to find a string in a sorted list faster. Instead of comparing string0, string1, and so on, compare string50, then string25 or string75 and so on. Reply Reply TheVig Posting Freak Posts: 988 Threads: 248 Joined: Feb 2008 11-27-2009, 07:25 AM How does that work in programming? There's not a response that says "Too big" or "Too small." Is there a name for this method of working with data? Now I'm curious :9 Thanks, jimmy vig Reply Reply Gintaras Administrator Posts: 10,951 Threads: 125 Joined: Dec 2002 11-27-2009, 07:45 AM sorry, don't know the name of the algorithm Reply Reply TheVig Posting Freak Posts: 988 Threads: 248 Joined: Feb 2008 11-27-2009, 07:49 AM Yep...I gotta learn about more of those. They seem to be a good way of looking at things. I tend to want to re-invent the wheel! Reply Reply Time_Runner Senior Member Posts: 262 Threads: 63 Joined: Nov 2005 11-30-2009, 12:52 AM Nice – however, the game chose a 0 as its number and I never went below 1, so I lost. Reply Reply BillTalada Junior Member Posts: 9 Threads: 6 Joined: Oct 2009 12-04-2009, 07:32 PM The algorithm for solving it in the least turns is call a binary search. Just guess the middle number of the remaining set. So, for example, from a set of 0 to 255 numbers, it will never take more than 8 guesses by guessing 128, 64, 32, 16, 8, 4, 2, 1 or 0. Reply Reply « Next Oldest | Next Newest »