I have the following scenario:
if someone is killed in any of the rooms there would be bad smell for the rooms horizontally or vertically next to that room and for that room itself for example if a person is killed in dinning room there would be stench in library dinning and conservatory rooms so
I made four rules like this :
b1: sd => BL or Bd or Bc which gives not Sd or BL or Bd or Bc
andI made four of these rules
Now I want to say this sentenceaccording to the rules that are made above:
the person is not in library:
I startedin this way: not BL => Bk or Bd or Bc which gives BL or Bk or Bd or Bc
but now I am stuck and I can not go any further. I want to say that sentence at the end according to the b1,b2,b3,b4
Can anyone help?
Related
Question
The program is supposed to do the following:
Add up the first 6 data items ($1 to $6) stored at address label DATA.
Store the sum of the first 6 data items to address label SUM1.
Multiply the sum stored at address label SUM1 by 8, and store the result at address label MUL8. (loop then add)
Add up the last 6 data items ($7 to $C) stored at address label DATA.
Store the sum of the last 6 data items to address label SUM2.
Divide the sum stored at address label SUM2 by 4, and store the result at address label DIV4.
How do I do the BSR SUBR, and define the SUBR part of the code?
You can't solve this task without consulting the Programmer's Reference Manual
There's really nothing more to do for the BSR SUBR instruction that already does a 'Branch to Subroutine' (BSR). Defining the SUBR part is just a matter of writing down the instructions that will perform the six steps that were outlined in your task description and then execute a 'Return from Subroutine' (RTS).
To get you on your way, here's a detailed explanation for step 1
Add up the first 6 data items ($1 to $6) stored at address label DATA.
In order to sum up 6 bytes from the array, we can load the first byte in a data register and then add the next 5 bytes from a loop.
Before the loop we:
load an address register like A1 with the address of the DATA label. The movea.l #DATA, a1 instruction does that.
load a data register like D1 with the loop count which is 5. The moveq.l #5, d1 instruction does that. To load small numbers in the range [-128,+127] always prefer moveq over move because it is both faster and has a smaller encoding .
load another data register like D0 with the first byte from the array. The move.b (a1)+, d0 instruction does that. Because this instruction uses the post-increment addressing mode and because the size attribute is byte, the address held in the A1 address register will automatically increment by 1. This way we can step through the array.
In the loop we:
add the next byte to the chosen D0 data register. The add.b (a1)+, d0 instruction does that.
decrement the loop count we have in the D1 data register. The subq.l #1, d1 instruction does that. To subtract small numbers in the range [1,8] always prefer subq over sub/subi because it has a smaller encoding and is much faster then subi.
branch back to the top of the loop only if the decrement on the loop counter did not produce 0. The bne.s loop1 instruction does that.
movea.l #DATA, a1
moveq.l #5, d1
move.b (a1)+, d0
loop1:
add.b (a1)+, d0
subq.l #1, d1
bne.s loop1
I'll throw in the next step since it is rather trivial
Store the sum of the first 6 data items to address label SUM1.
Step 1 left the sum in the D0 data register. Just move it to the SUM1 variable but be sure to use the correct size tag which is .b in accordance with how the SUM1 variable was defined:
move.b d0, SUM1
Good luck with steps 3 to 6...
I am a beginner in Stata and I am trying to create a loop regression, store the coefficients of the DVs and then plot these. Does this code make sense?
forvalues i = 1/100 {
regress y x1 x2 x3 if ID==`i'
matrix b1 = e(x1)
matrix b2 = e(x2)
matrix b3 = e(x3)
}
I am using coefplot right after and it just does not work. Any help will be very highly appreciated.
Does this code make sense? As you say, it does not work.
I see three bugs.
After each regression, the coefficients are not stored in e(x1) and so on. Such references are not illegal, but they just return missing values.
Similarly a command like
matrix b1 = e(x1)
just creates a 1 x 1 matrix with a single missing value.
Each time around the loop you just overwrite the previous matrices. Nothing in the code accumulates results, even if #1 and #2 were what you want.
Hence, a natural question is: where did this code come from?
There are several ways to get coefficients stored from say 100 regressions. See for example statsby and the community-contributed rangestat (SSC).
I've got a string with eight characters in it, e.g. abcdefgh. I need to generate all possible 10-character combinations of this string.
For example, all 2-character combinations of this string would be ab bc cd ef gh ac ad ae af ah, etc.
I thought of doing something like this but I couldn't figure out how to get it working.
What should I do? Is there a simple algorithm I'm missing?
You can use 2 pointers, one on the letter t the start of your string, who is incremented a each time you are on '/0' and the second who is simply incremented on each turn of your loop with a condition fo you don't rewrite an older combination.
aa ab ac ... bb bc ...
Edit :
No need condition, only the reset of your second pointer have to be 1 on the first pointer
I looked in Decomposing a relation into BCNF answers and tried it on my homework, but i don't get the correct answers, so i ask for help in BCNF decomposition
Consider R=(ABCDEG) & F={BG->CD, G->A, CD->AE, C->AG, A->D}.
I start pick A->D.
Now i got S=(AD), R'=(ABCEG).
I pick G->A.
Now i got S=(AD,AG) R'=(BCEG).
I pick C->G.
Now i think i need to get S=(AD,AG,CG) and R'=(BCE), But the answer in the end is (AD,AG,CGE,BC) .what went wrong? or perhaps, a better algorithm?
To convert a relation R and a set of functional dependencies(FD's) into 3NF you can use Bernstein's Synthesis. To apply Bernstein's Synthesis -
First we make sure the given set of FD's is a minimal cover
Second we take each FD and make it its own sub-schema.
Third we try to combine those sub-schemas
For example in your case:
R = {A,B,C,D,E,G}
FD's = {BG->CD,G->A,CD->AE,C->AG,A->D}
First we check whether the FD's is a minimal cover (singleton right-hand side , no extraneous left-hand side attribute, no redundant FD)
Singleton RHS: So we can write our FD's as { BG->C, BG->D, G->A, CD->A, CD->E, C->A, C->G, A->D}.
No extraneous LHS attribute: We can remove D from LHS of CD->A and CD->E since D is an extraneous attribute here (As we can get D from C since C->A and A->D). So we now have {BG->C, BG->D, G->A, C->A, C->E, C->G, A->D}
No redundant FD's: We note that there are a lot of redundant dependencies here. Removing them we have {BG->C, G->A, C->E, C->G, A->D}
Second we make each FD its own sub-schema. So now we have - (the keys for each relation are in bold)
R1={B,G,C}
R2={G,A}
R3={C,E}
R4={C,G}
R5={A,D}
Third we see if any of the sub-schemas can be combined. We see that R3 and R4 can be combined as they have the same key. So now we have -
S1 = {B,G,C}
S2 = {A,G}
S3 = {C,E,G}
S4 = {A,D}
This is in 3NF. Now to check for BCNF we check if any of these relations (S1,S2,S3,S4) violate the conditions of BCNF (i.e. for every functional dependency X->Y the left hand side (X) has to be a superkey) . In this case none of these violate BCNF and hence it is also decomposed to BCNF.
Note My final answer above is (AD,AG,CGE,BCG). The solution you expect is (AD,AG,CGE,BC) but that's wrong. The last relation here (S1) should also have the G attribute as shown above.
Give input: A relation R0 with set (Minimal) of FD's S0.
Output : A decomposition of R into a collection of relations, all of which are in BCNF
Algo:
R <- R0, and S <- S0
Repeat till R is in BCNF.
If there is a FD X -> Y that violates BCNF condition.
Compute {X}+ , and choose {X}+ as one relation as R1, and
another R2 as {(R - X + ) U X}
Map FD set S on R1 and R2 (determine FDs on R1 and R2).
Recursively repeat the algo on R1 and R2.
Rule:
1.Should be attribute preserving.
2.Should be lossless
3.Should be FD preserving
Example:
R(xyz) FD xy -> z; key : xy
z-> y;
Solve:
z-> y violet the BCNF condition.
So decompose relation R
{z}+= yz;
R1(yz) where key is z
and R2(xz) key is x
I have a web service response that provides me a block of data (in a long string), which I split into separate elements using the hard return as the separator. This gives me several sentences or elements (indexes I think), and each one has several data values within each element. For example:
//Gets data from web service response<br>
Def longstring =
"0 * 549 F7 G8 H9
1 2247 F6 G4 H10
17JUN DFWPHX F7
M7 B2 Y1"
//Splits the above into separate sentences/elements
longstring.split("\\r?\\n")
String[] Element=longstring.split("\\r?\\n")
//Print out of elements<br>
Log.info Element[1] = "0 * 549 F7 G8 H9"
Log.info Element[2] = "1 2247 F6 G4 H10"
Log.info Element [3] = "17JUN DFWPHX F7"
Log.info Element[4]= " M7 B2 Y1"
I have written a block of groovy code, which when provided the element ID, the code will try and drill down to get only a certain value within that element. For example, If Element[1], starts with "0" then do "x" thing, else do "y" thing. I need to be able to loop through all the elements (or indexes) with this same code until I come away with the information I need, then exit the iteration/loop once that data has been found.
I am not a groovy expert. I've seen the google results for maps, loops, and different operators. None of them make sense with my scenario. The text in each element is not a list. Mapping and looping seem to require a different set up than what I have. If you can help me solve this, please explain the code in simple terms if possible. Thanks in advance for your time and expertise.
It's a bit hard to understand your need here, but I will give it a try.
Assuming you want some piece of code to be executed based on the pattern of a line. I have an example here for you that tries do achieve this:
//Here I define 2 action closures - what I want to happen
def whenZero = { line ->
println "The line '$line' starts with a zero"
}
def whenOne = {line ->
println "The line '$line' starts with a one"
}
//Then I declare patterns and map them to each of the actions
Map methodMap = ['0.*':whenZero, '1.*':whenOne]
//This method will do the matching of the pattern and call any action
def executeBasedOnKey(Map map, String line){
map.each{ key, method ->
if (line.matches(key)) method(line)
}
}
//Your input
def longstring ="""0 * 549 F7 G8 H9
1 2247 F6 G4 H10
17JUN DFWPHX F7
M7 B2 Y1"""
//This line calls the evaluation for each of the lines
longstring.split("\\r?\\n").each{line->
executeBasedOnKey(methodMap, line)
}
This is the solution that worked for me. I labeled it based upon how I was told it was designed
//String that needs to be split
def longString ="""0 * 549 F7 G8 H9
1 2247 F6 G4 H10
17JUN DFWPHX F7
M7 B2 Y1"""
//Splits the entire string response above into substrings based upon hard returns ("S" becomes the new chopped up strings)
longString.split("\\r?\\n")
String[] S=longString.split("\\r?\\n")
//Creates the variable foundData for the loop to use below
String foundData;
//Creates "subS" variable for all the elements seen in the array "S" from above
for(String subS: S)
{
//Creates a matcher pattern to look in each subelement (subS) where it looks for a regex pattern.
//Description of the regex used: /\d\s+(\d+).*/ = one digit followed by one or more spaces, followed by another one or more digits
//Note that the regex above includes: (\d+). This creates a "group" within the pattern, which is referred to below in the DataMatcher
def DataMatcher = (subS =~ /\d\s+(\d+).*/);
//If the subelement (subS) matches the above pattern, it goes into the below block of code
if (DataMatcher.matches())
{ //Sets the variable foundData (see above) to value of the DataMatcher and only grabs the data needed
//Note that the flightMatcher has two sections [0] and [1]. These represent the following:
//[0] = The entire string should be looked at
//[1] = Only group 1 in that string should be retrieved *See group created (in comments) in the regex portion above
foundData = DataMatcher[0][1];
//This breaks the loop once the Data needed has been matched
break;
}
}
//Displays the foundData needed
log.info foundData