Find the regular expressions of the following?Language of odd length and cannot contain length multiple of 3 over ๐šบ={๐’‚,๐’ƒ} [closed] - theory

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.

Related

Solution to make all array elements equal [closed]

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 days ago.
Improve this question
Can you advise the solution for this..
ARRAY EQUALITY
Problem Statement
Amy has an array A, of N integers. She wants to make all the elements of the array equal.
On each day she can select a subarray of A, with length exactly M and perform following operation: ยท
Pick any element of the selected subarray and increase or decrease it by 1. She can perform this operation any number of times she wants (possibly 0), on that day.
Find the minimum number of days required to make all the elements of the array A equal. NOTE: A subarray is the sequence of consecutive elements of the array. You are given T independent test cases.
Constraints
`
All input values are integers.
Input Format First-line contains T.
First line of each test case consists of two space separated integers N and M.
Second line of each test case consists of N space separated integers denoting the array A. Output Format Print in a newline for each test case single integer denoting the minimum number of days required to make all the elements of the array A equal.
Sample Input 1
1
5 3
1 2 2 3 1
Sample Output 1
1
I want to know the aproach to solve this problem?

MATLAB Basics - interpreting parentheses and colons in array manipulation [closed]

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 3 years ago.
Improve this question
What does it mean in MATLAB when I do:
array = array (1:number)
and what does it mean:
array = array(indexes_array)
and finally, what does it mean:
array = array(indexes_array,:)
Answers, according to MATLAB docs:
1)
array = array (1:number)
The colon notation in MATLAB provides an easy way to extract a range of elements from v:
v(3:7) % Extract the third through the seventh elements
ans =
9 4 2 11 7
2)
array = array(indexes_array)
array is reorganized according to indexes_array order, assuming that indexes_array is composed of indexes.
3)
array = array(indexes_array,:)
just the same as number 1), array is reorganized according to all the rows of indexes_array, ignoring the columns.
References:
https://www.mathworks.com/help/matlab/math/array-indexing.html
https://www.mathworks.com/company/newsletters/articles/matrix-indexing-in-matlab.html

Computation theory - DFA [closed]

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.

What is the logic to find out Leonardo number in C programming? [closed]

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.

Find number of k-permutation with ordering but no repetition [closed]

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)!

Resources