comparing three cells in openoffice calc. (i'd be happy with 2) - openoffice-calc

I need to do a simple function that is driving me nuts.
I have 3 columns with cells filled as follows.
I2 Y
I3 N
I4 Y
I am looking for every row that has N N N. I'm trying to formulate it so I can do a visual inspection but (baby steps) my first stage is failing. I'm trying
=IF(I2='N';'Y';'N')
In this case the output should be 'Y', Instead I'm getting #VALUE.
Any pointers?

try using double quotes and that should do it
=IF(A1="y";"y";"n")
this works for me

Related

How to set an upper bound over all elements of a set in gams

I have been trying to do the below code, which attempts to set the upper bound of every element of set J to 3.
set J /a1, a2, a3/;
positive variables b(J);
variable obj;
equations cons1, goal;
cons1..
b.up(J) =e= 3;
The rest of the GAMS code just runs the model. However, the generated error statement says "Uncontrolled set entered as constant". I have also tried "b.up(J) = 3;" -- Get the same problem. Does anyone know how to solve this? This problem is similar (How to set upper and lower bounds for each element in a set?), but is actually not my solution.
You can define upper bounds in two ways: Formulating an equation or using the .up suffix. You mixed the two ways which causes problems.
This is the first way, defining an equation:
Equation cons1(J);
cons1(J)..
b(J) =l= 3;
If you use the suffix approach (which is the niceer one), you should not use an equation, just do:
b.up(J) = 3;

root mean square (RMSD) of two datasets

I'm dragging along in python, learning so slow but making progress. Have hit a wall, and don't even know where to start on this.
I have other scripts that get me to where I am now: two output CSV files with multiple rows containing 4 numbers each. The first number is an identifier integer, the other three are X, Y, Z coordinates.
Now the OTHER file is the same thing, with the same set of identifier integers, but a different set of X, Y, Z coordinates.
For each identifier integer, I want to calculate the RMSD between the X,Y,Z. In other words, I think I need to do (X2-X1)^2 + (Y2-Y1)^2 + (Z2-Z1)^2 then take the square root of that. This will give me a float as an output answer, which I'd like to write into an output file of two columns: one with the the identifier integer, and the second is the output from this script.
I actually have no idea where to start on this one.. I've never had to work with two files at once. Gah!
thanks so much!!
sorry I have no script to even start here!

Is there even a slight possibility to process two lists in one single list comprehension line?

I would like to ask if there's a possibility to process more than one list in just a single line with list comprehension? I'm using Python 2.7 .
Here is what the code looks like:
n=[1,2,3,4,5,6,7]
m=[1,7]
c=[]
for x in m:
if x in n:
c.append(x)
n.pop(n.index(x))
print n
print c
The output is:
[2,3,4,5,6]
[1,7]
Now I'm wondering if I could turn the code (line 5 to line 8) into a single line using a list comprehension?
I would appreciate your advice. Let me know if my question has a duplicate. Thank you very much.
You can do it this way since popping a value from the list returns the value
n=[1,2,3,4,5,6,7]
m=[1,7]
c=[n.pop(n.index(x)) for x in m if x in n]
print n
print c
n=[1,2,3,4,5,6,7]
m=[1,7]
print set(n)-set(m)
> [2,3,4,5,6]
Assign the sets to their own variables if you need to perform additional operations. Converting to a set will take some time on a big list but then membership, subtraction, union or intersection operations should be very fast.

Split sample in Stata

I have a variable X containing 3100 values.
I need to split X into variable Y and Z. Y containing 1500 first values of X and Z containing the rest of X.
I'm not sure whether it works with
split X
or any other code
Did you try it?
split is for splitting strings and for splitting them into parts according to their contents.
You appear to want something like separate X, by(_n <= 1500) followed by renaming if you wish. Two generate statements would also work fine.

C++ cοde related to matrix,n*n grid etc

Buttons
Each cell of an N x N grid is either a 0 or a 1. You are given two such N x N grids, the initial grid and the final grid. There is a button against each row and each column of the initial N x N grid. Pressing a row-button toggles the values of all the cells in that row, and pressing a column-button toggles the values of all the cells in that column.
You are required to find the minimum number of button presses required to transform the grid from the initial configuration to the final configuration, and the buttons that must be pressed in order to make this transformation.
When the initial and the final configurations are the same, print "0".
Input
The first line contains t, the number of test cases (about 10). Then t test cases follow.
Each test case has the following form:
The first line contains n, the size of the board (1 ≤ n ≤ 1000).
n lines follow. The ith line contains n space separated integers representing the ith row of the initial grid. Each integer is either a 0 or a 1.
n lines follow, representing the final grid, in the same format as above.
Output
For each test case, output the number of row-button presses, followed by the row buttons that must be pressed. Print the number of column-button presses next, followed by 0-indexed indices of the column buttons that must be pressed. The total number of button presses must be minimized.
Output "-1" if it is impossible to achieve the final configuration from the initial configuration. If there is more than one solution, print any one of them.
Input:
1
3
0 0 0
1 1 0
1 1 0
1 1 0
1 1 1
1 1 1
Output:
1
0
1
2
Though it works absolutely fine on my machine,it doesnt accept a solution at codechef and gives me a wrong answer.Can anyone guide me what to do pls pls pls??
Code has been written in C++ and compiled using g++ compiler.
In the code posted, I would revise the code after you calculate "matrixc". I find it very difficult to follow beyond that point, so I'm going to stop looking at the code and talk about the problem. For those without the code, matrix C = initial matrix - final matrix. The matrices are over the binary field.
In problems like these, look at the symmetries in the solution. There are three symmetries. One is the order of the buttons does not matter. If you take a valid solution and rearrange it, you get another valid solution. Another symmetry is that pressing a button twice is the same as not pressing it at all. The last symmetry is that if you take the complement of a valid solution, you get another valid solution. For example, in a 3x3 grid, if S = { row1, row3, col1 } is a solution, then S' = { row2, col2, col3 } is also a solution.
So all you need to do is find one solution, then exploit the symmetry. Since you only need to find one, just do the easiest thing you can think of. I would just look at column 1 and row 1 to construct the solution, then check the solution against the whole matrix. If this solution gives you more than N buttons to press for an NxN grid, then take the solution's complement and you'll end up with a smaller one.
Symmetry is a very important concept in computer science and it comes up almost everywhere. Understanding the symmetries of this problem is what allows you to solve it without checking every possible solution.
P.S. You say this code is C++, but it is also perfectly valid C if you remove #include <iostream> from the top. It might take a lot less time to compile if you compile it as C.