03-23-2022 02:32 PM
I thought that the SRs would ONLY be re-initialized when the VI was stopped and then re-started, not when the LOOP goes through the iterations. The values I saw in between the outer loop & inner loop SRs were: 0,1,2; 2,0,1;& 1,2,0. What I saw feeding the top of the outer SR (or the indicator) was 2, then 1, then 3 the final answer.......
I think I am more confused now than ever! 🙂
VI attached!
G
03-23-2022 03:20 PM
The inner loop is indeed stopped (after it runs 2 times) and re-started (the next iteration of the outer loop).
Blog for (mostly LabVIEW) programmers: Tips And Tricks
03-23-2022 03:44 PM - edited 03-23-2022 03:53 PM
@LvTech wrote:
Hi,
I am taking multiple practice tests in preparation for the CLAD. My weak spot seems to be questions where you need to say what the output of a loop within a loop will be. For the below example, is there a way to approach this problem without going through each iteration in my head & trying to keep track of the values that will be in each of these stacked shift registers after every iteration? Gets very confusing because not allowed to have paper and pencil to note things during the exam. I am creating these examples in LabVIEW and stepping through hem to follow the data flow, but wondering if there is a "faster" way to get to the solution. The choices given as possible answers in this example are: 0, 1, 2, or 3.
Thanks for the help!
George
What is the value in Numeric Value Out after the following has executed?
![]()
OK let's go through quick. The SR elements are N-0, N-1 and N-2 initialized to 0,1,2 on i 0,i 0
The inner loop runs once incrementing N -2 and placing the result in the SR for a 3,0,1 and again 1+1 = 2,3,0. The 2 is stuck back to the OUTER SR so iteration 2 starts with 2,1,0 and the inner loop SR is reinitialized to that. Running the inner loop leaves 1,2,2 and the 1 is place back for i3 of 1,2,1. And we reinit the inner loop again
So two iterations later the SR 0th element will be (drum roll) N-1 incremented of course or 3
And yes, it's probably the strangest way to increment element n-1 ever.
03-23-2022 07:24 PM
I think the answer to things like these is like you'd do with an algebra equation: Simplify until it looks like something you can handle.
Start by looking at the middle loop. Since it iterates a fixed amount of times, the output can be replaced by a fixed set of math done on its input. In this case, it always just outputs the middle value of its 3 inputs with a +1 to its value. So you simplify that down to do just that:
After that, it's pretty easy to see that a lot of wires and nodes can be removed as they contribute nothing. The bottom shift register on the left and everything connected to it, plus the wire on the top shift register on the left, and the structure are all no-ops. Remove them and it looks like this:
From here it's not too hard to work out the values in your head since there's now far fewer to keep track of, and hopefully you can figure out what's happening. It basically simplifies to this:
But since the effort to simplify that is probably equal to the effort to just mentally iterate the 3 loops, there's not a huge need to bother and stopping at the step before and just answering is probably best.
03-31-2022 08:31 AM
Announcing a Kudos bounty for finding the moot error in my solution.
03-31-2022 09:38 AM
Ok, I'll play along. When I read your msg before, a couple details didn't match my notes, but they were things that didn't propagate forward to affect the final answer. I figured it was just a typo-level mistake, ignored it, and kudo'ed the answer anyway. I just went back through it again to check, here's what I had different:
The inner loop runs once incrementing N -2 and placing the result in the SR for a 3,0,1 and again 1+1 = 2,3,0. The 2 is stuck back to the OUTER SR so iteration 2 starts with 2,1,0 and the inner loop SR is reinitialized to that.
I have iteration 2 of the outer loop starting 2,0,1. This naturally leads to the other diff...
Running the inner loop leaves 1,2,2 and the 1 is place back for i3 of 1,2,1
I have i3 of the outer loop starting at 1,2,0.
But the element in dispute has no influence on the final answer of 3 anyway.
-Kevin P
03-31-2022 09:53 AM
Thanks Kevin
It was a typo and moot but after the solution got marked I wanted to have it addressed.
03-31-2022 11:14 AM
I must say, I especially liked the way Kyle97330 broke it down in msg #14. A really nice bit of analytic thinking -- I consider him the real winner of this thread!
-Kevin P
03-31-2022 12:22 PM
@Kevin_Price wrote:
I must say, I especially liked the way Kyle97330 broke it down in msg #14. A really nice bit of analytic thinking -- I consider him the real winner of this thread!
-Kevin P
Regardless of how silly the puzzle is or how it is solved the examinees must know two things
So it's a fair puzzle since, with the values shown, either or both mistakes yield the other 3 distractors. It does the job of testing the knowledge. It should trigger a whole lot of derogatory laughter in a code review.