Qix diagonally adjacent movement

I’m implementing a Qix clone game and I do not have any problems with implementation but rather with possible scenario.

Is this a valid scenario for this game and if yes how exactly should gameplay go in this case?

Black – Filled, Red – Current Player’s Path, Blue – Player

Step 1

If this is a possible scenario, then after completing the path player will end up with two diagonally adjacent rectangles.

Step 2

After that player can start moving from the bottom of the top rectangle to the right.

Step 3

In this case it should be immediately considered as a complete path and fill 1×1 square or player can create a path adjacent to the top of the bottom rectangle?

Step 4

When playing on a grid, can I pour a flask of oil on any adjacent square or just on the one I am standing on?

The description of a flask of oil says:

You can also pour a flask of oil on the ground to cover a 5-foot-square area, provided that the surface is level.

When playing on a grid, can I pour a flask of oil on any adjacent square or just on the one I am standing on?

How to remove any words containing two adjacent characters with different cases?

I have a list of permutations of ABCabc and I want to remove any permutations with two adjacent characters with different cases (uppercase and lowercase).

For example,

  • ABCcab is kept.
  • ABCacb must be removed because Ca contains two adjacent characters with different cases.
  • AbBcaC must be removed as well.

Attempt

Here is my attempt but without filtering.

Select[StringJoin /@ Permutations[Characters@"ABCabc"],....] 

Find original array from array with pairs of adjacent elements

Given an array composed of pairs, like this:

[[3,5],[1,5],[3,2],[1,4]]

Each element in the array (call it pair) means that pair[0] and pair[1] are adjacent in the original array. Note, they can come in either order. For instance, for the sample array above, the original array would be:

4,1,5,3,2 (or the reversed version of this)

How can I do this quickly? I tried doing this as follows, which works, but it’s too slow:

Create a hashmap that maps adjacent elements. Map = {3: [5,2], 1: [5,4], 5: [1,3], 4: [1], 2:[3]}. My algorithm would then start with one of the keys that only has a corresponding value length of 1 (in this case either 4 or 2), and then add to an output array, and go through the hashmap. I.e. First I would add 4 to my output, and then go from key of 4 (with a corresponding value of 1), to the key of 1, with corresponding values of 5 and 4. I’d ignore 4 (since it’s already in output), and add 5, then go to the key of 5, and so on and so forth. This is too slow! Is there a better algorithm?

How does increasing in size affect adjacent squares and enemies?

Inspired by this question and effectively asking the opposite question. Assuming play is on a grid, what squares can a creature occupy when it goes from being medium size (1×1) to large size (2×2)? Does the square it already occupied when it was medium need to be included in its new form? What are the options for the three additional squares, can they simply be any that would make the creature 2×2? How does increasing in size interact with the “Moving Around Other Creatures” rule which states:

Whether a creature is a friend or an enemy, you can’t willingly end your move in its space.

So if there were a creature in one direction would you not be able to include its current space in your new form/size? What if you were surrounded by creatures, could you increase in size at all?

Some hopefully helpful diagrams: You are C, monsters are X, empty spaces are #.

Can

###   #C#   ###    

change into:

CC#   CC#   ###   

or

#CC   #CC   ###   

What can

XXX   #C#   ###   

change into?

What can happen from this last scenario:

XXX   XCX   XXX 

Note: I am looking for an answer that is rooted in RAW, but if no answer exists there an answer from experience with this issue would also work.

Examples of why this might matter:. If you end up occupying the same space as an enemy then a spell like fireball would no longer be able to target you.
If you push the creatures out of the way this could do things such as pushing then into a moonbeam spell.
If you are not allowed to occupy the same space as the monsters then I am confused what would happen if you were initially surrounded.

What squares can you occupy when your size increases, and do other nearby creatures impact this?

Given a list of integers and a target integer, return the number of triplets whose product is the target integer and two adjacent triplets


Question: Given a list of integers (possibly negative) and a target integer, return the number of triplets whose product is the target integer and two of the triplets must be adjacent.

More precisely, given a triplet $ (i,j,k)$ with $ i<j<k,$ it satisfies the question above if $ A[i] \times A[j] \times A[k] = target$ and either ($ j = i+1$ and $ k > j+1$ ) or ($ k = j+1$ and $ i < j -1$ .)

For example, if the list given is $ A = [1,2,2,2,4]$ and target $ = 8,$ then the answer is $ 3$ as $ (0, 1, 4) , (1, 2, 3)$ and $ (0, 3, 4)$ are the only triplets satisfying conditions above if we use $ 0$ -based numbering.

I stucked at this question for 3 hours and not able to solve it.

Any hint is appreciated.

Longest Even Length Palindromic Substring (with unique adjacent characters except for the center 2 letters)

You are given a string S containing lowercase English characters. You need to find the length of the largest subsequence of S that satisfies the following pattern: X1,X2,X3…Xn,Xn,…X3,X2,X1 where Xi is some character of S. The only constraint is that no adjacent character should be the same except Xn, that is Xi != X(i+1) for all 1<=i< n.

Input: The string: S

Output: The integer: 2n

Constraint: 1<=|S|<=10^3

Sample input 1: “acdbdea”

Sample output 1: 4

Explanation: “adda” is the longest subsequence following the given pattern.

Sample input 2: “abbacdeedc”

Sample output 2: 6

Explanation: “cdeedc” is the longest subsequence following the given pattern.

Sample input 3: “taker”

Sample output 3: 0

Explanation: No subsequence follows the given pattern.


This question was asked in a coding interview and I didn’t know how to solve it. I understood how to find longest palindromic sub sequence but don’t know how to implement the unique adjacent character part. Please help. pseudo code is fine

Can you Ready a Help action against a creature not (currently) adjacent to you?

Per the combat rules,

Alternatively, you can aid a friendly creature in attacking a creature within 5 feet of you.

Is there anything in the rules that prevents me from readying an action to help one specific creature (Friend) attack another (Enemy), should at some point before my next turn Enemy find itself within 5ft of me?