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 years ago.
Improve this question
i want to design a DFA of an alphabet {x,y,z} which accepts words with a number of 'z' multiples of 3 (eg "xzyyxzzyy")
Does anybody knows how? or which is the language that accepts it?
You will need three states to keep track of the number of z's seen, modulo three; the states will cycle through each other on input z, and the one for #z(w) = 0 (mod 3) will be the only accepting state.
To allow any arbitrary x's and y's, each state can loop to itself on these inputs.
You might use q0, q1 and q2 for the states, making q0 the initial state and only accepting state. Then, you have three transitions f(qi, z) = wh where j = i + 1 (mod 3), three transitions f(q, x) = q and three transitions f(q, y) = q for a total of nine transitions.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Language of odd length and cannot contain length multiple of 3 over
𝚺={𝒂,𝒃}
OK to have an odd length that's not a multiple of 3, we can have a "head" part that generates strings of length 6n, and then a "tail" part that generates strings of length 1 and 5 (but not 7). Any odd number that's not a multiple of 3 can be written as 6n + 1 or 6n + 5 for n >= 0. So, let's get crackin.
r = ((a + b)^6)*((a + b) + (a + b)^5)
I have used a shorthand notation here which you can omit; basically, s ^ n stands for the regular expression s repeated n times. As long as n is a definite number this can be written out, just makes the regular expression a little longer.
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 years ago.
Improve this question
Leonardo number
L(x)= {
1 if x=0
1 if x=1
L(x-1)+L(x-2)+1 if x>1
}
If x>1, what logic can I apply to find out the Leonardo number?
In your function L(int x)
If x is 0 or 1
return 1;
If x is greater than 1
return L(x-1) + L(x-2) + 1;
What I am doing using L(x - 1) is calling the function for the value x - 1 and the value will be evaluated directly as 1 if it is 0 or 1, otherwise it call again for (x - 1) - 1 i.e. x - 2 and the process repeats.
Same is the case for calling L(x - 2).
This is the logic, without the entire code.
For more information on this kind of logic, try searching for Recursion.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I have 2 arrays of strings as under. I want to compare them and execute some code if these arrays are not equal-
current_instances = ["170601_7711", "170601_8811"]
app_instances = ["170602_7711", "170602_8811"]
How can I compare them in ruby?
x = ["alpha1", "beta1"]
y = ["alpha2", "beta2"]
Check if all elements are the same
x == y #=> false
Compare each element
Compare each string at some index i, assuming both arrays are the same size. Then apply some code to the matches.
x.zip(y) #=> [["alpha1", "alpha2"], ["beta1", "beta2"]]
x.zip(y).map {|a,b| a == b ? 'do this' : 'else do this' }
#=> ["else do this", "else do this"]
Perhaps you can do an array difference with the - operator and execute your code if the difference is zero
arr_diff = current_instances - app_instances
This is the simplest solution I could think of :)
Check my solution and let me know how it goes
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 7 years ago.
Improve this question
I try vectorizing a 'for loop' for array but it does not work to me.
My 'for loop' is
for k = 1:N
R(n,n,k) = R(n,n,k) - SE3(k,k);
end
and vectorize it
diagSE3 = diag(SE3);
R(n,n,1:N) = R(n,n,1:N) - diagSE3(1:N);
With
R(n,n,1:N) = R(n,n,1:N) - diagSE3(1:N)
you try to subtract a vector (N x 1) from a 3-dimensional array with dimensions 1 x 1 x N. This can be repaired using squeeze:
R(n,n,1:N) = squeeze(R(n,n,1:N)) - diagSE3(1:N)
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Im truggling to find a closed form for the number of k-permutations of a set S of cardinality n.
The combinations should regard ordering, but no repitions.
Example:
|S| = n = 3
S = {a,b,c}
k = 2
{a,b}
{b,a}
{b,c}
{c,b}
{a,c}
{c,a}
Anyone could help me out how to compute the number of viable permutations (and not the permutations itself)?
What I've tried:
I've read through different material and found out, that including repitititions it is
O(n) = n^k
My initial though was, that I need to eliminiate the permutations like
{a,a}
{b,b}
{c,c}
But I struggle finding a closed form for the number of perceivable repititions.
You are looking for the number of k-permutations of a set S of cardinality n.
The formulae is well known : n!/(n-k)!
Pseudo-proof :
for the 1st element, you are able to choose among the n elements of S ;
for the 2nd, only among : n-1, because you don't want doublons ;
...
for the ith, only among : n-(i-1) ;
...
for the kth, only among : n-(k-1) ;
So, finally :
n * (n-1) * ... * (n-i) * ... * (n-k+1)
= n! / (n-k)!