Determine the lexicographically smallest array of size N - python-3.x

You are given 4 non-negative integers N, A, B, and C. Determine the lexicographically smallest array of size N such that Bitwise AND of the whole array is A, Bitwise OR of the whole array is B, and Bitwise XOR of t he whole array is C. if no such array exists then print "-1.​" python program

Related

Getting the max of a column based on criteria in another column

I have some data like:
Group
Alpha
Numeric (Sometimes)
1
A
Z
1
B
X
1
C
Y
2
B
Z
2
A
X
2
C
Y
A, B, and C repeat in that not necessarily in that pattern but always in groups together, while the numeric column is often numeric data that varies or text. How can I get the max numeric value for a group for just A and B using a repeatable formula (or a lambda function)? I have tried using vlookup for A and B in the range composing a group and passing the numeric column to MAX() but when the numeric column has text, MAX() and MIN() fail (even though it supposedly ignores text). Any ideas on how to get it to return correctly?

returning highest value with vlookup function

i have this kind of dataset and i have to fill the "tot depth" column taking the highest value from each progressive (col K).
i've tried with ==VLOOKUP(N2,K1:L13841,2,0) but it gives me back the lowest value of the "P1" entry (-0.22).
the result i need would be :
Progressiva Tot depth
P1 -1.15
P2 -1.15
P3 -1.67
If you do not have MINIFS, you might try this in cell O2:
=MIN(INDIRECT("L"&MATCH(N2,K:K,0)&":L"&IF(N3="",COUNTAK:K),MATCH(N3,K:K,0)-1)))
And drag it to the end of the list. It will work as long as:
K column contains only the uninterrupted list of "progressiva" values;
H column contains the uninterrupted complete list of single occurences of "progressiva" value;
both column K and column N are sorted in the same way.

Sigma summation in Excel for accumulated value

how can I use an iterative summation in Excel to compute the accumulated value starting amount (stored in one column) which escalates at 5 % p.a for n years (stored in another column) with the resultant amount then being subjected to a constraint. In essence, the raw function looks like:
where x = starting amount in a column, constraint is 10% of the amount less 80
Also, is my raw function okay to compute the accumulated value with the constraint?
To sum just one year:
Put n in cell A1, put x in cell A2:
=1.05^A1*0.1*A2-80
That will give you the value you're looking for.
To sum all of the years less than (and including) n down to 1:
Put n in cell A1, put x in cell A2:
=SUMPRODUCT(1.05^ROW(INDIRECT("1:"&A1))*(0.1*A2)-80)
Much the same, except that it's wrapped in a SUMPRODUCT() to allow for array formulas and the value given for n will return all positive integers less than (and including) n. The calculation is repeated n times and the result summed.
To sum all years less than (and including) n down to zero
=SUMPRODUCT(1.05^(-1+ROW(INDIRECT("1:"&A1+1)))*(0.1*A2)-80)
Same as answer #2, except it includes zero.

Sum of the elements of the ith row up to jth column of a Pascal's triangle in O(1) time

The sum of the elements of the ith row of Pascal's triangle is 2^n. How can we find the sum of the elements of the ith row up to the jth column of Pascal's triangle in O(1) time?
The solutions that came to my mind is not O(1). The recursive combination function for the nth row of Pascal's triangle. nCk = n-1Ck + n-1Ck-1

Excel: Count of reciprocal pairs in two columns

I have two columns that each contain pairs of individuals.
Individual 1 Individual 2
A B
A C
A D
B A
C A
C D
How would I create a count of the number of times an individual has a reciprocal pair i.e. matched with the same partner but in the opposite order? For this example, the output should be:
A: 2
B: 1
C: 1
D: 0
I think this is quite tricky but here are two suggestions
=SUMPRODUCT(COUNTIFS(A$2:A$7,B$2:B$7,B$2:B$7,A$2:A$7,A$2:A$7,C2))
or
=SUM(((A$2:A$7&B$2:B$7)=TRANSPOSE(B$2:B$7&A$2:A$7))*(A$2:A$7=C2))
The second one has to be entered as an array formula using CtrlShiftEnter and I'm assuming that the A's and B's are in A2:A7 and B2:B7 and you can get a list of the four individuals A, B, C and D in C2:C5.

Resources