Numbers guessing game

A=1;B=100;X=0;C=0;N=$[$RANDOM%$B+1];until [ $X -eq $N ];do read -p "N between $A and $B. Guess? " X;C=$(($C+1));A=$(($X<$N?$X:$A));B=$(($X>$N?$X:$B));done;echo "Took you $C tries, Einstein";
Felt like I need to win the lottery, and wrote this command so I train and develop my guessing abilities.
Sample Output
N between 1 and 100. Guess? 50
N between 1 and 50. Guess? 20
N between 20 and 50. Guess? 21
Took you 3 tries, Einstein

13
By: rodolfoap
2009-12-16 13:24:23

What Others Think

Heh, the first time I ran this the random number was 100 and I thought something was wrong with the logic. Neat.
deltaray · 551 weeks and 1 day ago
I used to want to become a programmer, but this is a difficult profession for me, so I did not go to work in this specialty, but simply made it my hobby. Now I make money using [url=https://csgobettings.com/lootbear/] lootbear promo code[/url] is a site where there are various top-end betting platforms. You can also try, you might like it, this is a very easy way to earn big money without leaving home.
Ablessairse · 15 weeks ago
Ablessairse · 15 weeks ago
Ablessairse · 15 weeks ago
I used to want to become a programmer, but this is a difficult profession for me, so I did not go to work in this specialty, but simply made it my hobby. Now I make money using csgoempire.gg is a site where there are various top-end betting platforms. You can also try, you might like it, this is a very easy way to earn big money without leaving home.
Ablessairse · 10 weeks and 4 days ago
My favorite guessing game is online casino games, especially these last days)) I found the perfect one for me at this site by reading numbers of reviews. I have chosen Grand Mondial casino, have you played it?
MaddisonFuller · 5 weeks and 3 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: