## 2021-12-05

### Maximum path sum of 2 lists

My question is about this kata on Codewars. Function takes two sorted lists with distinct elements as argument, which they might or might not have common items. Task is find the maximum path sum. While finding the sum if there any common items you can choose to change your path to the other list. The given example is like this:

list1 = [0, 2, 3, 7, 10, 12]
list2 = [1, 5, 7, 8]
0->2->3->7->10->12 => 34
0->2->3->7->8 => 20
1->5->7->8 => 21
1->5->7->10->12 => 35 (maximum path)

Actually i solve the kata but my code doesn't match the performance criteria so i get execution timed out. What can i do for it? How can i improve?

Here is my solution:

``````def max_sum_path(l1:list, l2:list):
common_items = list(set(l1).intersection(l2))
if not common_items:
return max(sum(l1), sum(l2))
common_items.sort()
s = 0
new_start1 = 0
new_start2 = 0
s1 = 0
s2 = 0
for item in common_items:
s1 = sum(itertools.islice(l1, new_start1, l1.index(item)))
s2 = sum(itertools.islice(l2, new_start2, l2.index(item)))
new_start1 = l1.index(item)
new_start2 = l2.index(item)
s += max(s1, s2)
s1 = sum(itertools.islice(l1, new_start1, len(l1)))
s2 = sum(itertools.islice(l2, new_start2, len(l2)))
s += max(s1, s2)
return s
``````

from Recent Questions - Stack Overflow https://ift.tt/3puYtng
https://ift.tt/eA8V8J

### Passing props that will be used in style in child component - Vue

I have a button that runs the function `startProcess` which will generate a random number. This random number will be passed as a prop to `Child.vue` that will be used in style. I looked into some pages "How to use props in style in vue". The solution was to use `computed`, but nothing seems to work. For a better understanding, please check the code.

P.S. This is a simplified code. Removed `template, script, style`.

App.vue

``````<button @click="startProcess">Start</button>
<Child v-if="toggleChild" :top="top" />

data() {
return {
toggleChild: false,
top: 0
}
},
methods: {
startProcess() {
this.toggleChild = !this.toggleChild;
this.top = Math.random();
};
}
``````

Child.vue

``````<button @click="logTop">Log</button>

props: { top: Number },
computed: {
return {
cssProps() {
"--top": `\${this.top}%`;
};
};
};

.foo {
top: var(--top);
};
``````

from Recent Questions - Stack Overflow https://ift.tt/3Dqmj8X
https://ift.tt/eA8V8J

### i can't connect to Azure database in QT

My database is on an Azure server. And I'm trying to connect to it via an ODBC driver (by the way, I tried to install it manually, but I couldn't get it. They say it's built in). I get the following error: "Data source not found and no default ODBC driver specified: Unable to connect"

``````dataBaseKnowFood = QSqlDatabase::addDatabase("QODBC");
QString connectString = QStringLiteral("myconnectionstring");
dataBaseKnowFood.setDatabaseName(connectString);
if (!dataBaseKnowFood.open())
{
QMessageBox::critical(this, "Programm", dataBaseKnowFood.lastError().text());
}
``````

from Recent Questions - Stack Overflow https://ift.tt/3dB0g4Z
https://ift.tt/eA8V8J

### Find combination of string sentences - Combinations of frequency tables to target frequency table

I have a list of sentences, for example a list of 1000 sentences.

I would like to find a combination of sentences to match/'match closest' a certain frequency table:

[a:100, b:80, c:90, d:150, e:100, f:100, g:47, h:10 ..... z:900]

I thought about finding all possible combinations from the sentences list by using combinations like in here (so comb(1000, 1); to comb(100, 1000); ) and then compare every combination with the frequency table, so that distance is minimum. So sum all frequency tables from a possible combination and compare this sum with the target, the combination with the smallest difference with the target should be recorded. There could be multiple combinations that match closest.

The problem is that the calculation of all combinations takes way too long to complete, apparently couple of days. Is there a known algorithm that could solve this efficiently? Ideally couple of minutes maximum?

Input sentences:

More RVs were seen in the storage lot than at the campground.

She did her best to help him. There have been days when I wished to be separated from my body, but today wasn’t one of those days.

The swirled lollipop had issues with the pop rock candy.

The two walked down the slot canyon oblivious to the sound of thunder in the distance.

Acres of almond trees lined the interstate highway which complimented the crazy driving nuts.

He is no James Bond; his name is Roger Moore.

The tumbleweed refused to tumble but was more than willing to prance.

She was disgusted he couldn’t tell the difference between lemonade and > limeade.

He didn’t want to go to the dentist, yet he went anyway.

Find combination of sentences that match the following frequency table closest:

[a:5, b:5, c:5, d:5, e:5, f:5, g:5, h:5 ..... z:5]

Example:

Frequency table of sixth sentence

He is no James Bond; his name is Roger Moore.

is [a:2, e:5, g:1, h:1, i:3, j:1, m:3, n:3, o:5, r:3, s:4]

Frequency table takes upper and lower equal and excludes special characters.

from Recent Questions - Stack Overflow https://ift.tt/3xWWDja
https://ift.tt/eA8V8J

### How to use ImageSource in xaml

I want to give the Button an Image like this:

``````<Button Name="Close" Grid.Column="1" HorizontalAlignment="Left" Margin="513,0,0,0" VerticalAlignment="Center" Height="15" Width="15" BorderBrush="{x:Null}" Click="Minimize_Click">
<Button.Background>
<ImageBrush ImageSource="{DynamicResource  CloseImage}"/>
</Button.Background>
</Button>
``````

and this is in my ResourceDictionary:

``````<ImageSource  x:Key="CloseImage"><Image Source="../Resource/close-button.png"></Image></ImageSource>
``````

But it says that I can't add somethin in ImageSource (In German):

``````  Resources.xaml(7, 39): [MC3028] Einem Objekt vom Typ "System.Windows.Media.ImageSource" kann kein Inhalt hinzugefĆ¼gt werden. Zeile 7 Position 39.
``````

I have no idea how to make this because this also doesn't work:

``````<Button Name="Close" Grid.Column="1" HorizontalAlignment="Left" Margin="549,0,0,0" VerticalAlignment="Center" Height="14" Width="14" BorderBrush="{x:Null}" Click="Close_Click" >
<Button.Background>
<ImageBrush ImageSource="../resource/close-button.png" TileMode="None"/>
</Button.Background>
</Button>
``````

It says the recource can't be found.

from Recent Questions - Stack Overflow https://ift.tt/3plBT0g
https://ift.tt/eA8V8J