How to apply Python generators to finding min and max values?

I’m solving yet another problem in HackerRank (https://www.hackerrank.com/challenges/determining-dna-health/problem). In short: you are given 2 arrays (genes and health), one of which have a ‘gene’ name, and the other – ‘gene’ weight (aka health). You then given a bunch of strings, each containing values m and n, which denote the start and end of the slice to be applied to the genes and health arrays, and the ‘gene’-string, for which we need to determine healthiness. Then we need to return health-values for the most and the least healthy strings.

My solution is below, and it works, but it’s not scalable, i.e. it fails testcases with a lot of values.

import re
if __name__ == '__main__':
    n = int(input())

    genes = input().rstrip().split()

    health = list(map(int, input().rstrip().split()))

    s = int(input())
    weights = ()
    for s_itr in range(s):
        m,n,gn = input().split()
        weight = 0
        for i in range(int(m),int(n)+1):
            if genes(i) in gn:
                compilt = "r'(?=("+genes(i)+"))'"
                matches = len(re.findall(eval(compilt), gn))
                weight += health(i)*matches
        weights.append(weight)
    print(min(weights), max(weights))

Can you advise on how to apply generators here? I suspect that the solution fails because of the very big list that’s being assembled. Is there a way to get min and max values here without collecting them all?

Example values:

genes = ('a', 'b', 'c', 'aa', 'd', 'b')
health = (1, 2, 3, 4, 5, 6)
gene1 = "1 5 caaab" (result = 19 = max)
gene2 = "0 4 xyz" (result = 0 = min)
gene3 = "2 4 bcdybc" (result = 11)

This case returns 0 19

python – Apply additions on a base array based on date ranges

please roast my code, I hope this is the good place to look for some advice on where I can improve.

Problem definition:

Apply modifications on values depending on date ranges.

Data:

Base array – holds dictionaries in the following format:

({‘date’: 20200101, ‘value’: 1}, {‘date’: 20200102, ‘value’: 2})

Modifier array – holds dictionaries with similar format:

({‘date’: 20200101, ‘value’: 1}, {‘date’: 20200201, ‘value’: 2})

Goal:
Add the respective value of the modifier array to the base array lining up the date ranges. Dates are exclusive, for example when the modifier array contains 2020-01-01 you have to add the value ‘1’ to all values in the base array that have a date less than 2020-01-01. Base array has a lot of elements while modifier array relatively few. In practice this splits the base array into a couple of date ranges. If the last modification date is less than the date in base array no modification is required.

My solution:

This is assuming the comparing of dates will work, I have translated this from perl for an easier read.

mod_index = 0 
mod_size = len(mod_arr)

for elem in base_arr:
  if elem('date') > mod_arr(mod_size - 1)('date'):
    break
  else:
    if elem('date') < mod_arr(mod_index)('date'):
      elem('value') += mod_arr(mod_index)('value')
    else:
      elem('value') += mod_arr(mod_index + 1)('value')
      mod_index += 1

magento2 – Apply filters or mass actions on grids with fake collection (or wirhout ui components)

I a admin grid with a change on _prepareCollection() function to get the collection from a response of api call, its working fine. But I do not have the filters or mass functions, how can I do that without ui components?

enter image description here

I have this change on my grid file:

/**
 * Collection
 *
 */
protected function _prepareCollection()
{
    $filter = (
        'query' => 'cat yellow',
        'page' => 1,
        'region' => '',
        'year' => '',
    );

    $collection = $this->_api->searchCat($filter);

    $this->setCollection($collection);
    return parent::_prepareCollection();
}

If I could simulate a collection, maybe I could use ui components, but I’m lost, how can I resolve my problem?

The idea is use the filter to search cats with cat api, and the mass action is to import those registers into a products.

How to force Slack to apply markdown within a word?

Slack has “recently” introduced its a bit annoying WYSIWYG “message composer” which breaks the message formatting with the inline markdown. Fortunately there is now also option called “format messages with markup” which kind of reverts this feature back to normal, but…

I would like to know, how to force this inline markdown interpreter to work also in the middle of words. For example, how to achieve these:

partiallystrike

connected

Apparently, the following:

par~tiallys~trike

`connect`ed

do not work. There must be a separator before/after ~ or `, but if space is used, it’s no more a single word 🙁 Is there any “invisible” (and simply reachable) character Slack would accept as a separator which we could use for this purpose?

germany – Do I qualify for a German visa? How do I apply?

In the website of Germany Embassy in U.K., it is stated that

(…)

Urgent reasons for entry exist especially in the following cases.

(…)

4. Educational reasons

initial entry: documentation from the apprenticeship or study
institution regarding the requirement of in person attendance as well
as proof of accommodation.

(…)

Similarly, the interior minister of Germany government states that

What are valid grounds for crossing the border?

(…)

Travellers can be permitted to cross borders to visit their partners
or families, receive medical treatment, attend educational and
training institutions that require in-person attendance, or attend
important family events.

My situation as follows, I will conduct internship starting from 15 of June, and I am starting to my Master’s program on the 1st of September of this year, both in Germany.

However, I am a Turkish national, living in U.K. for the last 6 months.

Now, I have to get a visa in order to enter Germany, but neither the embassy haven’t, nor visametric (the external source which handles the visas for German embassy) opened, yet.

To make sure that I understand everything correctly: Am I allowed to get a German visa?

If so, how do I supposed to get it since visametric is closed?

germany – Am I entitled to apply for a German visa

In the website of Germany Embassy in U.K., it is stated that

(…)

Urgent reasons for entry exist especially in the following cases.

(…)

4. Educational reasons

initial entry: documentation from the apprenticeship or study
institution regarding the requirement of in person attendance as well
as proof of accommodation.

(…)

Similarly, the interior minister of Germany government states that

What are valid grounds for crossing the border?

(…)

Travellers can be permitted to cross borders to visit their partners
or families, receive medical treatment, attend educational and
training institutions that require in-person attendance, or attend
important family events.

My situation as follows, I will conduct internship starting from 15 of June, and I am starting to my Master’s program on the 1st of September of this year, both in Germany.

However, I am a Turkish national, living in U.K. for the last 6 months.

Now, I have to get a visa in order to enter Germany, but neither the embassy haven’t, nor visametric (the external source which handles the visas for German embassy) opened, yet.

To make sure that I understand everything correctly: Am I entitled to get a German visa?

If so, how do I supposed to get it since visametric is closed?

Is there a plugin to sell products and apply fee?

Common scenario. I have a platform that sell services and source code from different suppliers (a similar example is Fiverr). I’m looking for a plugin for WordPress that:

  • users can create their own products and services
  • when the user buys something, automatically the platform pays my supplier minus my fee

visas – Apply for a green card as a British citizen born in Albania?

I was born in Albania. If I apply for a green card (via the green card lottery) and I can't, would I have problems later if I just wanted to travel to the United States as a tourist? Could I be denied entry if they thought I would stay there indefinitely due to the failure of the green card visa? I wouldn't, I have a pretty comfortable life in the UK as a software developer, but I've always wanted to work in Silicon Valley.

I have visited America once for a few weeks (on an ESTA) and have enjoyed it very much. It would be a shame not to be able to go back there as a tourist.

dnd 5e – Does the creature trait Angelic Weapons apply to any weapon used by the creature?

It applies to any weapon

The trait that applies the extra radiant damage clarifies (emphasis mine):

When the planetar hits with any weapon, the weapon deals an extra 5d8 radiant damage

If you equip the planetar with an adamantine greatsword, attacks with it will also get this extra damage.

You can use Multiattack

In many monsters, their Multiattack action specifies what kinds of attacks they can use with it, but the planetar (among other angels) is special in that it says:

The planetar makes two melee attacks.

This means the planetar can use any weapon given to it with multiattack.

You can probably get the 4d6 slashing damage

The planetar’s stat block specifies that the Greatsword action has 4d6 slashing damage. This does not necessarily apply to an adamantine greatsword, which deals only 2d6 slashing damage by default. That being said, a greatsword and adamantine greatsword are basically identical in how you would wield it, so a GM could certainly rule that the 4d6 damage dice are used.

Larger weapon sizes is a rule concerning creating monsters in the Dungeon Master’s Guide that could also result in these damage dice:

Big monsters typically wield oversized weapons that deal extra dice of damage on a hit. Double the weapon dice if the creature is Large, triple the weapon dice if it’s Huge, and quadruple the weapon dice if it’s Gargantuan.

Whether or not you could find/craft an oversized weapon is also up to the GM, but this would apply the higher damage dice as well.

Even if it does 4d6 slashing damage, that usually won’t destroy a larger ship in two turns

Looking at the larger ships in Ghost of Saltmarsh, destroying them in an average of 2 turns is very unlikely even with an oversized greatsword. Automatically scoring a critical hit helps, but your average damage for each attack is still only: $$8*3.5+10*4.5+7$$
This yields an average of 80 damage per attack, and with four attacks over two turns that gives 320 damage. Then you have to account for the 10% chance that your attacks don’t beat the AC of the hull. The larger ship hulls have 15 AC (18 for a warship), so with a +12 to hit you are not dealing damage on a 1 or 2. This reduces your expected damage over two turns to only 288 (240 against a warship).

That being said, gaining advantage does push the expected damage against 15 AC hulls to 317 (300 against warships). The chance that you sink a 500 HP ship (like a galley or warship) in two turns with this strategy is basically 0 regardless.

Without the extra 2d6 slashing damage, you aren’t even sinking those 300 HP ships with two turns

If your DM rules that the adamantine greatsword only deals 2d6 slashing damage, you have only:
$$4*3.5+10*4.5+7$$

…or 66 damage per attack. This totals to 261 expected damage over two turns with advantage, and you are only sinking longships and sailing ships in two turns 0.8% of the time. Those 500 HP ships are then completely out of your grasp in two turns.

dnd 5th – Does the creature with angelic weapons apply to a weapon used by the creature?

The planetar deals massive amount of damage to a CR16 creature. I was wondering, if you gave her an adamantine sword (which critically hits objects), what would happen if she struck an object?

My concern is whether Angelic weapons the bonus only applies to a magic divine sword carried by the planet, or if it is applied to weapons used by the angel.

Normally, he rolls 4d6 + 5d8 + 7 per single attack (not counting multiple attacks). With an adamantine sword (which I guess I can't say is conjured), would that do 8d6 + 10d8 + 7 damage to the object?

I want to use it for a wizard, who would change shape to planetary, equip an adamantine sword, and then attack some ships (by Salt marsh ghosts standards, it could destroy most boats in two turns).

Here is the description of the capacity:

Angelic weapons: planetary weapons attacks are magical. When the planetary strikes with any weapon, the weapon deals 5d8 additional radiant damage (included in the attack).