Two random variables that sum up to user-defined value [closed]

What I am looking for is to create an application so 6 year old can learn math. This application should generate random examples, like:

1 + 6 5 + 4 3 + 1 0 + 10 9 + 1 

The sum should never exceed 10. Cases like “9 + 1” and “1 + 9” are two different cases.

I tried to generate random numbers the following way (JavaScript):

const getRandomInt = (min, max) => {   min = Math.ceil(min);   max = Math.floor(max);   return Math.floor(Math.random() * (max - min + 1)) + min; }  const hh1 = {}; const hh2 = {}; for (let i = 0; i < 10000; i++) {   const x = getRandomInt(0, 9);   const y = getRandomInt(0, 9 - x);    if (!hh1[x]) {     hh1[x] = 1;   } else {     hh1[x] = hh1[x] + 1;   }    if (!hh2[y]) {     hh2[y] = 1;   } else {     hh2[y] = hh2[y] + 1;   } } 

But it obviously didn’t work, result is:

> hh1 { '0': 1005,   '1': 1037,   '2': 952,   '3': 951,   '4': 1048,   '5': 986,   '6': 1025,   '7': 1060,   '8': 992,   '9': 944 } > hh2 { '0': 2850,   '1': 2009,   '2': 1438,   '3': 1092,   '4': 821,   '5': 643,   '6': 488,   '7': 328,   '8': 225,   '9': 106 } 

First number looks random, the the second isn’t. Zero appears 10 times more than 9, for example. One way to fix is to generate all pairs and pick from the pair. But I’m wondering if there is a better way.

Finding all rows of 2 variables using Gaussian Elimination

Suppose I have a system of linear equations. Using Gaussian elimination, I can determine whether a solution exists, and even find a valid solution.

During the elimination, I can combine rows together, to produce new rows with different number of variables. Is there a method to find all possible rows that contain exactly 2 variables? For example, I may want to find all equalities between variables. This is equivalent to finding all rows that contain exactly 2 variables. Is it possible to do this without trying all (exponentially many) combinations of rows?

For example if I have:

Row 1: A xor B xor C = 1

Row 2: A xor B xor D = 1

I can combine row 1 and row 2 to say that C xor D = 0

If I have a large amount of rows, and they require large combinations of large rows to produce smaller rows, is it trivial or hard to find all rows of size 2? Can I do better than adding random pairs to the system and checking it still has a solution?

Local variables in sums and tables – best practices?

Stumbled on Local variables when defining function in Mathematica in math.SE and decided to ask it here. Apologies if it is a duplicate – the only really relevant question with a detailed answer I could find here is How to avoid nested With[]? but I find it sort of too technical somehow, and not really the same in essence.

Briefly, things like f[n_]:=Sum[Binomial[n,k],{k,0,n}] are very dangerous since you never know when you will use symbolic k: say, f[k-1] evaluates to 0. This was actually a big surprise to me: by some reason I thought that summation variables and the dummy variables in constructs like Table are automatically localized!

As discussed in answers there, it is not entirely clear what to use here: Module is completely OK but would share variables across stack frames. Block does not solve the problem. There were also suggestions to use Unique or Formal symbols.

What is the optimal solution? Is there an option to automatically localize dummy variables somehow?

How to rewrite URL with PHP variables with htaccess to a normal looking URL?

I have a problem. I want to change an old database website that is not made in WordPress to WordPress. My site uses PHP variables So the URL is originally:

website.com/index.php?tl=1&pg=2&bs=3&hcbs=4&sc1bs=5&sc2bs=6&sc3bs=7&hc=8&blbs=9

But I could rewrite that to a normal looking url:

website.com/1/2/3/4/5/6/7/8/9.php

To do that in the old site I used the following rewrite rules in the .htaccess file:

RewriteEngine on  RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&sc1bs=$  5&sc2bs=$  6&sc3bs=$  7&hc=$  8&blbs=$  9 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&sc1bs=$  5&sc2bs=$  6&hc=$  7&sc3bs=$  8 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&sc1bs=$  5&hc=$  6&sc2bs=$  7 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hcbs=$  4&hc=$  5&sc1bs=$  6 [L] RewriteRule ^(.*)/(.*)/(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3&hc=$  4&hcbs=$  5 [L] RewriteRule ^(.*)/(.*)/(.*).php ?tl=$  1&pg=$  2&bs=$  3 [L] 

But now I am trying to do so in WordPress. WordPress already has some preinstalled rewrite rules:

<IfModule mod_rewrite.c> RewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$   - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L] </IfModule> 

But when I try to combine the both in any way the complete wordpress site stops working. Does anyone have an idea how to solve this?

Looking forward for your replies

Greetings

Hanno

Factoring long trigonometric expressions separating specific variables

I have a very long expression with trigonometric functions:

n (2 a - h - 2 z) (-Sin[p (β - δ + t ω)] + Sin[p (β + δ + t ω)]) 

I would like to simplify the term (-Sin[p (β - δ + t ω)] + Sin[p (β + δ + t ω) to 2 Sinδ Cos (ωt + β).

Any suggestions? Just using Simplify does not work on this case. Thank you for your help.

Does hiding variables work in terms of blocks or line-by-line?

Let’s assume I have the following code:

declaration of a declaration of b ..a..b {   ..a..b   declaration of a    declaration of b   ..a } 

In this code {} represent the inner block. declaration represents binding occurrence, and .. represent applied occurrence.

So my question is that is it legal to use the outer scope variables inside an inner scope and then redeclare them ? If so how does the hiding of outer variables system work (Does it start to work when it sees a redeclaration)? Thanks in advance.

Issue with button instantiation and variables in Unity3D

Im currently trying to make a system where an inventory of buttons are created and upon runtime the buttons are placed into a GUI component(Panel). I used a list of buttons which gets created on start and creates X amount of buttons for X amount of spells found for said player, and for some reason the button created isn’t acknowledging any changes made to it:

    public void createButton(int index)     {         var panel = GameObject.Find("ButtonPanel");         Spell spell = GlobalControl.Instance.spells[index];         GameObject button1 = (GameObject)Instantiate(ButtonPrefab);         button1.GetComponent<GUIText>().text = spell.spellname;         button1.GetComponent<RectTransform>().SetParent(panel.transform);         //get prev button position         float yindex = 130.0f - spellinv.Count * 35.0f;         button1.GetComponent<RectTransform>().SetInsetAndSizeFromParentEdge(RectTransform.Edge.Left, yindex + 0, 10);         button1.layer = 5;         spellinv.Add(button1);     } 

There are no issues at runtime, however the RectTransform doesn’t alter the position it just sits at (0,0,0), and the text is still set to the prefab default “Button”, it appears to not register anything I apply to the button, except for the layer settings.