Miscellaneous > Programming & Networking

Let's play a game, pals. Challenge 3

(1/2) > >>

TheQuirk:
Next one.

Next challenge:

You have a chessboard. On the chessboard, there is a white knight and a
black pawn. Disregarding all the rules except the ones that
concern the movement of knights and pawns, the computer must calculate
if it's possible for the knight to stop the pawn from reacing the first

row, and if so, on which (earliest) move. The knight can stop the pawn in two
ways--either by eating it, or by moving right in front of it. If the pawn
takes the knight (I like to use the term "eats"), then the knight fails
to stop the pawn. The knight moves first.

I/O:
The program must read the starting positions for the pieces from a
file called "input.txt". It should be in the following format:

a4
d7

Where the first line represents the knight's location, and the second
line represents the pawn's location.

Once the program finishes its calculations, it must output the result
to "output.txt" with a number representing the number of moves. If
it's impossible to stop the pawn, then the program should outout the
number zero into "output.txt".

By the way, maybe I should post every challenge in a seperate thread? That would probably be a bit easier to read + easier to reference in the future.

Edit: Hints are available on AIM.

KernelPanic:

--- Quote from: TheQuirk ---
By the way, maybe I should post every challenge in a seperate thread? That would probably be a bit easier to read + easier to reference in the future.
--- End quote ---



Yes.
In fact, did it for you.

Pathos:
I'm going to use cin/cout instead.

And I should do my homework first.

worker201:

--- Quote from: Pathos ---I'm going to use cin/cout instead.
--- End quote ---


Unless things have changed ALOT since I used C++, reading from a textfile and writing to a textfile is not that hard.

Quirk, where are you getting this shit from?  Some textbook?  Maybe I want to read this book...
Right now, I am reading a barely comprehensible book about infinite sets and Cantor.  Much fun.

TheQuirk:
I got the first two challenges from an old Soviet book; this one I had to solve in class. The formatting is screwed up because I copy-pasted it from an email.

If you want a book, get "Programming Challenges" by Steven S. Skiene and Miguel A. Revilla. I haven't gotten very far into it, but it seems to be pretty good. If you don't want to make the same mistake I made--pay for stuff you can easily get online for free--just search Google for "informatics olympiad problems" and the like. Online programming competitions also contain a lot of programming problems (some solved, some unsolved).

Navigation

[0] Message Index

[#] Next page

Go to full version