• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Funny(deadly) Interview Question

 
Siddhesh Deodhar
Ranch Hand
Posts: 118
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ryan McGuire
Ranch Hand
Posts: 1078
4
  • Likes 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
9
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another take on this problem is something like...

and run the program with the following arguments:
java Test Test
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Yogesh Gnanapraksam
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice.. I have to learn more about quines...
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 384
Java MyEclipse IDE Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is java Quine program

 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naveen yadav wrote:here is java Quine program



This doesn't work...I get a "File not found" error...Note that there are examples above that DO work, without requiring the source file.
 
Andy Jack
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an important question is - why do i need a quine ?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't. There's no practical use (that I can think of), it's just a puzzle. Some people find the challenge interesting.
 
Ivan Jozsef Balazs
Rancher
Posts: 981
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quine (computing)
 
Ivan Jozsef Balazs
Rancher
Posts: 981
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andy Jack wrote:an important question is - why do i need a quine ?


George Mallory

Mallory is famously quoted as having replied to the question "Why do you want to climb Mount Everest?" with the retort "Because it's there",
which has been called "the most famous three words in mountaineering".

 
Jayesh A Lalwani
Rancher
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait a minute. The discussion of Quine is interesting.. But the interviewer was smoking in the interview?!
 
Ivan Jozsef Balazs
Rancher
Posts: 981
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
naveen yadav wrote:here is java Quine program


For the record: it is actually not a Quine program:

A quine is a computer program which takes no input and produces a copy of its own source code as its only output.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic