| Author |
Funny(deadly) Interview Question
|
Siddhesh Deodhar
Ranch Hand
Joined: Mar 05, 2009
Posts: 117
|
|
For my campus placements, Interviewer asked me one funny(deadly) question.
He said, "write a program whose output is the program itself".
I thought on it for while, Interviewer was smiling saying take your own time kid and started smoking.
After stretching my head i shouted, "Sir, within my code I will read the same code file and display"
"Amazing kid"..you are right, please write it and show me.
With victorious face, i wrote code in front of him in C considering standard's, indentation and other conventions.
Interviewer was very happy and started behaving like he is my uncle. . Asked me few questions about my family and some other technical stuff.
I got selected without any hassle.
He gave me few sample answers which my friends told him. Following are some which i rememebred
- We need to read RAM
- We need to print code as it is in "print" statements.
Well, This might be a joke, but the question he asked me can stand deadly when you are under pressure.
|
Good, Better, Best, Don't take rest until, Good becomes Better, and Better becomes Best.
Sidd : (SCJP 6 [90%] )
|
 |
Ryan McGuire
Ranch Hand
Joined: Feb 18, 2005
Posts: 890
|
|
However often the executable (or the .class or .jar file for Java) is distributed without the source code file. If you had to solve the problem WITHOUT the source code available at run time, how would you do it.
|
 |
Tina Smith
Ranch Hand
Joined: Jul 21, 2011
Posts: 112
|
|
Another take on this problem is something like...
and run the program with the following arguments:
java Test Test
|
Everything is theoretically impossible, until it is done. ~Robert A. Heinlein
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 23395
|
|
|
There is a word for such a program; it's called a "Quine", if you're interested in Googling. The solution you've described -- reading the source and printing it -- is considered a cheat, and is not a valid quine. It's entirely possible to create genuine quines that don't read their own source.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Yogesh Gnanapraksam
Ranch Hand
Joined: Dec 17, 2009
Posts: 93
|
|
Tina Smith wrote:Another take on this problem is something like...
and run the program with the following arguments:
java Test Test
I don't understand !!! how this is supposed to be Quine
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 8428
|
|
Tina Smith wrote:Another take on this problem is something like...
and run the program with the following arguments:
java Test Test
This won't compile.
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 2686
|
|
Ernest Friedman-Hill wrote:The solution you've described -- reading the source and printing it -- is considered a cheat, and is not a valid quine.
It's probably the sort of cheat that would go down well in an interview if you can't actually create a genuine quine, though .
|
 |
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2127
|
|
Matthew Brown wrote:
Ernest Friedman-Hill wrote:The solution you've described -- reading the source and printing it -- is considered a cheat, and is not a valid quine.
It's probably the sort of cheat that would go down well in an interview if you can't actually create a genuine quine, though  .
Also a perfectly legitimate answer if the interviewer hasn't actually specified that you can't read the source file. Might as well go with a solution that's simple and easy to maintain.
|
 |
Daniel Doboseru
Ranch Hand
Joined: Sep 26, 2011
Posts: 57
|
|
@Siddhesh: you said:
For my campus placements, Interviewer asked me one funny(deadly) question.
What do you mean be campus placements? You're student and for a place in the campus you had a technical interview as for hiring?
|
 |
Yogesh Gnanapraksam
Ranch Hand
Joined: Dec 17, 2009
Posts: 93
|
|
What do you mean be campus placements?
It refers to an event organized by the college management in which various companies visit the college campus and conduct written tests and technical interviews and give a job offer to the candidates who seem to fit their requirements.
|
 |
Daniel Doboseru
Ranch Hand
Joined: Sep 26, 2011
Posts: 57
|
|
|
Oh, i see. Very nice thing. We have such a thing too: several companies come and present their offer, technologies etc and afterwards accept CVs from interested students, offering them the chance of a interview. We call them generically InfoTechs (ElectroTech, InstallTech, MechaniTech depending of the faculty).
|
 |
simi selva
Greenhorn
Joined: Nov 18, 2011
Posts: 2
|
|
|
nice.. I have to learn more about quines...
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 3901
|
|
from wikipedia:
A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are self-replicating programs, self-reproducing programs, and self-copying programs.
sounds a lot like a worm to me.
where did this interview take place?
viruses are us ?
|
I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
|
 |
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 3901
|
|
However often the executable (or the .class or .jar file for Java) is distributed without the source code file. If you had to solve the problem WITHOUT the source code available at run time, how would you do it.
so much for my career as a virus writer
|
 |
Bhanuprakash Sreenivas
Greenhorn
Joined: Jan 01, 2010
Posts: 6
|
|
Since Java is compiled and then interpreted , technically it is not feasible to get a exact copy of the
source code.
For example - The comments of a source will not be visible.
Directly interpreted languages like Javascript can be used to achieve this.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 23395
|
|
Bhanuprakash Sreenivas wrote:Since Java is compiled and then interpreted , technically it is not feasible to get a exact copy of the
source code.
For example - The comments of a source will not be visible.
Directly interpreted languages like Javascript can be used to achieve this.
Indeed, the many working examples above are all imaginary.
|
 |
Bhanuprakash Sreenivas
Greenhorn
Joined: Jan 01, 2010
Posts: 6
|
|
Ernest Friedman-Hill wrote:
Bhanuprakash Sreenivas wrote:Since Java is compiled and then interpreted , technically it is not feasible to get a exact copy of the
source code.
For example - The comments of a source will not be visible.
Directly interpreted languages like Javascript can be used to achieve this.
Indeed, the many working examples above are all imaginary. 
Oops.. jumped the gun
|
 |
naveen yadav
Ranch Hand
Joined: Oct 23, 2011
Posts: 328
|
|
here is java Quine program
|
 |
 |
|
|
subject: Funny(deadly) Interview Question
|
|
|