• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

Funny(deadly) Interview Question

 
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.
 
Rancher
Posts: 1191
22
  • 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.

 
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
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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.
 
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
 
lowercase baba
Posts: 12792
51
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.
 
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 .
 
Rancher
Posts: 3418
34
  • 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.
 
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).
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice.. I have to learn more about quines...
 
Ranch Hand
Posts: 4714
9
Scala Java
  • 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: 4714
9
Scala Java
  • 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
 
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
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • 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
 
Ranch Hand
Posts: 384
MyEclipse IDE Spring Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is java Quine program

 
fred rosenberger
lowercase baba
Posts: 12792
51
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.
 
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.
 
Rancher
Posts: 1041
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quine (computing)
 
Ivan Jozsef Balazs
Rancher
Posts: 1041
6
  • 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".

 
Rancher
Posts: 2759
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: 1041
6
  • 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.


 
I'm full of tinier men! And a tiny ad:
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!