simplyfing common data values (parts of a string) in an array – by merging same attributes (data values)

I have arrays comprised of string elements like the following 2 examples. Each of the following lines is a string element of the array.

example1:

aaa bbb cc1 dd1  aaa bbb cc1 dd2  aaa bbb cc2 dd1  aaa bbb cc2 dd2  aaa bbb cc3 dd1  aaa bbb cc3 dd2  

example2:

bbb rrr nnn ttt ooo eee ddd fff contr  bbb sss nnn ttt ppp eee contr  bbb sss nnn aaa ooo eee ddd fff contr  bbb rrr nnn ttt yyy eee ddd fff contr  

I want to simplify and remove "redundant" lines by merging in a single line duplicate attributes. So the results should be:

example1:

aaa bbb cc1 dd1/dd2 aaa bbb cc2 dd1/dd2 aaa bbb cc3 dd1/dd2 

example2:

bbb rrr nnn ttt ooo/yyy eee ddd fff contr  bbb sss nnn ttt ppp eee contr  bbb sss nnn aaa ooo eee ddd fff contr  

(the results are an array as well).

My current approach goes like this: remove the first column then compare all elements. if equal lines are found, merge them. remove second column, compare. It becomes though somewhat complicated, as not all lines have the same number of data values (separated by spaces).

I’m stuck here. Any help would be welcome.

FileStream DB SQL Server – merging DB data

We recently upgraded a server from 2014 to 2017. Since down time was a concern, we migrated some DB’s a couple days before.

Migration complete Sunday afternoon, we’ve now come to find out the Filestream DB was used between restore and cutover. So we have a datagap to mitigate. I restored the old DB to a backup server, and did a basic ‘not in’ to find 12 documents in the old DB.

Finally, the question: how do we get those 12 documents into the current DB? Is it as simple as an insert from old to new?

If it helps, this query is what shows the 12 record gap:

SELECT *  INTO #tmpFileStore FROM OPENQUERY (OldDBSever_LinkedServer, 'SELECT * FROM [FSDB].[dbo].[DocumentFileStore]');  SELECT stream_id   FROM #tmpFileStore   WHERE stream_id not in (Select [stream_id] FROM [dbo].[DocumentFileStore]) GO 

Merging 4 tables that also include Union All

I have this code WHICH IS JOIN OF 3 TABLES,    SELECT   [Provider] AS Publisher ,[Price_Rate] ,[Source_ID] ,Media.Date ,Media.Impressions ,Media.Clicks ,'0' AS [Opt-buyers] ,'0' AS [Completed buyers] ,Media.accounting FROM [dbo].[budget]  AS BUDGET  LEFT JOIN  (    SELECT CASE WHEN [Ad_Set_Name] LIKE 'tw_%'    THEN'twitter'    WHEN [Ad_Set_Name] LIKE 'IN_%'   THEN 'insta'    ELSE '?'       END AS Publisher   ,CAST([Day] AS Date) AS Date   ,SUM(CAST([Impressions] AS INT)) AS Impressions   ,SUM(CAST([Link_Clicks] AS INT)) AS Clicks   ,SUM(CAST([Amount_Spent__USD_] AS money)) AS Spend   FROM [dbo].[twitter]   Group by Day,[Ad_Set_Name]     UNION ALL      SELECT CASE WHEN [Site__PCM_] = 'acuits.com'     THEN 'acqt'      WHEN [Site__PCM_]= 'PulsePoint'      THEN 'plpt'     WHEN [Site__PCM_] = 'SRAX'     THEN 'srax'     ELSE [Site__PCM_]     END AS Publisher     ,CAST(Date AS Date) AS Date     ,SUM(CAST(impressions AS INT)) AS Impressions      ,SUM(CAST(clicks AS INT)) AS Clicks     ,SUM(CAST(media_cost AS money)) AS Spend    FROM [dbo] [pcm]    Group by [Site__PCM_]   ,Date   ) AS new_sources_budget  ON BUDGET.Source_ID = Media.Publisher   WHERE source_id IS NOT NULL    and I'm trying to join another table **called Email** to what's this code is currently providing, but    I'm  having tough time passing thus far. the goal is to add this code     SELECT    SUM(CAST(_Send2 AS INT)) AS [Email Sent]  ,SUM(CAST(_Open2 AS INT)) AS [Email Open]  ,SUM(CAST(Click2 AS INT)) AS [Email Click] FROM [dbo].[behaviour] Group by _Send2,_Open2,Click2   any help will be appreciated. 

How can merging two sorted arrays of N items require at least 2N – 1 comparisons in every case?

The HW question, on page 362 of Data Structures and Algorithms in C++: Fourth Editionby Mark Allen Weiss, reads as follows:

Prove that merging two sorted arrays of N items requires at least 2 * N – 1 comparisons. You must show that if two elements in the merged lists are consecutive and from different lists, then they must be compared

If we are trying to find the lower bound then wouldn’t the number of comparisons be N, not 2 * N – 1? If the largest element is some array Ais smaller than the smallest element in some array B then at most you would only have to do N comparisons since after all of A‘s elements are placed in the merged array then the remaining elements in B‘s can simply be appended in to the merged array.

The lower bound has to be something that is true for every possible N and every possible combination of elements in both arrays, right? 2 * N – 1 seems more like it would be the upper bound since there is no way there can be more comparisons than that.

Note: I am not asking for an answer to the HW question itself as I know that is deprecated. I am confused about the implied assertion the question is making about the lower bound

Showing that the class of regular languages are closed under merging / modified shuffle

Consider $ ab$ and $ cd$ which are two words. We merge these two into 6 possibilities: $ abcd, acbd, acdb, cabd, cadb, cdab$

So in general, a merge of words/sequences $ x, y ∈ Σ∗$ , is a word of length $ |x| + |y|$ with both $ x$ and $ y$ as disjoint subsequences in it.

For two languages $ L1$ and $ L2$ their merge is defined as the set of all possible merges of two words $ x ∈ L1, y ∈ L2$ .

So basically, a merge is a modified shuffle and should be of length that of the sum of the length of two languages, and should also be in order (see $ ab$ and $ cd$ example, as $ b$ could not come before $ a$ ).

I was thinking of just connecting the states of all $ L1$ and $ L2$ but this seems wrong as if you connect them all like a fully connected graph, one can jump and go back which is not acceptable.

What’s a basic idea on the construction I could do to prove this?

Merging 4 matrices to one matrix

I am struggling with the task to merge four matrices as presented below. Since the matrices A-D contain more than just four entries it would be too complex to do it by hand. Is there a simple or clever way to get the result in Mathematica?

A = {{A11,A12}, {A21,A22}}

B = {{B11,B12}, {B21,B22}}

C = {{C11,C12}, {C21,C22}}

D = {{D11,D12}, {D21,D22}}

E = {{A11,B11,A12,B12}, {C11,D11,C12,D12}, {A21,B21,A22,B22}, {C21,D21,C22,D22}}

Thanks in advance. 🙂

Max

Safest option for resizing /home and merging newly freed space with existing free space to form shared partition

I have Ubuntu 18.04.2 installed in the dual-boot mode along with Windows 10, and here is my current partition setup.

enter image description here

What I’d like to do is install Ubuntu 18.04.4 afresh while resizing my /home partition to, say, 4 GB (is this a reasonable size? I do not plan on storing any large files such as audio/video ones) and then combining the freed space with the 2.36 GB currently unallocated to create a shared NTFS partition.

What is my best (safest) course of action? Should I carry out the partition resizing and partition creation steps before I install Ubuntu 18.04.4? I believe I can do this by booting using a gparted live USB. Then, I could just install 18.0.4 on the existing / partition while formatting it and the newly resized /home. Is this the right way to do it?

Or will I get a chance to make these changes at the time of the installation of the OS? I have not clicked beyond this screen during the installation process and do not whether the above will be an option.

enter image description here

Merging individual files from two folders sequentially (never asked question)

I need to merge the contents of two folders sequentially into individual destinations. Here is what i have. A,B,C,D,E,F are individual files.

Folder 1: A B C ...  Folder 2: D E F ... 

At the output i need merged files sequentially. So they should be merged like this:

Output: AD BE CF ... 

In other words, first file from the Folder 1 with the first file from the Folder 2. Second file from the Folder 1 with the second file from the Folder 2. In our case AD is consisting of the content of files A and D, BE consisting of files B and E, etc.

Both folders have the same number of files. Output can go anywhere. For the sake of simplicity let’s call it Output folder and locate it in the same root as Folder 1 and 2.

Been looking for the solution for two days now. Yikes!

Merging nodes of a DAG

I would like to merge connected nodes with a specific attribute of a directed acyclic graph. After each merge operation, the graph should remain acyclic. Let’s say my graph contains blue nodes and white nodes.

enter image description here

A and B are connected, they may be merged:

enter image description here

The above graph is DAG. Merging node {A,B} with node {D} is illegal since it creates a cycle!

enter image description here

My current algorithm is based on union-find.

For each blue node b:    Make-Set(b) merge blue nodes if they are connected 

The bug is the output graph contains cycles. How can I avoid merges that create cycles in the graph?