Hey guys i want to generate repeating sequence in expression transformation in INFORMATICA .
Sequence should like this
1
2
3
4
1
2
3
4
1
Why don't you use a Sequence Generator Transformation?
Related
I came across a question where we are given with a sequence of numbers, and we have to find the number of subsequences with gcd=1.
Eg:
2 3 5 7
count: 11
6 10 15
count: 1
I have solved this question using the top-down approach by the recurrence relation in which we either consider the element or not which goes like -
func(position,current_gcd) = func(position+1,current_gcd) + func(position+1,GCD(curr_gcd,element[position]) ;
Can someone please suggest a tabulation or bottom-up approach for the same..?
I have a file with the structure:
N1H3O1 C2H2
C1H4 H201
C1H1N1 N1H3
C2N1O1P1H3 P5
What I am trying to do is to count the sum of coefficients in each of the formulae. Thus, the desire output is:
1+3+1 5 2+2 4
1+4 5 2+1 3
1+1+1 3 3+1 4
2+1+1+1+3 8 5 5
What I did is a simple replacement of each letter with "+" and then deleting the first " +".
I however would like to know how to do it in a more proper way in sed, using branch and flow operators.
The problem with your input is the 0 which is used instead of O, which might make it difficult to design a regular expression for it, which you can see here:
([^A-Z]+)*([0-9]+)
Other than that, you might be able to capture the numbers by simply adding ([^A-Z]+).
However, you may not wish to do this task with regular expression, since your data except for that 0 is pretty structured, and you could maybe write a script to do so.
Let's say I was comparing two adjacent lines to each other after running sort -u on a file. I find they both match n-characters over from the left side, then begin to disagree at some point, and where the disagreement begins, the first line had a digit "0" to "9". The second line has a non-digit. I want the two lines to swap positions. Why do I want this? Because the digit in the first line meand it is a longer number, and needs to go behind the other, so that these lines, regardless of the digit value, will rearrange from this:
xxxx-xxxx-xxxxxxx.xxxxxxx.xxxx.DD-xx.x.x.x
xxxx-xxxx-xxxxxxx.xxxxxxx.xxxx.D-xx.x.x.x
to this:
xxxx-xxxx-xxxxxxx.xxxxxxx.xxxx.D-xx.x.x.x
xxxx-xxxx-xxxxxxx.xxxxxxx.xxxx.DD-xx.x.x.x
And this:
1
10
11
12
13
14
15
2
3
4
5
6
7
8
9
becomes this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
because it forces numeric values with the same number of digits to be
compared with each other, as those grouped from the left with more digits are moved behind those with fewer digits.
My logic might break down at some point, but until I can code it, I can't check the results returned. So does anybody know how to do this in bash?
sort -g (general numeric sort) should do the trick.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I am trying to solve problem 51 in project euler.
Here is the problem statement : Project Euler Problem 51
I tried the approach given below.
Generate all the prime numbers between 2 and 10 power 8 using Sieve of Eratosthenes
Gather all n-digit numbers from sieve (i.e .. first i will get all 3 digits, then 4 digits .. so on and compute on it)
check if the number has repeated digit (as per problem statement we have 2 *s of same digit) . If yes , convert into string
if yes, find the position where it repeats and save it as a key (for ex: 12341 will result 04 as key since 1 is the number which is repeated in 0 and 4th position)
now based on the key , insert into the bucket (Bucket is a multimap which contains key as repeated position (04) and value as the prime number)
For each key in bucket, delete the repeated position . If am taking 04 bucket key , then all the prime numbers in that bucket would have the strings repeated in the positions 0 and 4. Am deleting 0th and 4th position of the string which would result my number (12341) as 234 and insert it into a map , which will store the occurence as (234, 8 being the trimmed number and number of occurences).
Now, if the key 234 is repeated 8 times, find the numbers which got trimmed and resulted 234. Those are the answers.
I ran this algorithm in c++ , and for 7 primes 56003, 56113, 56333, 56443, 56663, 56773, and 56993 is resulting less than a second ..
but , for 8 digits , i crossed 10 power 8 primes and still it didnt result any answer. I believe answer is above that limit.
And when i try to generate primes between 2 and 10 power 9 its aborting , since i am storing all the numbers in vector.
My question is ,
Is there any way by which we can fine tune the above mentioned steps and find the answer,
or i need to think some other way to find the answer .
Note: Just for an example i took 12341.
There is atleast one issue in your brute force solution. You are assuming exactly 2 digits are * but question never mentions this. There may be 1 or 3 or more digits which when replaced with the same digits 0-9 still generate primes.
It is impossible to have 8 prime with 1 or 2 * for the following reason:
If you use just 1 *, and let's say replace it with 1 to get a prime(let's call this prime p). Now if p % 3 = 1, you can not replace * with 0, 3 and 6 otherwise the number would become composite(divisible by 3). Throwing away 3 candidates makes it impossible to generate another prime. Next case if p % 3 = 2 you can not replace * with 2, 5 and 8 for the same reason. Making 8-primes with one * impossible for any number of digits.
If you use just 2 *, and let's say replace both with 1 to get a prime(let's call this prime p). Now if p % 3 = 2, you can not replace both * with 0, 3 and 6 otherwise the number would become composite(divisible by 3). Throwing away 3 candidates makes it impossible to generate another prime. Next case if p % 3 = 1 you can not replace * with 2, 5 and 8 for the same reason. Making 8-primes with two * impossible for any number of digits.
This is the reason why your code does not give the required output. You should perhaps try with 3 * characters.
Is there a library (in any language) that can search patterns in matrixes like regular expressions work for strings ? Something like regular expresions for matrixes, or any matrix pattern search method ?
If you're not averse to using J, you can find out whether two matrices are equal by using the -: (match) operator. For example:
X =: 4 3 $ i.12
X
0 1 2
3 4 5
6 7 8
9 10 11
Y =: 4 3 $ (1+i.12)
Y
1 2 3
4 5 6
7 8 9
10 11 12
X -: X
1
X -: Y
0
One nice feature of the match operator is that you can use it to compare arrays of arbitrary dimension; if A is a 3x3x4 array and B is a 2x1 array, then A-:B returns 0.
To find out whether a matrix is a submatrix of another matrix, you can use the E: (member of interval) operator like so:
X =: 2 2 $ 1 2 4 5
X
1 2
4 5
Y =: 4 3 $ (1+i.12)
Y
1 2 3
4 5 6
7 8 9
10 11 12
X E. Y
1 0 0
0 0 0
0 0 0
0 0 0
The 1 at the top left of the result signifies that the part of Y that is equal to X has the given pixel as its upper left-hand corner. The reason for this is that there may be several overlapping copies of X embedded in Y, and only flagging the one pixel lets you see the location of every matching tile.
I found two things: gawk and a perl script.
It's a different problem because string regular expressions work (e.g., sed, grep) work line-by-line on one-dimensional strings.
Unless your matrices are one-dimensional (basically vectors), these programs and the algorithms they use won't work.
Good luck!
Just search rows of the pattern in each row of the input matrix using Aho-Corasick (time O(matrix size)). The result should be small enough to quickly join it into the final result.
I don't think there exists anything quite like regular expressions for dimensions higher than 1, but if you want to match an exact pattern instead of a class of patterns then I might suggest you read up on convolution (or rather Cross-correlation )
The reason being, there are many highly optimized library functions (eg. IPP) for doing this faster than you could ever hope to achieve on your own. Also this method scales to higher dimensions as well.
Also, this won't necessarily give you a "match", but rather a "peak" in a correlation map which will correspond to the match if that peak is equal to the sum of squared coefficients of the pattern you are searching for.