Construct a array using following rules

Consider there is a array $ a$ of length $ n$ , $ a=[a_i ,0 \leq i \leq n]$ and all $ a_i>0$ and I need to construct a array $ b$ of length $ n$ (if possible) , $ b=[b_i , 0\leq i \leq n]$ .Rules for making array b is all $ 1\leq b_i\leq 5$ .

Consider $ j=i+1$ ,if $ a_j>a_i$ then $ b_j>b_i$ ,if $ a_j<a_i$ then $ b_j<b_i$ and if $ a_i=a_j$ then $ b_i \neq b_j$ .

Example : $ a=[2,3,4]$ then $ b$ can be $ [1,2,3]$ ,any $ b$ is $ accepted$ .

My approach is to use a simple $ dynamic$ $ programming$ ,$ dp[i][j]$ where i will check if first $ i$ elements of $ b$ can be formed if $ b_i=j$ where $ 0<j<6$ if it is possible $ dp[i][j]=1$ else ,$ dp[i][j]=0$ .By this method i could find if answer exits but i could not find the array $ b$ ,I know array $ b$ can be formed by depth first search as we can see states are connected by i have no idea after that.Could anyone help me how to use dfs on this question.

Soure : link

Parallel Matrix Manipulation: find eigenvalues and construct list

I’m having some trouble with the Parallel commands in Mathematica 12.1:

I need to construct a table where its entries are {M, Eigenvalues of X[M]}, where X is a square matrix of dimension N with N big (>3000) and M a parameter. Specifically, I do the following:

AbsoluteTiming[BSg1P = Table[M = m;      {M, #} & /@ (Eigenvalues[N[X]]), {m, -2, 2, 1}];] 

and I compare with

AbsoluteTiming[BSg1P = ParallelTable[M = m;      {M, #} & /@ (Eigenvalues[N[X]]), {m, -2, 2, 1}];] 

The computing time is similar for both cases: the difference is around 6 sec. for a total time of 300 sec., which makes no sense if the parallel evaluation is performed. Since I have 2 processors, I would expect half of the time or a considerable fraction for the computing duration.

Am I doing something wrong? Or is there something about parallelization that I don’t understand?

On the other hand, if I don’t want to use ParallelTable, is there a way to compute the eigenvalues of X[M] in a faster parallel form?


How can follow this this guide to construct a graph with matrix/reachability

Let’s we have k matrices. For example we have 3 now, where first one is 8×5 ($ a_1$ x $ b_1$ ), second one is 5 x 6 ($ a_2$ x $ b_2$ ) and last one is 6 x 8 ($ a_3$ x $ b_3$ ). And our goal is to figure out if possible to multiply within any given matrices and reach a matrix of dimension x and y, when x and y is given ahead of time. In this example, (8×5) x (5×6) x (6×8), end up a 8×8 matrix. The hints is given, but I cannot visualize. Any more help is appreciated. can understand the first step, but have not idea about the second one.

First, we can define nodes in the graph as the values of each $ a_i$ and each $ b_i$ , and put an edge from $ a_i$ to $ b_i$ .

Second, Whenever there is a chain of matrices $ M_{i1},…M_{ik}$ , we can multiply, then x=$ a_{i1}$ has an edge to $ b_{i1} =a_{i2}$ , and $ a_{i2}$ has an edge to $ b_{i2}$ =$ a_{i3}$ , and so on, up until $ b_{ik}$ =y. So there could be a path from x to y in this graph.

Third, Inversely, for any path from x to y, the edges form a chain of matrices that we can multiply, which create a x x y matrix. therefore, x is reachable from y in the graph iff there is a chain of matrices which from the x x y matrix.

The first step create something like this ?

>  x-->  > n8-->n5 > n5-->n6  > n6-->n8 >   -->y 

What is $ M_{i1}$ , $ a_{i1}$ and $ b_{i1}$ ? How does that differ to $ a_{1}$ ?

How does someone (safely) construct, expand & renovate any given demiplane? [closed]

Casting Demiplane allows the caster (warlock or wizard… or sorcerer using Wish… &/or sneaky bard) to have:

  • A Medium-only door (‘Must be this size or smaller to ride – NO OGRES ALLOWED’) that vanishes when spell ends / after one hour.

  • Creates a permanent (30′ x 30′) room of stone &/or wood walls.

This spell has amazing uses yet serious limits which others have questioned:

Question: “How much one can customize the interior of this spell?”

Answer: “If / as / so much as the DM says / so!”


Question: “What the nature of this demiplane for location & tracking purposes?”

Answer: “They must describe it a bit &/or use a ‘tuning fork‘!”

Information on Demiplane is amazingly light, especially for a game system that prides itself on doing the absolute minimum possible for a spell’s casting. This spell is neither useful for combat mechanics nor very clear for role-play purposes.

My concerns with this spell description & use:

  • Does this shadowy connection door between Demiplanes vanish within the hour? The spell description does not specify, so this may be a way to build up a massive interconnected demi-mansion. Can this door stay ‘open’? Can it be a ‘window’ instead? Can the connection between planes let larger creatures through if you double it up multiple shadow doors in one spot?

  • What happens if one adds plane-space expanding magic to this Demiplane? Say you cast a Mordenkainen’s Magnificent Mansion in there – does the whole plane become a bit bigger? Or does this simply not fit? Or does this spell trigger a collapse-explosion similar to sticking a Bag of Holding into a Portable Hole? Can one change the time-passage of the original Demiplane so as to make these space-holder-builder spells permanent?

  • The 5e spell specifies the new parts must be cast OUTSIDE of the original. Is there ANY way to add or expand to the space-size of this 30′ x 30′ plane? Possibly the repeated use of the (non-exhausting) Wish spell? ‘You need not meet any of the requirements’… does that allow one to add bonus space to this walk in closet? Or even make this silly vanishing smoke-door a bit more durable.. or big enough to fit a donkey through?

Base question: Demiplane feels small / simple / specific / stuck. How does an Arch-mage add bits / expand / give it more space for activities?

Answers may include: any of the guides (Volo’s Mordenkainen’s, etc.), tweets from Lord Crawford, Sage Advice, any 5e Unearthed Arcana… or whatever one can find that is RAW, quasi-legal or even slightly more tested than outright home-brew.

construct a sql , assign it to a variable and execute inside shell script

I am trying to execute a mysql query inside my shell script, which is not executing . Here is what i am trying to do

query="\"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';\"" 

echo $ query

"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';" 

Inside my shell script , i am executing below which is not working. It is not giving any error but simply not considering -e option and listing down all the valid options for mysql client.

mysql -u$  username -p$  password -e$  query 

I even validated below in my shell prompt

echo "mysql -uroot -p -e$  query" mysql -uroot -p -e"select count(*) from information_schema.tables where TABLE_SCHEMA not in ('mysql','performance_schema','information_schema') and engine!='INNODB';" 

which is perfectly fine and executes without any issues. I am not sure what to do now. please help.Thanks

Why do modern sites frequently use JSON blobs client-side and construct the webpage in JavaScript client-side? [closed]

I have noticed something in later years. Instead of actually creating a HTML page, such as a table of data, on the server and sending the finished HTML page, they nowadays send a “minimal” (in a very broad sense of that word…) webpage which executes a JavaScript which in turn loads in JSON blobs which it then parses in JavaScript, client-side, to construct a webpage which is finally displayed to the user.

One side-effect of this, intentional or not, is that it often makes it much easier for me to “grab” their data since they frequently just “dump” their internal database’s fields to the client, even if they themselves don’t use all fields. So in a way, it’s like they are making it easier for people like me to automate things on their websites, whereas I used to have to constantly parse complex, messy, ever-changing HTML code.

So while I hate how idiotic this is from a logical/user perspective, as well as from a security one (depending on various factors), it’s actually “good” for me in a way. I just don’t understand it, since it’s significantly more work on their part and an overall extremely strange way of doing things.

Whenever I notice that a HTML page is “empty from content”, I always open the network tab in Pale Moon and reload the page, and then I see a “JSON” blob which I can study. It’s bizarre. It’s almost as if they are unofficially providing an “API” without mentioning it openly, but secretly they wink/nudge to us “powerusers”?