Showing posts with label Computing. Show all posts
Showing posts with label Computing. Show all posts

Thursday, October 7, 2010

Surviving the monster: A programming problem

Comments
I encountered this programming problem some time ago-

Inside a room, there is a monster with N heads, and a human (with 1 head). The human has two laser guns. The first gun, A destroys C1 heads when fired and the second gun,B destroys C2 heads when fired [The guns may destroy both the monster's as well as human heads, but the guns prioritize monster heads over human ones].

Also, if after the firing of the gun the monster has a positive non-zero number of heads left, the monster will grow additional heads. The monster grows G1 heads when gun A is used and it grows G2 heads when gun B is used.

The problem is to input N, C1, C2, G1 and G2, then find out what would be the shortest combination of gun-choice(A or B) the human must use to kill the monster(the monster dies when No. of heads=0).


I asked for help on the Codecall Forums to solve it, and a member, zoranh has solved the problem for me in C++. The solution makes use of Dijkstra's algorithm and it works with any number of guns. You can download the solution here.

And of course, if you have found an alternative method do post it here!!

Interested in solving more C++ puzzles? Get your copy of Exceptional C++: 47 Engineering Puzzles, Programming Problems, and Solutions

Wednesday, October 6, 2010

Maverick Meerkat: Ubuntu 10.10

Comments
I just wanted to remind you guys that the latest version of Ubuntu, version 10.10 (dubbed Meerkat Maverick) is set to release on the 10th of October, which is four days from today. Most Ubuntu users will definitely want to upgrade to this version. For those of you who do not already use Ubuntu, now is a great time to start. You can download it for FREE from http://www.ubuntu.com.Ubuntu 10.10 will certainly be a great starting point for those of you who want to begin their journey on open source software and Linux.

You can also read the review of the beta version here by Linoob.com here- http://www.linoob.com/2010/09/ubuntu-10-10-first-impressions/ . Stay tuned for more Linux and open-source news!