Here is a link to the K map: http://tma.main.jp/logic/logic.php?lang=en&type=eq&eq=%28%7EA%7EBC%7ED%29+%2B+%28%7EA%7EBCD%29+%2B+%28%7EAB%7ECD%29+%2B+%28%7EABCD%29+%2B+%28A%7EB%7EC%7ED%29+%2B+%28A%7EB%7ECD%29+%2B+%28A%7EBC%7ED%29+%2B+%28A%7EBCD%29+%2B+%28AB%7EC%7ED%29+%2B+%28AB%7ECD%29+%2B+%28ABC%7ED%29+%2B+%28ABCD%29
I've also attached the screenshot below.
My questions is, if the groups should be large enough, why the highlighted area is not considered but only a subset is considered to get BD instead of D?
Thank you in advance.
The groups should be "large enough" so they cancel a variable X and NOT X out. This only works when a complete X or NOT X is hit by your selection. When you select your six selected cells you will hit the AD area completely, but not the A'D area. This means you cannot cancel them out and get just D as you want to. When you hit the whole AD and A'D area this has the meaning as: "Well, the condition depends on D and is totally unrelated to the value of A."
When written as boolean algebra you get:
AD OR A'D
(A OR A') AND D
( true ) AND D
D
That would be the goal. But since you don't cover the whole A'D area you can't make this simplification here.
To check if you have selected the correct numbers of cell in a selected area, the numbers of cells must be a value of power of 2. So it must be one of 1, 2, 4, 18, 16, ...
In this case you have the regions:
A (2*4=8)
BD (2*2=4)
B'C (2*2=4, notice how the region "wraps" around the edge of the K-map)
Keep in mind that the result for A'B'C'D is false, not true. But when you have just D in your boolean algebra like in A+D+B'C, the result would be true.
I have this picture of a state diagram and have to calculate the value of x after a few events. The events are e1-e2-e2-e2-e2
The x would be 2 in the beginning.
First event is e1, so I think it would become 4 after that event.
Next is e2 and I was wondering because the exit is x=x-1, so would it go to state B, because it is less that 4, or C because it was 4, but became 3 in the exit?
And lets suppose it goes to B, and becomes 5, and we do e2 again. Would nothing happen because the only possibility is x>5 and it is equal to 5?
Assuming that the guard between A and C is x>=4 (since there is no e defined) I made a small transition table:
So the final state should be B and X is 11.
In UML state machines, the guards are evaluated, when beeing in the original state. I.e., when receiving e2 the first time, x is 4 and thus you take the transition to C, unser the assumption that e is x (otherwise it doesnt make sense) . After you decided going to C, and thus leave A, you aubstract 1 from x due to the exit ocndition. When beeing in C, you can change B by trigger of e2, which is unguarded (the guard x>5 belongs to the transition from B to C). Now x is 6, as you add 3 due to the entry condition. Then you receive the next e2 and transide to B, where you add 1, so x is now 7. When receiving the next e2, you check the guard on the transition to C, which demands that x is greater 5, which holds. So lets go to C and execute the entry action once again. So x is now 10. Then you get one more e2, so the state changes to C and its entry action is executed, thus x is 11.
So after the execution of the given events, x is 11 and the statemachine is in state B.
I'm trying to implement movement through four points, while recording which points I visit. Think of it as a square. I can move from corner to corner or diagonally.
If you 'unwrap' the square you get a straight line with four points, which can be thought of as 1-2-3-4- where after 4 it goes back to 1. So if I'm at point 2 I can move to 1 and 3 directly or 4 diagonally. I'd implement that as 2-1 / 2+1 for corner-to-corner or 2+/-2 for diagonally. The problem occurs when I'm at 2 and will try to subtract 2 where I'll end up outside of the list.
The thought I've had is that if I could somehow translate my "out of bounds" numbers to in bounds this would be solved. One solution is hard coding that:
0=4
-1=3
5=1
6=2
but I'm pretty sure there is a better way to do this, however I can't seem to find it.
It seems to me all you want is modular arithmetic (bless the lord for math)
magicFun <- function (x) x %% 4
Here is a simple test run
> magicFun(0:6)
[1] 0 1 2 3 0 1 2
Addendum
It's more about math but the reason it works for negatives is that in Z/nZ ("the world where n is equal to 0") n is "identified" to 0.
This means you can add n as many times as you wish to a given number without changing it's "value".
Also, by convention the numbers in Z/nZ are listed as {0, 1, ..., n-1}.
So suppose n = 4 and x = -6, by the above x = x + 2*4 = 2.
Let's say I have 4 events: A, B, C, and D. All of these events have an independent chance of 25% to occur.
It's possible that only 1 of these 4 events occur : A, B, C, or D.
It's possible that 2 of these 4 events occur at once : (A,B), (A,C), (A,D), (B,C), or (B,D).
It's possible that 3 of these 4 events occur at once : (A,B,C) or (B,C,D)
It's possible that all 4 events occur at once : (A,B,C,D)
I understand that the odds of (A,B) or (A,B,C) happening would be calculated by P(A)*P(B) or P(A)*P(B)*P(C) respectively. But how do you determine the odds of whether you get any one of the pairs of two or any one of the pairs of three?
Is it as simple as saying there are 12 possible outcomes and, for instance, any one pair of two would be 5 of those outcomes so 5/12 = 41.67%? Is this consistent regardless of what A, B, C, and D's individual occurrence chances are?
Your event "any two" is equivalent to:
A and B but neither C nor D
A and C but neither B nor D
A and D but neither B nor C
B and C but neither A nor D
B and D but neither A nor C
C and D but neither A nor B
Each of these events has probability (1/4)(1/4)(3/4)(3/4) = 9/256; there are six of them, so the total probability of any of them is 54/256.
For exactly three happening, we get four distinct events having probability 3/256 each. The overall probability of any of these is 12/256.
The probability of all and none are 1/256 and 81/256, respectively. Each can occur only one way.
Finally, there are four ways for only one of the four events to happen, and each of these outcomes has probability 27/256. The total is this 108/256.
81/256 + 108/256 + 54/256 + 12/256 + 1/256 = 256/256, as expected.
Say we have a set of 3D (integer) coordinates from (0,0,0) to (100,100,100)
We want to visit each possible coordinate (100^3 possible coordinates to visit) without visiting each coordinate more than once.
The sum of the differences between each coordinate in adjacent steps cannot be more than 2 (I don't know if this is possible. If not, then minimized)
for example, the step from (0,2,1) to (2,0,0) has a total difference of 5 because |x1-x2|+|y1-y2|+|z1-z2| = 5
How do we generate such a sequence of coordinates?
for example, to start:
(0,0,0)
(0,0,1)
(0,1,0)
(1,0,0)
(1,0,1)
(0,0,2)
(0,1,1)
(0,2,0)
(1,1,0)
(2,0,0)
(3,0,0)
(2,0,1)
(1,0,2)
(0,0,3)
etc...
Anyone know an algorithm that will generate such a sequence to an arbitrary coordinate (x,y,z) where x=y=z or can prove that it is impossible for such and algorithm to exist? Thanks
Extra credit: Show how to generate such a sequence with x!=y!=z :D
One of the tricks (there are other approaches) is to do it one line [segment] at a time, one plane [square] at a time. Addressing the last part of the question, this approach works, even if the size of the volume visited is not the same in each dimension (ex: a 100 x 6 x 33 block).
In other words:
Start at (0,0,0),
move only on the Z axis till the end of the segment, i.e.
(0,0,1), (0,0,2), (0,0,3), ... (0,0,100),
Then move to the next line, i.e.
(0,1,100)
and come backward on the line, i.e.
(0,1,99), (0,1,98), (0,1,97), ... (0,1,0),
Next to the next line, going "forward"
And repeat till the whole "panel is painted", i.e ending at
... (0,100,99), (0,100,100),
Then move, finally, by 1, on the X axis, i.e.
(1,100,100)
and repeat on the other panel,but on this panel going "upward"
etc.
Essentially, each move is done on a single dimension, by exactly one. It is a bit as if you were "walking" from room to room in a 101 x 101 x 101 building where each room can lead to any room directly next to it on a given axis (i.e. not going joining diagonally).
Implementing this kind of of logic in a programming language is trivial! The only mildly challenging part is to deal with the "back-and-forth", i.e. the fact that sometimes, some of the changes in a given dimension are positive, and sometimes negative).
Edit: (Sid's question about doing the same diagonally):
Yes! that would be quite possible, since the problem states that we can have a [Manhattan] distance of two, which is what is required to go diagonally.
The path would be similar to the one listed above, i.e. doing lines, back-and-forth (only here lines of variable length), then moving to the next "panel", in the third dimension, and repeating, only going "upward" etc.
(0,0,0) (0,0,1)
(0,1,0) first diagonal, only 1 in lengh.
(0,2,0) "turn around"
(0,1,1) (0,0,2) second diagonal: 2 in length
(0,0,3) "turn around"
(0,1,2) (0,2,1) (0,3,0) third diagonal: 3 in length
(0,4,0) turn around
etc.
It is indeed possible to mix-and-match these approaches, both at the level of complete "panel", for example doing one diagonally and the next one horizontally, as well as within a given panel, for example starting diagonally, but when on the top line, proceeding with the horizontal pattern, simply stopping a bit earlier when looping on the "left" side, since part of that side has been handled with the diagonals.
Effectively this allows a rather big (but obviously finite) number of ways to "paint" the whole space. The key thing is to avoid leaving (too many) non painted adjacent area behind, for getting back to them may either bring us to a dead-end or may require a "jump" of more than 2.
Maybe you can generalize Gray Codes, which seem to solve a special case of the problem.
Seems trivial at first but once started, it is tricky! Especially the steps can be 1 or 2.
This is not an answer but more of a demostration of the first 10+ steps for a particular sequence which hopefully can help others to visualise. Sid, please let me know if the following is wrong:
s = No. of steps from the prev corrdinates
c1 = Condition 1 (x = y = z)
c2 = Condition 2 (x!= y!= z)
(x,y,z) s c1 c2
---------------
(0,0,0) * (start)
(0,0,1) 1
(0,1,0) 2
(1,0,0) 2
(1,0,1) 1
(1,1,0) 2
(1,1,1) 1 *
(2,1,1) 1
(2,0,1) 1 *
(2,0,0) 1
(2,1,0) 1 *
(2,2,0) 1
(2,2,1) 1
(2,2,2) 1 *
(2,3,2) 1
(2,3,3) 1
(3,3,3) 1 *
(3,3,1) 2
(3,2,1) 1 *
(3,2,0) 1 *
.
.
.