4 ms·
Many years ago (wow...almost 10 now...I'm so old...) I was given a phone screen and at the end of the screen I was given a question to code a solution to and em
by justrudd 13y ago
Many years ago (wow...almost 10 now...I'm so old...) I was given a phone screen and at the end of the screen I was given a question to code a solution to and email it in. Since this was for a job across the country, I figure what the hell.
The problem was -
A man has to get a fox, a chicken, and a sack of corn across a river.
He has a rowboat, and it can only carry him and one other thing.
If the fox and the chicken are left together, the fox will eat the chicken.
If the chicken and the corn is left together, the chicken will eat the corn.
Write a program that will help the man make the correct decision and explain the operational complexity.
I was given an hour to come up with a solution. I worked on it about half-an-hour coming up with the algorithm. And then for some reason my brain keyed in on the "write a program" part of the question. So I wrote the following in C++ (from memory so may not be exact) -
int main(int argc, char** argv) {
std::cout
<< "Man takes chicken, leaves fox and corn, and returns" << std::endl
<< "Man takes fox, leaves corn, and returns with chicken" << std::endl
<< "Man leaves chicken and takes corn, leaves corn with fox, and returns" << std::endl
<< "Man takes chicken back across" << std::endl;
return 0;
}
It was a program that would tell the man the correct way to get everything across the river.
Must have been an OK answer because I got flown up and ended up working for them for 4 years (before a series of bad jobs that have finally lead back to something good).