Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Post your favorite trick questions

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it would be fun to post your favorite short trick questions where the anser seems like one thing if you read it fast, but it really is another.

Here is one that I like:

There are five apples and you take three. How may apples do you have left?



Eric
[ October 22, 2008: Message edited by: Eric Pascarello ]
 
Paul Yule
Ranch Hand
Posts: 229
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the vice president dies who will be the president?
 
Jhon Clay
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The President himself will continue until and unless the president has killed the vice president and is in court and has been ordered a life sentence or a death sentence
 
John Stone
Ranch Hand
Posts: 332
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the following sentence true or false?
"This sentence is not true."
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by John Stone:
Is the following sentence true or false?
"This sentence is not true."


It is neither. It's "mu".
[ November 13, 2008: Message edited by: pete stein ]
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are five apples and you take three. How may apples do you have left?

3 apples?
 
Patel Chintan
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose there is a town with just one male barber; and that every man in the town keeps himself clean-shaven: some by shaving themselves, some by attending the barber. shaves only those men who do not shave themselves.

question: Does the barber shave himself?

 
Jules Bach
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I remember this one from school, it actually left me very confused at the time:

The Puzzle:
Three friends share a hotel room together, and the bill is $25.
The three friends pay $10 each, which the bell boy takes to the hotel manager.

The manager keeps $25, and hands back $5 to the bell boy to return as change.

But the bell boy can't split $5 three ways, so he gives the friends $1 each and keeps $2 as a tip.

Each friend paid $10 and got $1 back. $10-$1 = $9

There were three of them 3 X $9 = $27

They paid a total of $27 for the room, and the bell-boy kept $2, so that adds up to $29.

Where did the other dollar go?
 
Maja Gralewska
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If each of them only paid $9 each then they paid the manager $27 in total, therefor $27 - $25 = $2 change which the bell bot takes as a tip.

right??
 
Pranay Narotam
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that other dollar is divided between the 3 friends..
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Um, no - Maja had it. There is no reason at all to add the bellboy's $2 to the $27 paid by the three friends. But if you subtract it, everything makes perfect sense.
 
arulk pillai
Author
Ranch Hand
Posts: 3387
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q. When designing your new code, what level of importance would you give to the following attributes?

-- Performance
-- Maintainability
-- Extendability
-- Ease of use
-- Scalability
 
Mandar Khire
Ranch Hand
Posts: 569
Android Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Solve this!
Following sentence is true!
Above sentence is false!

:?
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
arulk pillai wrote:Q. When designing your new code, what level of importance would you give to the following attributes?

-- Performance
-- Maintainability
-- Extendability
-- Ease of use
-- Scalability

What's the trick here?
 
Ganesh Rapolu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in migrating my project from mysql to oracle, which is in Java. when i am doing so I am

getting org.hibernate.type.SerializationException: could not deserialize.This is occurring

when iam reading from table where the field type in Data Base is BLOB and in the hibernate

mapping file type specified is java.security.PublicKey.

This exception is occurring only with oracle data base not with Mysql.I don't have any clue

to resolve this.Please help me.
Thanks in advance.
 
Sagar Rohankar
Ranch Hand
Posts: 2907
1
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ganesh, welcome to JR.

You're supposed to create a new thread for your question in Hibernate section. You just hijacked the thread that also in wrong forum.

Read http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
 
Costi Ciudatu
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a C programming tricky question that I like:


What's the result of compiling and running the above code ?
 
Ryan McGuire
Ranch Hand
Posts: 1068
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Costi Ciudatu wrote:Here's a C programming tricky question that I like:


What's the result of compiling and running the above code ?


Unless there's some syntax gotcha I'm missing...

i divided by *p is: 1

I hope I don't seem too cocky when I classify that as "elementary" and not very "tricky" at all.
 
Costi Ciudatu
Ranch Hand
Posts: 74
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a syntax gotcha you're missing (actually, everyone that I know has missed it, including myself; that's why I find it "tricky"):
in i/*p there's no space between / and *, therefore that's the beginning of a block comment that's never ended, so the compiler will complain.
Other than this, you're not "cocky" at all, the problem is indeed at most "elementary".
 
Ryan McGuire
Ranch Hand
Posts: 1068
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Costi Ciudatu wrote:There is a syntax gotcha you're missing (actually, everyone that I know has missed it, including myself; that's why I find it "tricky"):
in i/*p there's no space between / and *, therefore that's the beginning of a block comment that's never ended, so the compiler will complain.
Other than this, you're not "cocky" at all, the problem is indeed at most "elementary".


D'oh! Not very tricky but i got it wrong anyhow. I looked right at the i/*p and wondered how it would parse those operators but completely missed that it was a comment delimiter.

C'mon, gimme another.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently, who is the senior Folk in Javaranch ?
 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
write a c program to print hello world on screen,
your program should not contain ";"

I dont think this can be done in java though.
 
Rizvan Asgarov
Ranch Hand
Posts: 462
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seetharaman venkatasamy wrote:
Currently, who is the senior Folk in Javaranch ?

These are either Bear Bibeault or Marc Weber to my mind
But, Currently, who is the junior Folk in Javaranch ?
 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rizvan Asgarov wrote:...who is the junior Folk in Javaranch ?

definately me !!
 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:write a c program to print hello world on screen,
your program should not contain ";"

I dont think this can be done in java though.



 
Rizvan Asgarov
Ranch Hand
Posts: 462
IntelliJ IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Such a question have been asked from me during my high school year:

If you come across with a new car that very very cheaper, so what you will think about it?
 
Ryan McGuire
Ranch Hand
Posts: 1068
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


What does this print?

Disclaimer: I don't have a C compiler with me, so I might have a syntax error.
 
Vlado Zajac
Ranch Hand
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 2nd #include should probably be #define.
 
Ryan McGuire
Ranch Hand
Posts: 1068
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, a #define. What does this code print? If someone has a C compiler and can compile and run this, please post the output here. Why did it print what it did?


 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15356
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:
salvin francis wrote:write a c program to print hello world on screen,
your program should not contain ";"

I dont think this can be done in java though.




Almost, Salvin, but your example does not compile! Add { } after the if-statement and you're done. And indeed, this trick can't be translated to Java, because the expression inside the if-statement in Java is required to evaluate to a boolean, which is not so in C.
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(Titar is a name of bird in india)

Titar's front side 2 more titar.

Titar's back side 2 more titar.

Titar's upside 2 more titar.

Titar's downside 2 more titar.

Then tell me smarty, total no of titars ???

 
Ryan McGuire
Ranch Hand
Posts: 1068
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jigar Naik wrote:(Titar is a name of bird in india)

Titar's front side 2 more titar.

Titar's back side 2 more titar.

Titar's upside 2 more titar.

Titar's downside 2 more titar.

Then tell me smarty, total no of titars ???



There might be a language issue here, but I think the number you're looking for is 2 + 2 + 2 + 2 + 1 = 9. That assumes one single titar is the subject of all four sentences.
 
Mazer Lao Tzu
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Patel Chintan wrote:Suppose there is a town with just one male barber; and that every man in the town keeps himself clean-shaven: some by shaving themselves, some by attending the barber. shaves only those men who do not shave themselves.

question: Does the barber shave himself?



No, he does not shave himself. He gets his wife to shave for him. Some go to barber and some shaving themselves does not mean that all men do one of those two options (After that, it is simple deduction to determine that he has a wife and makes her do it).
 
Jigar Naik
Ranch Hand
Posts: 762
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suppose there is a town with just one male barber; and that every man in the town keeps himself clean-shaven: some by shaving themselves, some by attending the barber. shaves only those men who do not shave themselves.

question: Does the barber shave himself?






This sentence is unsatisfiable (a contradiction) because of the universal quantifier. The universal quantifier y will include every single element in the domain, including our infamous barber x. So when the value x is assigned to y, the sentence can be rewritten to , which simplifies to , a contradiction.



Wiki
 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jigar Naik wrote:(Titar is a name of bird in india)

Titar's front side 2 more titar.

Titar's back side 2 more titar.

Titar's upside 2 more titar.

Titar's downside 2 more titar.

Then tell me smarty, total no of titars ???



abbe question poonchna seekh.

its
Titar ke ek aage Titar
Titar ke ek peeche Titar
aage Titar,
peeche Titar,
bolo kitney Titar?


English Translation:

There is a Titar in front of a Titar
There is a Titar behind a Titar
Titar in front,
Titar behind,
How many Titar in all ?


 
Ryan McGuire
Ranch Hand
Posts: 1068
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:
There is a Titar in front of a Titar
There is a Titar behind a Titar
Titar in front,
Titar behind,
How many Titar in all ?


Let's see... I drew a diagram of the scenario described. I have a row of 15 titars side-by-side. In front of the fifth one is one more titar, so...
16. Final answer.

Let's take that concept a little farther...


At a small family gathering...
someone was there with their mother.
someone was there with their father.
someone was there with their sister.
someone was there with their brother.
someone was there with their son.
someone was there with their daughter.
someone was there with their aunt.
someone was there with their uncle.
someone was there with their neice.
someone was there with their nephew.
someone was there with their cousin.

How many people were there?
 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan McGuire wrote:
salvin francis wrote:
There is a Titar in front of a Titar
There is a Titar behind a Titar
Titar in front,
Titar behind,
How many Titar in all ?


Let's see... I drew a diagram of the scenario described. I have a row of 15 titars side-by-side. In front of the fifth one is one more titar, so...
16. Final answer.


Answer = 3

[Titar][Titar][Titar]

 
salvin francis
Bartender
Posts: 1277
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan McGuire wrote:
At a small family gathering...
someone was there with their mother.
someone was there with their father.
someone was there with their sister.
someone was there with their brother.
someone was there with their son.
someone was there with their daughter.
someone was there with their aunt.
someone was there with their uncle.
someone was there with their neice.
someone was there with their nephew.
someone was there with their cousin.

How many people were there?


lets see,

If i am a guy - A
and i came with my sis - B
and my mom - C
and my Dad - D
and my Mon/Dad's Brother - E
and his wife - F
and his son/daughter - G.

1. someone was there with their mother. A to C
2. someone was there with their father. A to D
3. someone was there with their sister. A to B
4. someone was there with their brother. B to A
5. someone was there with their son. C or D to A
6. someone was there with their daughter. C or D to B
7. someone was there with their aunt. A or B to F
8. someone was there with their uncle. A or B to E
9. someone was there with their neice. E or F to B
10. someone was there with their nephew. E or F to A
11. someone was there with their cousin. A or B to G

Total = 7


not so sure
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think six is the minimum number of people involved. (Well, for, how shall I put it... traditional family trees. ) One solution is to take Salvin's answer and send E or F home. We need one or the other, but we don't need both. Or we can send them both home, if we can augment G with another cousin of opposite gender.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
salvin francis wrote:
Ryan McGuire wrote:
salvin francis wrote:
There is a Titar in front of a Titar
There is a Titar behind a Titar
Titar in front,
Titar behind,
How many Titar in all ?


Let's see... I drew a diagram of the scenario described. I have a row of 15 titars side-by-side. In front of the fifth one is one more titar, so...
16. Final answer.


Answer = 3

[Titar][Titar][Titar]


Two seems sufficient.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic