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 · 584 weeks and 3 days 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 · 48 weeks and 2 days ago
Ablessairse · 48 weeks and 2 days ago
Ablessairse · 48 weeks and 2 days 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 · 43 weeks and 6 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 · 38 weeks and 5 days ago
Nachdem ich Ihnen von dem Online Casino https://online-roulett.at/roulette-echtes-geld-gewinnen/ erzählt habe, das ich schon lange spiele, werden Sie es auch besuchen wollen, da bin ich mir sicher. Behalten Sie daher den Link zu sich selbst oder gehen Sie sofort, um keine Zeit zu verschwenden.
Thicileares · 17 weeks ago
I honestly find the contents to this platform super informative and interesting at the same time. It is called the platform of https://jocuri-casino.net/live-casino-romania. I highly recommmend everybody out there to check it out for once.
KayGasaway · 10 weeks and 4 days ago
As we all long for the day our lives can return to something approaching our old normality, GAA players across the country are hoping that the GAA will prove an exception. Xbox Emulator All this has been said countless times of course, but the frustrations bear repeating to highlight how farcical it has been for club players for so long.
hrihant · 9 weeks and 4 days ago
I managed to get an outstanding product or service right now, along with I aquired this device coming from a ?????? site that will my mate informed me with regards to. My spouse and i has not been ready for a good deal, nevertheless My spouse and i ended up being mesmerized by simply the standard of the product or service.
WalkerNolan · 6 weeks and 4 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: