Spreadsheet filter multiple values (comma sep) - filter

Hi how can I make the "FILTER" function to work if I have multiple parameters separates by comma.
FACTION HERO
A X
B Y
A,B Z
Now if I do a FILTER(B:B; A:A="A") the output will only be X. But Since Z is also in Faction A the output should be X and Z. How can I take care of this?
Wanted output Actual output
X X
Z

Two ways are:
=filter(B:B, regexmatch(A:A, "A"))
=QUERY( A:B , "Select B Where A contains 'A' " )

Related

How to Concatenate two variable in algorithm?

I need to add a statement (contains three words that come from 3 variables) to a file
for example:
Algorithm1
Input X,Y,Z: input words
Output: file:text file
Begin
...\\some operations
...\\some operations
...\\some operations
file<-- X + Y + Z
End
I need a concatenation symbol other than +, which is used for mathematical operations, to concatenate X, Y, and Z and addd them as one statement in a file.

Prolog - adding two arguments, even if one is not a number

in Prolog, how should I proceed when I want to add two arguments, even if one is not a number. So for instance, if I enter add2args(1,2,R). the result should be R = 3. If I enter add2args(1,x,R). the result should be R=1+x.
So far I have this:
add_2args(X,Y,R):- number(X),number(Y), R is (X+Y).
Which allows me to add two numbers, but I don't know how I can get it to print out anything other than true and false if X and Y are not numbers which is normal since number(X) checks if X is a number or not. What other rule do I have to add to get the desired result?
Prolog will view an expression symbolically (as a Prolog term) unless explicitly evaluated with something like is/2. So the simplest way to do this in your case would be the following:
add_2args(X, Y, R) :-
( number(X), number(Y) % Both X and Y are numbers, then...
-> R is X + Y % Evaluate the expression
; R = X + Y % Else, just unify R with the expression
).
The R = X + Y will not evaluate the expression but only unify the term X + Y with R. This is also a nice "Prolog beginner's guide" illustration for the difference between =/2 and is/2. If you wrote, for example, R = 2 + 3, then did a write(R) you would see 2 + 3, not 5. You could subsequently do, Result is R which would then evaluate the expression R and yield Result = 5.
| ?- R = 2 + 3, Result is R.
R = 2+3
Result = 5
yes
| ?-

NiceLabel VBScript - Adding Variables

x and y are always numeric.
x, y, and Quantity are always "1" by default if the user does not change values.
I've set y = 4.
When running the code below, I receive error:
Variable "Quantity" has format Numeric. Value "4+1-1" is invalid for this format"
Dim x, y, z, result
x = EndingLabel.Value
y = BarcodedNumber.Value
z = x & "+" & 1 & "-" & y
result = z
If (z > y) Then
Quantity.Value = result
Else
End If
I'm not certain if the problem is my code or the program I'm writing it in, but it doesn't appear to be calculating the actual equation "4+1-1". What am I doing wrong?
You are assuming that "4+1-1" isn't being seen as a string which it is. I'd suggest putting an "Eval" around it so that it is taken in that form. Change the assignment of z to this:
z = eval(x & "+" & 1 & "-" & y)
If you want another way to consider this. Think of a 2 that in code could be the digit 2, an ASCII character of the digit 2 or something else and thus interpretation is a key point here.

Calculating all possible row combination that satisfies its row constraint in a nonogram

So basicly what I'm asking is the exactly same as what this person asked a year ago: Calculation of all possible mutations of a nonogram which was closed as unclear, though I can't see why it would be.
To recap the exact problem. In nonograms row and columns can be filled in different ways that must satisfy a constriction.
As an example, if a row has the constraint [2,3,2] and length 10, it means 2 adjecent cells must be filled, then a blank, then 3 adjecent, a blank and finally 2 adjecent.
All the possible combinations would then be:
[2,3,2] : x x _ x x x _ x x _
[2,3,2] : x x _ x x x _ _ x x
[2,3,2] : x x _ _ x x x _ x x
[2,3,2] : _ x x _ x x x _ x x
I imagined it would be quite easy creating a general function for calculating all possible combinations for any row length and constraint, but I've been trying this the whole weekend and it's driving me insane! Any help is very much appreciated.
I suggest you think of this as a combinatorial question:
Given the constraint [2,3,2], you basically have to have the following:
xx, _, xxx, _, xx.
The question left is where do you put the rest of your spaces. Since you have 3 sets of xs, you have 4 places to put them. Your example shows putting the only available space after the third set, aster the second, after the first and before the first.
To generalize, work out how many free spaces you have (n = total length - number ofxs - (number of sets - 1) ). Now use combinatorics 101 to figure out all the combinations of putting k identical spaces into n possible places. Once you have the list - you're good to go.

Out of local stack trying to test Fibonacci function in Prolog

I made two different Fibonacci functions, the first one worked perfectly. Then I tried to simplify it in an intuitive way. I thought it would work but for some reason it says ERROR: Out of local stack every time I test it.
Working version:
fibonacci(0,0).
fibonacci(1,1).
fibonacci(N,F) :- N1 is N-1, N2 is N-2, fibonacci(N1,F1), fibonacci(N2,F2), F is F1+F2.
Not working version:
fibonacci(0,0).
fibonacci(1,1).
fibonacci(N,F) :- fibonacci(N-1,F1), fibonacci(N-2,F2), F is F1+F2.
Could someone explain me what is the problem with the second one? Thanks.
Your problem is that in your second one you are recursively calling fibonacci/2 with the term N-1 instead of an integer whose value is N-1.
So, for example if you where calling fibonacci(3, F) it would enter in the third clause and call fibonacci(3-1, F1) instead of fibonacci(2, F1). It would then enter again in the third clause and call fibonacci(3-1-1, F1) and so on.
Note that Prolog uses special operator is to perform arithmetic operations.
The first example is right.
Wouldn't this be simpler? Define fibonnaci\3 such that the first two arguments are the two 'seed' elements (normally 1 and 1, though they can be any two positive integers). The third argument is the computed value of that element of the series.
All you have to do is maintain a sliding window as you recurse along the fibonnaci sequence, thus:
%
% the public interface predicate
%
fibonnaci( A , _ , A ) . % 1. return the first element of the series
fibonnaci( _ , B , B ) . % 2. return the second element of the series
fibonnaci( A , B , C ) :- % 3. all subsequent values are the sum of
fib_body( A , B , C ) . % the preceding two elements in the series.
%
% the 'private' worker predicate
%
fib_body( A , B , X ) :- % 1. first, compute the next element of the series
X is A + B . % as the sum of the preceding two elements.
fib_body( A , B , X ) :- % 2. on backtracking, shift our window
C is A + B , % and recurse down to get the next element
fib_body( B , C , X ) . % in the series.

Resources