Help Solving a Logic Puzzle

Associate
Joined
20 Sep 2003
Posts
2,384
Location
Scotland
Hi All,

I am looking for some help with a logic puzzle I was presented with at a recent coding challenge. I was given 10 minutes to read and solve the puzzle and I cannot see how it should work out and relate to the flow chart on the left. Can any fellow programers tell me how you would attach the puzzle and what the answer is?

I cannot understand how any of the suggested answers are possible and how I should relate my answers to the flow diagram provided. I would appreciate any help with it.

https://imgur.com/a/qMQ425z#eNvAESc


Thanks
 
I assume when it says put number in box, you add it to the existing number in that box, at a quick glance
 
Well this is the thing. I am not sure, I initially thought it meant put the number into the box i.e. divide the existing number in the box by the new number. But I think it means replace the existing number in the box by the new number.

It could mean many things, so thats what I have stuck it out there for other folks opinion as I am totally confused. I failed this part of the challenge but passed the actually coding piece.
 
Following the loop I get to 55 but I guess you're being expected to figure out a short cut

Edit - I was completely replacing the numbers
 
Following the loop I get to 55 but I guess you're being expected to figure out a short cut

Edit - I was completely replacing the numbers

Anyway you could explain or detail how you got that answer?...... it was more about the thinking of how you get to the answer than the actual answer.

Would appreciate that, thanks :)
 
I assume it means replaced
you continue the loop until you are at 64 in box 7.then you progress ot final stage and take 9 away from it, to give an answer of 55?

each loop cycle adds 2 to box 4, meaning it goes 1 3 then 5, which equals the value in box 9 allowing progressing

each loop cycle changes the value of the square
 
Anyway you could explain or detail how you got that answer?...... it was more about the thinking of how you get to the answer than the actual answer.

Would appreciate that, thanks :)

Literally just followed the steps in the flow chart
 
As others have said - each box/variable starts with the values in the table at the top.
each "command" replaces the existing value with a new one.

it starts by 1 + 0 -> box4 = 1

now there's a loop with the check is box4 (which starts as 1, from the previous command) = 5

the loop incriments box4 by box1 each time, which is 2. So, this loop runs around 3 times until it equals 5. (1, 3, 5)

Box7 increases each loop as ^2-1 (with the -1 being after the check)
So, at each check box7= 4, then 9, then 64

It's now left the loop, so box3+box9 -> box10 (4+5=9)

finally box7-box10 -> box11 (64-9 = 55)

I hope that makes sense.
 
each loop cycle adds 2 to box 4, meaning it goes 1 3 then 5, which equals the value in box 9 allowing progressing

each loop cycle changes the value of the square
This is presumably the point of the puzzle from a programming perspective.

Identify from the logic sequence which boxes would be fixed variables (some never change) and which are truly variable, then identify how the sequence progresses and how to tell when one of the changing figures will meet a fixed figure and subsequently how that affects the other boxes along the way.

Or whether you do what my non programming brain did and just iterate your way through to the answer by following the instructions over and over again :p
 
^ I think I would be the same.

it starts seeminly complex with 12 variables. But by scanning throught he flowchart it's easy to see that only 4 "boxes" have anything changing (4, 7, 10 and 11). So they are the only actual variables - the remaining boxes can be substituted for their values from then on.

int box4=4
int box7=2
int box10=19
int box11=1

box4=1+0
box7=box7^2
if (box4=5)
{box10=4+5
box11=box7-box10}
else
{box4=box4+2
box7=box7-1
box7=box7^2}

It's been years since I've done any programming, so the formatting/definitions might be wrong, but I hope it makes sense. I'm also sure it can be refined better, to prevent using the box7=box7^2 inside and outside the loop.
 
Thanks for all the answers folks, really appreciate the breakdown of the puzzle. I must admit I still find it hard to get my head around so I will take this away and have a look at it in more detail.

To give this some more context I was applying to a code training academy and my code was legit but they hit with this puzzle at the end. I have literally only started JS programming so I a personally feel this was a little tricky to be given in an interview situation and given 10 minutes to solve.

From your guys experience would you say the puzzle is aimed at a total beginner or an intermediate style programmer?....... I feel hard done by as my actual code was ok but I was rejected based on this puzzle.
 
Just write out buckets 1 to 12 on one line on a bit of paper and then fill in the numbers on the line below as you go - if you need to update one then put a line through and write the updated number on the line below.

You could literally just do it by following the instructions a step at a time in less than 10 minutes.

Though once you've done one loop then you know what the update is going to be; box 4 = box4 + 2 and box 7 = (box7 - 1)^2
and the condition for entering that loop - so might as well just do the updates at once and go to the last steps for the answer. :)
 
Well you should be able to reach the answer of 55 in a couple of minutes with zero programming knowledge, it's just following instructions.

At a guess they're using it as a test to see if you approach it from a programming thought process or not - as per above, identifying the loop etc. I can't imagine they're expecting you to write code for it in 10 minutes but at least to have spotted what Destination posted above - that the check box increases by 2 each loop and another box being modified alongside changes as squared numbers... and then that knowing that, you could presumably write some fairly tidy code that wouldn't necessarily need to iterate it's way through the loop to find the answer.
 
the test looks like it is trying to illustrate out of order instruction execution when dependencies have been established, by a compiler say -
step 6, using box 3&9 could have been executed anywhere in sequence too, seems bizarre to have included it.

edit: I guess that they want you to assert initial state is stable itself
 
I was able to identify that the flow chart had an endless loop unless the program was able to move past stage 3. I guess you need to have a logical thinking brain or programming approach to situations. I thought I would be able to learn how to program and then the course would then help me understand how to think like a programmer.

I am able to reapply in 6 months but if I cannot get past this stage then I feel I am not cut out to be a programer. Is this something I can learn or should I give up now?

To give more background to this I have been a Business Analyst for the past 10 years and have unfortunately been out of work for the past 8 months but I thought I would try and transition to a developer. I feel I am more of a geek than a people person with great communication skills which is a key part of being a BA.

Anyway I appreciate your guys input.

I have been working through some coding tutorials and have been messing around with ideas http://cruitme.com/javascript/
 
It's a little dated now, but if you want to learn how to think like a programmer then check out the online version of CS106A from Stanford: https://see.stanford.edu/Course/CS106A

Or if that's too much, then there's quite a few games out there nowadays that will teach you to solve problems with coding style logic. Swift Playgrounds is great if you have an iPad, or Human Resource Machine (multi-platform) is also good.
 
Back
Top Bottom