Given $n$ unique items and an $m^{th}$ normalised value, compute $m^{th}$ permutation without factorial expansion

We know that the number of permutations possible for $ n$ unique items is $ n!$ . We can uniquely label each permutation with a number from $ 0$ to $ (n!-1)$ .

Suppose if $ n=4$ , the possible permutations with their labels are,

0:  1234 1:  1243 2:  1324 3:  1342 4:  1432 5:  1423 6:  2134 7:  2143 8:  2314 9:  2341 10: 2431 11: 2413 12: 3214 13: 3241 14: 3124 15: 3142 16: 3412 17: 3421 18: 4231 19: 4213 20: 4321 21: 4312 22: 4132 23: 4123 

With any well defined labelling scheme, given a number $ m, 0 \leq m < n!$ , we can get back the permutation sequence. Further, these labels can be normalised to be between $ 0$ and $ 1$ . The above labels can be transformed into,

0:       1234 0.0434:  1243 0.0869:  1324 0.1304:  1342 0.1739:  1432 0.2173:  1423 0.2608:  2134 0.3043:  2143 0.3478:  2314 0.3913:  2341 0.4347:  2431 0.4782:  2413 0.5217:  3214 0.5652:  3241 0.6086:  3124 0.6521:  3142 0.6956:  3412 0.7391:  3421 0.7826:  4231 0.8260:  4213 0.8695:  4321 0.9130:  4312 0.9565:  4132 1:       4123 

Now, given $ n$ and $ m^{th}$ normalised label, can we get the $ m^{th}$ permutation while avoiding the expansion of $ n!$ ? For example, in the above set of permutations, if we were given the $ m^{th}$ normalised label to be $ 0.9$ , is it possible to get the closest sequence 4312 as the answer without computing $ 4!$ ?

How to do WP_User_Query for Nested Array value Inside Nested Array field

i am still new in wordpress development and try to playing with WP_User_Query right now.

I have meta field, with this value:

array (   0 =>    array (     'address' =>      array (       'street_1' => 'Street 1 String',       'street_2' => '',       'city' => 'SEARCH',       'zip' => '',       'state' => '',       'country' => '',     ),   ), ) 

What i am trying to do, i want to search / query user filtered by city using SEARCH keyword. How to achieve that using WP_User_Query?

Thanks

Monthly search value in adwords api is much larger then in a Keyword Planner

I am trying to use an adword api to get some keyword statistics. But what I see is that with a same parameters my monthly search volue is about 7 mln searches. While adword keyword planner shows around 400-500. I can provide php code with parameters I am setting. Network settings:

$  networkSetting = new NetworkSetting();         $  networkSetting->setTargetGoogleSearch(true);         $  networkSetting->setTargetSearchNetwork(false);         $  networkSetting->setTargetContentNetwork(false);         $  networkSetting->setTargetPartnerSearchNetwork(false); 

Language is set to Russian following way:

 $  languageParameter = new LanguageSearchParameter();         $  english = new Language();         $  english->setId(1031);         $  languageParameter->setLanguages([$  english]);         $  searchParameters[] = $  languageParameter; 

Location is set to Ukraine:

$  loc = array();         $  location = new location();         $  location->setId(2804); // Ukraine         $  loc[]=$  location;         $  locationTargetParameter = new LocationSearchParameter();         $  locationTargetParameter->setLocations($  loc);         $  searchParameters[] = $  locationTargetParameter; 

What Am I missing?

Mass update all cells in a column with a substring of it’s original value

I need to trim the last seven characters off of all the cells in a column.

This query returns the results that I need

SELECT test_date, SUBSTRING(test_date FROM 1 FOR CHAR_LENGTH(test_date) - 7) as test from results; 

I now need to take the computed result from the substring and replace the original values.

Here’s what the data looks like, if it helps.

Data Table

Find position in array where element-wise multiplication with string of 1 and 0s results in max value

I have a sequence of 1s and 0s. For example: $ bits = [1, 0, 1, 1, 1, 0]$ . I also have an array of positive integers. For example $ arr = [12, 23, 4, 6, 8, 0, 24, 72]$ . I need to find the index, $ i$ , in $ arr$ of the leftmost element of $ bits$ such that

$ $ \sum_{j = i}^{i + \textrm{length of bits}}{bits[j – i] * arr[j]}$ $

is a maximum. Essentially I am maximizing the element-wise multiplication between the two sequences starting at index $ i$ .

I need to solve it in $ O(n\log n)$ or better, but I can only think of a way to do it in $ O(n^2)$ . I have a feeling prefix sums could be used but am not sure how.

Method to change value in a key for a min heap

How would you write a method to change the value of a min heap where bool changeKey(int oldKey, int newKey). The keys are unique, no duplicate keys are permitted. If there is a key in the heap with value oldKey, and no existing entry with key newKey, it will change it to newKey, keeping the the heap properties and returning true. If there is no key in the heap with value oldKey, or an existing entry has value newKey, then it will take no action and return false. Also an auxiliary map is used to store the locations of the keys in an array. I know how to write methods for insertion but haven’t seen any implementations of this.

How to numerically verify that principal value?

Mathematica finds

Integrate[Exp[I*s]/(1 + s/(s^2 - 1)^2), {s, -Infinity, Infinity}, PrincipalValue -> True] // ToRadicals (*A huge closed-form expression which is omitted here.*) N[%] (*-1.414 + 0.192275 I*) 

The use of the principal value is grounded by the plots

Plot[{Cos[s]/(1 + s/(s^2 - 1)^2),Sin[s]/(1 + s/(s^2 - 1)^2)},{s,-5,5},WorkingPrecision->30,PlotPoints -> 50] 

enter image description here

It’s clear that the integrand has its real singularities at the real roots of the denominator, so

sol = Reduce[1 + s/(s^2 - 1)^2 == 0, s, Reals] // ToRadicals;  sol[[1]][[2]] (*-(1/(2 Sqrt[3/(4 + (155/2 - (3 Sqrt[849])/2)^(1/3) + (1/2 (155 + 3 Sqrt[849]))^(1/3))]))  -  1/2 Sqrt[8/3 - 1/3 (155/2 - (3 Sqrt[849])/2)^(1/3) -  1/3 (1/2 (155 + 3 Sqrt[849]))^(1/3) +     2 Sqrt[3/( 4 + (155/2 - (3 Sqrt[849])/2)^(1/3) + (1/2 (155 + 3 Sqrt[849]))^(  1/3))]]*)  N[%] (*-1.49022*)  sol[[2]][[2]] (*-(1/(2 Sqrt[3/(4 + (155/2 - (3 Sqrt[849])/2)^(1/3) + (1/2 (155 + 3 Sqrt[849]))^(1/3))])) +  1/2 Sqrt[8/3 - 1/3 (155/2 - (3 Sqrt[849])/2)^(1/3) -   1/3 (1/2 (155 + 3 Sqrt[849]))^(1/3) + 2 Sqrt[3/( 4 + (155/2 - (3 Sqrt[849])/2)^(1/3)+(1/2 (155 + 3 Sqrt[849]))^( 1/3))]]*) 

However, I have doubts concerning the obtained principal value because the integrand asymptotically equals $ \exp(is)$ as $ s\to \infty$ and $ s\to -\infty$ and $ $ PV\int_{-\infty}^\infty \exp(is)\,ds $ $ does not exist.

In view of it I try to verify it numerically through

NIntegrate[Exp[I*s]/(1+s/(s^2-1)^2),{s,-Infinity, -(1/(2 Sqrt[3/(4+(155/2-(3 Sqrt[849])/2)^(1/3)+(1/2 (155+3 Sqrt[849]))^(1/3))]))- 1/2 Sqrt[8/3-1/3 (155/2-(3 Sqrt[849])/2)^(1/3)-1/3 (1/2 (155+3 Sqrt[849]))^(1/3)+ 2 Sqrt[3/(4+(155/2-(3 Sqrt[849])/2)^(1/3)+(1/2 (155+3 Sqrt[849]))^(1/3))]], -(1/(2 Sqrt[3/(4+(155/2-(3 Sqrt[849])/2)^(1/3)+(1/2 (155+3 Sqrt[849]))^(1/3))]))+ 1/2 Sqrt[8/3-1/3 (155/2-(3 Sqrt[849])/2)^(1/3)-1/3 (1/2 (155+3 Sqrt[849]))^(1/3)+ 2 Sqrt[3/(4+(155/2-(3 Sqrt[849])/2)^(1/3)+(1/2 (155+3 Sqrt[849]))^(1/3))]],Infinity}, Method->"PrincipalValue",AccuracyGoal->3,PrecisionGoal->3,WorkingPrecision->50] 

which results in the error message

NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in s near {s} = {3.7749613270651398879039428756113970426387939277790*10^28}. NIntegrate obtained 8.8211977939280824575415993952100374290963331174834*10^47 I and 9.1940327832901306869987159913883594088789773626283`50.*^47 for the integral and error estimates.

and

 (*-2.6098684408162971553635553440779848277629513026488*10^49 +   8.8211977939280824575415993952100374290963331174789*10^47 I*) 

Constructive suggestions are welcome.

Solve boundary value problem with NDSolve. How to print out approximations to a solution?

I solve particular boundary-value-problem for ODE with NDSolve “Shooting” method. The case is that solution is attained very slow, that seems to mean that boundary-value-problem which is supposed to be well-defined enough, in fact, is ill at some place. So i try figure out. First step is to see concrete values of a produced approximations to a solution. What language constructs should i use for that?

Simple example. Suppose we consider particle motion in vertical plane. We throw our particle from initial point with coordinates {x0,y0} := {0,0} and initial trajectory angle 45 degrees. And try to achieve point with coordinates {x1,y1} := {1,0} by varying particle initial velocity. We don’t know two things here: initial velocity and a duration of a motion. Here is how that toy problem can be presented and solved in mathematica:

gravity = 10; bvpsol = NDSolve[     {      {       (* ODE system (5th order) *)       {x''[u] / c[u]^2 == 0,        y''[u] / c[u]^2 == -gravity,        c'[u] == 0},       (* boundary conditions (5 items) *)       {x[0] == y[0] == 0,        x[1] == 1,        y[1] == 0,        x'[0] == y'[0]}       }      }, {x[u], y[u], c[u]}, u,      Method -> {"Shooting",        "StartingInitialConditions" -> {x[0] == y[0] == 0,          x'[0] == y'[0] == 1, c[0] == 1}}] // Flatten;  {dxdu, dydu} = D[{x[u], y[u]} /. bvpsol, u]; {vx0, vy0} = ({dxdu, dydu} / c[u] /. bvpsol) /. {u -> 0}; duration = c[u] /. bvpsol /. {u -> RandomReal[]};  ivpsol = NDSolve[{     (* ODE system *)     {x''[t] == 0, y''[t] == -gravity},     (* initial values *)     {x[0] == y[0] == 0, x'[0] == vx0, y'[0] == vy0}     }, {x[t], y[t]}, {t, 0, duration}];  ParametricPlot[{x[t], y[t]} /. ivpsol, {t, 0, duration},   GridLines -> Automatic, AspectRatio -> 1/2] 

comprehensive parabolic trajectory

Question: Now what options or language construct should i use to see approximations which are produced NDSolve while solving boundary-value-problem?

How can I maximize the value of Appearance for a sidhe?

I am preparing a character for my first Changeling:The Dreaming second edition game. I’ve opted for a sidhe, which come with this ability:

Sidhe get two extra dots of Appearance during character creation, even if this increases scores above 5.

Starting with an attribute of 7 sounds pretty incredible, so I’d like to maximize the value of my Appearance. I’m having some trouble:

  • I don’t see any attributes which obviously synergize with my high Appearance.
  • None of the Arts in the core rules are based on Appearance.
  • The only task I’ve seen which calls for Appearance is seduction.

How can I maximize the value of my abnormally high Appearance score? Assume nothing about the rest of the party (our characters will meet for the first time at the table). Anything published for Changeling: The Dreaming second edition is allowed, but I myself was only able to search the core rules.

Postgres- update a value in a array on particular index

I have a column named ids that is of type bigint[]. ids cane be null or of any length

It has values based on certain hierarchy.

My use case is I want to update value that is at a particular index. For example ids[2] = 50.

How can I achieve this?

I looked at this https://www.postgresql.org/docs/current/functions-array.html#ARRAY-FUNCTIONS-TABLE but couldn’t find anything that could help.

Thanks in advance.