So, I'm working on a programming puzzle and need some help to see what I'm missing.
Here is the prompt:
What are the contents of the stack after running the following algorithm?
Given an array and an empty stack:
Push the values of the array onto the stack until a -1 value is found. Do not push the -1.
Pop the values in the stack until an even value is found or the stack is empty. The even value shouldn't be popped.
Repeat steps 1 and 2 until the stack is full or the array is read completely.
Type the contents of the stack from top to bottom, separated by a space, in the Answer box. If the stack is empty, enter a 0.
For this problem, use an array = {10,1, 3, 2, 3, -1, 4, 5, 7}, and a stack size of 6.
I honestly feel like this should be pretty easy but for some reason I'm missing something and continue to get it wrong.
Here is my thought process: (stack from bottom to top)
10 1 3 2 3
10 1 3 2
10 1 3 2 10 1
10 1 3 2 10
10 1 3 2 10 10
Final from top to bottom: 10 10 2 3 1 10
Is there something about stacks that I'm missing?
Any ideas?
Related
write program to read a stack with size 10 then push 6 integer number and if number even put it in another stack and if odd put it in a third stack then print the 3 stack?
write program to read a stack with size 10 then push 6 integer number and if number even put it in another stack and if odd put it in a third stack then print the 3 stack?
//How do I solve it?
For example, when I want to make the leading value of 10 different UI elements match, should I be constraining 9 of them to the first item's leading value, or should I create a chain 1 -> 2 -> 3 -> 4 -> 5 -> 6 ...etc.
I was wondering about the performance differences and whether I should prefer one for maintenance reasons.
It's very difficult to answer an abstract question.
If you want the leading of 10 UI elements to match...
First, you're almost certainly better off putting them in a UIStackView... you constrain the stack view's leading and you're done.
Second, if there is a reason you don't want to (or can't) use a stack view, then the answer depends on what else you might be doing.
Suppose you want element 3 "indented" 40-pts?
If they're all aligned to element 1, you only change the constant of element 3.
If they're "chained" you have to change the constants of elements 3 and 4.
Suppose you want elements 5 through 10 "indented" 40-pts?
If they're all aligned to element 1, you have to change the constants of elements 5, 6, 7, 8, 9 and 10.
If they're "chained" you only change the constant of element 5.
Suppose you want to "insert" an element between 3 and 4? Or remove element 6?
Suppose any of the above - or any number of other possibilities - are "conditional" and factor into the alignment?
As you can see, the preference of one over the other will depend on many things.
So I've been experimenting with CNNs on iOS using the new iOS 10 APIs, and I'm not sure why I'm getting the following results.
So I initialize a plain MPSCNNConvolution class with a weight array of 1.0 and a bias array of 0.0, and kernel width and height of 3. For testing I'm using only a single feature channel. I'm setting the MPSImageEdgeMode to
convolution.edgeMode = .clamp
which, according to the iOS Docs should do the following
Out-of-bound pixels are clamped to the nearest edge pixel.
However, forwarding a texture filled with 1.0s, I get the following result:
4 6 4
6 9 6
4 6 4
which is exactly the same as leaving the edgeMode parameter to its default value .zero - so apparently for the top-left corner (0/0), only the values (0/0), (1/0), (1/1) and (0/1) are considered, and the remaining 5 out-of-bounds values are zero rather then the clamped 1 I expected.
Shouldn't the .clamp parameter result in the following?
9 9 9
9 9 9
9 9 9
Is the expected behaviour, or is there something I'm not considering here?
Thanks!
I am creating a football simulation game and I would like to make a 2D view of match. My match is 90 minutes long and there are 22 players on the field. How could I save a movements/path for players so that it wouldn't take lots of space. I know I could save it something like
Minute: min,
Player: id,
X: xCoord,
Y: yCoord
and then just move objects with jQuery from point A to point B, but I am sure it isn't the best solution, because it would require lots of space and database entries.
I am using MongoDB, but all suggestions are welcome.
How do the players move? They move a little in each step of the main loop? Or they go in long straight lines and then make sudden turns and go in other straight lines? In the first case you would probably need to save each milisecond or so (each step of the main loop), or you could save their positions every ten steps or every second, etc. And the replay could interpolate the saved points (thought the replay would look "gross" like that, it could save a lot of space in your db). In the second case (straight lines), you could just save the points where the players turn in another direction. In this case you'll save their position, angle and speed (along with time, obviously).
The first table could be (the intervals could be more than 1ms, depending on the power of the machine):
PLAYER TIME(ms) X Y
1 0 0 0
1 1 0 2
1 2 0 4
1 3 0 7
1 4 0 10
1 5 4 13
While the second table would be:
PLAYER TIME(ms) X Y Dir Speed
1 0 0 0 90 2
1 2 0 4 90 3
1 4 0 10 60 5
or something like that. Dir is the direction in degrees. Hope that helps!
i'm using a line chart which represent number of players every 5 minutes on our servers and i would like to show a drop in the player count and to present it with coloring the particular sector between the two points where the drop occurred, i didn't find the option to do it,
for example the line of the player count is colored on blue and when the drop is occured i would like to represent only the drop in red so the rest of the line will stay blue.
is it possible? or even just to highlight the specific sector?
There is not a direct way of doing it(highcharts do not provide that kind of customisation yet, maybe they will if you can add a ticket in their website for this particular suggestion and if others vote up, they will consider implementing it). But you can get the result by doing a get around like this :
Instead of plotting everything in a single chart, split it into two :
1. Rise (color 1)
2. Dips (color 2)
See the pic below for more insight :
Where the values would be :
A B C
1 Rise Dip
2 2002 0.273966
3 2003 0.126777
4 2004 0.584197 0.584197
5 2005 0.898247
6 2006 0.560888
7 2007 0.144713
8 2008 0.632703
9 2009 0.604576
10 2010 0.779904
Just split the rise and dips into two different plots and you will get the result you want..
But you need to do some calculations at your end..:)