Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chapter 4 Sierra/Bates Puzzel-y Question

 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm on the Q&A part of Sierra/Bates, and for the life of me, I cannot figure out the best approach to solve a fill-in-the-blank programming:



Place the fragments into the code to produce the output 33. Note, you must use each fragment exactly once.

FRAGMENTS:
y y y y
x x
-=
*=
*=
*=
*=



Of course, they give the answer, which is






Please, someone help!
 
Prasad Kharkar
Ranch Hand
Posts: 446
1
Eclipse IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well this is a little bit difficult to guess but I think this is the best way to do this
we are given 4 compound operators and we have to use them exactly once
now given that we want output as 33 and x =7 and y = 2
we have to give just trial and error to this
33 is big as compared to 2 and 7 and hence we will use *= operator first
and also we have to use only 2 x we will use them all in this line only

this gives x = 49
now we have to reduce the answer by 16 to get 33
what do we have now?
4 y's , 2 *= and one -=
we can achieve 16 by

now y is 4

now it is 16
as we have x = 49 and y = 16
we can write

this gives 49-16 = 33

 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no straight forward technique for solving this kind of problem. I consider
myself lucky to have spotted how the elements might fit together in a reasonable
amount of time. But it could have taken for ever. What helped was to "fiddle" with
the given information on paper, play what-if mind games and draw pictures. There
were constraints in both the fill-in template and the cut-and-paste elements. I know
that this may not be very helpful, but it's all I have to offer.

Jim ... ...
 
Sahil Kapoor
Ranch Hand
Posts: 316
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read "Constraint Satisfaction Problems "

May be that would help...........

I really skip such problems.

Take care
Cheers!!!
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aren't all the questions in the SCJP exam supposed to be answered? Or are a number of questions on the exam that are optional to answer?

I would think this type of question needs to be left till the very end (if there is time, of course!)
 
Sandra Bachan
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just googled "Constraint Satisfaction Problems" and I'm reading up on it. Quite interesting subject....
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

That one was a little TOO puzzle-y. We were trying to sort of emulate a drag and drop question, but none of the real D&D questions are that puzzle-y. So I'd say don't spend too much time on that particular question.

hth,

Bert
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic