Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
I'm trying to calculate AB+C (A, B and C being boolean values) but I only have the values ABC and C. I can negate, OR, and AND to my heart's content, but I am only getting ABC and C out of the system.
Specifically there is a service that has two boolean state variables. One is a combination of three internal properties and is only true when all three are true, but one of the three state properties is also available. I'm just trying to figure out if I can calculate the value I want without asking for them to add A and B as separate values.
AB is A and B
A + B is A or B
I don't think you can compute AB+C in any case knowing only the value of C and ABC:
If C is true, AB+C is true
If C is false, ABC is false and you can't find out anything about AB.
Old Answer - which is wrong as stated in the comments:
I'll give it a try. You can construct not(not(ABC)+C)+C:
not(not(ABC)+C)+C = not(not(A)+not(B)+not(C)+C))+C
= not(not(A)+not(B))+C
= AB+C
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
H = H === nothing ? h : [H h]
#both matrices
The matrix H is being assigned a value based on a ternary operator, which takes the form a ? b : c. In this case, if H is nothing, it will made the same as h. Otherwise, it will be concatenated with h (as with hcat).
Note: When H === nothing, the code does not assign H the values of h, as has been suggested. Instead, H is a copy of h. For instance, if you change one of the elements in H, it will change an element in h, since they are the same matrix.
It may help to look at the documentation for arrays.
Suppose
H === nothing
evaluates to true, then H is assigned the value of h. If false, then H is assigned to a 1x2 matrix which has H as its first value and h as its second value.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
Is there an R function that assigns variables bidirectionally? For example, let <-> represent a bidirectional assignment operator.
a <-> b
a
> b
b
> a
One can define something like:
`%<->%` <- function(x,y){
t <- y
assign(deparse(substitute(y)), x, envir=parent.frame())
assign(deparse(substitute(x)), t, envir=parent.frame())
}
a <- 1
b <- 2
a %<->% b
a
[1] 2
b
[1] 1
Such an operator would not make sense with the way R functions:
From Hadley Wickham's book Advanced R, section "Binding basics":
Consider this code:
x <- c(1, 2, 3)
[...] this code is doing two things:
It’s creating an object, a vector of values, c(1, 2, 3).
And it’s binding that object to a name, x.
So, for instance, when you run:
a <- 1
you are creating a numerical vector with one element and you are binding it to the name a.
a <-> b
would be binding names to one another, which makes no sense in R.
Also note than when you do:
a <- 1
b <- a
b
# [1] 1
You get 1 as the output, not a, because you create another binding (b) to the numerical vector with the value 1. And when you run b, the output is the object binding to it (1), not another name this object is binding to.
Note: Hadley explains all this very clearly with diagrams in his book.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 7 years ago.
Improve this question
i saw this picture over social network
put into equation that will be:
Given:
A=rabit
B=Dog
C=Cat
A+C=10
A+B=20
C+B=24
solve A+B+C = ?
some programming logic? what is your answer?
I do not see any programming logic in this, its just Math.
B + C = 24
-A-C = -20
Adding these two,
B-A = 4
Now taking the 1st equation,
A+B = 10
-A+B = 4
Adding both again
2B= 14
B = 7
Then, A = 3 ( from A+B = 10) and C = 17kgs (from B + C = 24)
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In R, I would like to create a function that returns the smallest n such that the n-th repetition of the natural logarithm gives a value smaller than one. Ex.: fun(9182) = 3 because ln(ln(ln(9182))) = 0,793 < 1.
Any suggestions will be appreciated!
logstar<-function(x){if (x<1) 0 else 1 + logstar(log(x))}
#mrip's answer works well for single values. If you'd like a function that works for vectors, you'll want to use ifelse() rather than if:
> logstar <- function(x){ifelse(x<1,0,1 + logstar(ifelse(x<1,x,log(x))))}
> x = c(0.5,1,100,10000,1E8)
> logstar(x)
[1] 0 1 3 3 4
The ifelse() in the recursive call to logstar() prevents log() from generating NaN in some cases.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
Given N = A%B, how to find the value of A%C , where B > C.
You are given value of N and C, but not of A.
Is there any way to find this?
Nope. Consider the following:
A = 19
B = 10
C = 7
==> Given 9, you should get 5.
A = 29
B = 10
C = 7
==> Given 9, you should get 1.
So given the same input, there may be multiple answers.
The modulo operation is one-way: given a mod b = n, all I can say is that a comes from the set of all other integers which, modulo b, equal n.
Let's demonstrate that this is impossible in general, taking B=3, C=2.
n = a mod 3 = 1
=> a is in the set of integers {3x + 1}
so consider, x=1
4 mod 3 = 1, so that works
4 mod 2 = 0
now consider x=2
7 mod 3 = 1, so we can't distinguish 4 from 7 knowing only n and b
7 mod 2 = 1
That is, given b=3 and n=1, you'd have to get two different answers without knowing a.
However, you may consider it's a special case that b and c here are coprime, and in fact are both prime. You can certainly solve this easily for some cases, such as b=4 and c=2.
BTW, further discussion on this is probably better suited to mathoverflow