## probability – With what frequency should points in a 2D grid be chosen in order to have roughly \$n\$ points left after a time \$t\$

Say I have a 2D array of $$x$$ by $$y$$ points with some default value, for generalisation we’ll just say “0”.

I randomly select a pair of coordinates with a frequency of $$f$$ per second and, if the point selected is `0`: flip it to `1`. However, if the point is already $$1$$ then do not change it.

How then, given a known $$x$$ and $$y$$ (thus known total points as $$xy$$) can I calculate a frequency $$f$$ that will leave me with approximately (as this is random) $$n$$ `0` points remaining, after a set time $$t$$? Where $$t$$ is also seconds.

For some context I am attempting some simplistic approximation of nuclear half-life but I’m not sure how to make use of the half-life equation for this, nor do I think that it is strictly correct to apply it given my implementation isn’t exactly true to life, picking single points at a time.

## homotopy theory – Identifying discrete points in derived hom spaces

Let M be a model category presenting an ∞-category $$mathcal{M}$$, and let $$f : X to Y$$ and $$g : Y to Z$$ be arrows of M. Consider the following propositions:

1. The connected component of $$f$$ in $$mathcal{M}(X,Y)$$ is contractible
2. $$mathcal{M}(X, Y) xrightarrow{g_*} mathcal{M}(X, Z)$$ restricts to a homotopy equivalence between the connected components of $$f$$ and $$gf$$

When can these propositions be expressed in an elementary way from the model structure on M?

I’m interested in the second proposition (it relates to homotopy uniqueness for properties expressed by arrows and extensions along arrows). But in the case $$Z$$ is fibrant, it can be reduced to the the first question for $$f in mathbf{M}_{/Z}(gf, g)$$. Conversely, the first proposition is the $$Z=1$$ case of the second.

Given a simplicial model category, when $$X$$ is cofibrant and $$Y,Z$$ are fibrant — or a general relative category by first computing a simplicial localization — one could answer these questions by appealing to the corresponding questions of simplicial sets.

However, I’m hoping there’s a useful way to express these propositions somewhat more directly in terms of the the model structure on M rather than having to appeal to more elaborate consturctions.

## statistics – How can I calculate expected Stunt Points per attack when FIRST dropping a d6?

Here’s a tweaked version of the function from my earlier answer that should work for any number (≥ 2) of ordinary dice, with the player choosing two of them:

``````function: stunt points for DICE:s and STUNT_DIE:n vs TARGET:n {
if {1,2}@DICE + STUNT_DIE < TARGET { result: 0 }   miss

it's a hit; can we choose a pair that will give us stunts?
if 1@DICE = STUNT_DIE { result: STUNT_DIE }
if DICE = STUNT_DIE & 1@DICE + 2 * STUNT_DIE >= TARGET { result: STUNT_DIE }
loop I over {1..#DICE-1} {
if I@DICE = (I+1)@DICE & 2 * I@DICE + STUNT_DIE >= TARGET { result: STUNT_DIE }
}

result: 0   hit but no pair
}
``````

The first line in the function (checking if the roll is a miss) is the same as in my old code, except that I’m explicitly summing only the highest two ordinary dice rolled using `{1,2}@DICE`: if those plus the stunt die don’t meet the target, then no combination will. Conversely, if they do, then we’ll at least get a hit, but we might or might not get any stunts.

(Replacing the `result: 0` on the first line with `result: d{}` will make the code calculate the distribution of stunt points conditioned on the roll being a successful hit, i.e. as if all misses were rerolled until they hit. You could also change this line to e.g. return -1 to distinguish misses from hits with no stunts.)

Next, I’m checking if the player might be able to choose two dice out of however many they rolled that will given them a hit with stunts. Here, there are three possibilities, which the code checks for in this order:

1. If the highest ordinary die matches the stunt die, then simply choosing the highest two ordinary dice will give a hit with stunts. (We know it will, because we just checked that at the start of the function.)

2. Otherwise, if any ordinary die matches the stunt die and if that die plus the stunt die plus the highest roll will meet the target, then the player can choose those and get stunts.

(In the code, `DICE = STUNT_DIE` compares a sequence with a number, returning true if any value in the sequence matches the number. We don’t actually need to know the index of the matching die in the sequence, if any, since we know its value anyway — it’s equal to the stunt die!)

3. Finally, we loop over the dice and check if any two consecutive dice in the (automatically sorted) sequence have the same value, and if so, whether that value twice plus the stunt die is enough for a hit. If so, the player can choose that pair and get stunts.

(Since we know the sequence is sorted in descending order, and since this is the last possibility checked for, we could actually abort the loop early and return 0 from the function as soon as we find that `2 * I@DICE + STUNT_DIE < TARGET`, as no smaller pair can possibly give a hit either. Implementing that minor optimization is left as an exercise for the reader. 🙂

Finally, if none of those checks succeeds, the function returns 0 indicating that the player could not get any stunts but still rolled a successful hit (choosing e.g. their top two ordinary dice plus the stunt die).

When called with 2d6 as `DICE`, this function is a drop-in replacement for the one in my earlier answer, and indeed gives the same results.

What about for more dice? As we can see, as the number of dice to choose from increases, the probability of getting stunts increases.

In general, higher stunt counts are more likely than lower ones, which makes intuitive sense: the higher you roll on the stunt die, the more likely you are to hit and to be able to choose a hitting combo that includes two identical dice. However, the specific shape of the curve varies depending on the target difficulty: DC 10 above, for example, gives fairly smooth looking plots, but DC 11 seems to favor odd numbers of stunts, leading to a more staircase-like graph:

Notably, for five or more normal dice and DC 11, the probability of getting a hit with stunts is actually slightly lower if you roll a 4 on the stunt die than if you roll a 3. (Of course you still get more stunts if you do get any, and your overall hit probability is higher too, so a higher roll on the stunt die is still better.)

## cortex prime – Can a player character avoid dying as long as they still have Plot Points?

I’ve read Cortex Prime and now I’m wondering whether a PC could die. The rule said that “you can spend a PP to avoid being taken out of the scene” (which I translate as dying).

Does this mean that as long as a player still has PP, they can’t die if they don’t wish so?

## Can you use meta-magic/sorcery points twice in a turn?

Example: You use Quicken Spell to cast a leveled spell or cantrip as a Bonus Action, you then use your Action to cast a cantrip along with using Transmute Spell to change the cantrip’s damage type.

Is this an ok thing to do?

LMBC:You’re using two meta-magic options on two different spells in one turn.

## Connecting common points on a map

I work with a private preschool – 12th-grade school. The school has several campuses. And each campus has several hundred families. We have two separate spreadsheets. One spreadsheet has all of the parents’ home addresses and the other spreadsheet has all of the parents’ work addresses. We’re using a mapping software called eSpatial (but it’s limited). We can upload the spreadsheets (datasets) and map both batches of addresses.

The problem is that this doesn’t really tell us very much. Ultimately, we need a way to link home and work addresses together, visually, as being the same person.

For example, let’s say one point on a map is a parent’s home address at 123 Main St. and another point on the map is the same parent’s work address at 321 Sycamore Rd. We need a way to visually know that the two points below to the same person so we can see who, and how far, each parent travels to work. Ideally, if there was a line that connected the two points that would be great. That would make it easy to see how far away the parent works. Or it would also work to hover over one point and the corresponding home or work point would highlight.

Currently, the two spreadsheets do not have a common column that links the two together (I guess a “key”). Although I can create a spreadsheet that has a student ID column which would be the key between the two.

Any thoughts on how to put something like this together? Hopefully, this makes sense.

## equation solving – Computing periodic points of some function

Instead of recursively determine the period points, you could first iterate the function and subsequently determine the period points.

E.g. let us define the n-iterated function `fn({x_,y_})` for `{b,c}=={1/100,-1}` (note, it is better to use rational numbers if computing times allows):

``````hn({x_, y_}) = Nest(Simplify(h(#, 1/100, -1)) &, {x, y}, n)
``````

E.g. for n=2 :

``````h2{x_, y_}) = Nest(Simplify(h(#, 0.01, -1)) &, {x, y}, 2)
``````

This gives the following period points:

``````Solve(h2({x, y}) == {x, y}, {x, y})
``````

Up to `n==9` `hn` is calculated rather fast, but `h10` suddenly takes much longer. The reason is not clear to me.

## unity – How can I change the curved meeting points in my waypoints system so it will be updated in run time?

The post is a bit long but all the scripts are connected.

I have a simple waypoints system.

The first script is moving along LineRenderer line/s positions :

``````using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class MoveOnCurvedLines : MonoBehaviour
{
public LineRenderer lineRenderer;
public float speed;
public bool go = false;
public bool moveToFirstPositionOnStart = false;
public float rotSpeed;
public bool random = false;
public int currentCurvedLinePointIndex;

private Vector3() positions;
private Vector3() pos;
private int index = 0;
private bool goForward = true;
private List<GameObject> curvedLinePoints = new List<GameObject>();
private int numofposbetweenpoints;
private bool getPositions = false;
int randomIndex;
int curvedPointsIndex;

// Start is called before the first frame update
void Start()
{
curvedLinePoints = GameObject.FindGameObjectsWithTag("Curved Line Point").ToList();

if (curvedLinePoints != null && curvedLinePoints.Count > 0)
{
transform.rotation = curvedLinePoints(1).transform.rotation;
}
}

Vector3() GetLinePointsInWorldSpace()
{
positions = new Vector3(lineRenderer.positionCount);
//Get the positions which are shown in the inspector
lineRenderer.GetPositions(positions);

//the points returned are in world space
return positions;
}

// Update is called once per frame
void Update()
{
if (lineRenderer.positionCount > 0 && getPositions == false)
{
pos = GetLinePointsInWorldSpace();
numofposbetweenpoints = curvedLinePoints.Count;

if (moveToFirstPositionOnStart == true)
{
transform.position = pos(index);
}

getPositions = true;
}

if (go == true && lineRenderer.positionCount > 0)
{
Move();
}

var dist = Vector3.Distance(transform.position, curvedLinePoints(curvedPointsIndex).transform.position);
if (dist < 0.1f)
{
if (curvedPointsIndex < curvedLinePoints.Count - 1)
curvedPointsIndex++;

currentCurvedLinePointIndex = curvedPointsIndex;
}
}

int counter = 0;
int c = 1;
void Move()
{
Vector3 newPos = transform.position;
float distanceToTravel = speed * Time.deltaTime;

bool stillTraveling = true;
while (stillTraveling)
{
Vector3 oldPos = newPos;

newPos = Vector3.MoveTowards(oldPos, pos(index), distanceToTravel);

distanceToTravel -= Vector3.Distance(newPos, oldPos);
if (newPos == pos(index)) // Vector3 comparison is approximate so this is ok
{
// when you hit a waypoint:
if (goForward)
{
bool atLastOne = index >= pos.Length - 1;
if (!atLastOne)
{
index++;
counter++;
if (counter == numofposbetweenpoints)
{
c++;

counter = 0;
}
if (c == curvedLinePoints.Count - 1)
{
c = 0;
}
}
else { index--; goForward = false; }
}
else
{ // going backwards:
bool atFirstOne = index <= 0;
if (!atFirstOne)
{
index--;

counter++;
if (counter == numofposbetweenpoints)
{
c++;

counter = 0;
}
if (c == curvedLinePoints.Count - 1)
{
c = 0;
}
}
else { index++; goForward = true; }
}
}
else
{
stillTraveling = false;
}
}

transform.position = newPos;
}
}
``````

The second script is creating the lines :

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GenerateLines : MonoBehaviour
{
public GameObject linesWaypointsPrefab;
public int amountOfLines = 30;
public int minRandRange, maxRandRange;
public bool randomPositions = false;
public bool generateNewPositions = false;

private List<Vector3> linesWaypoints = new List<Vector3>();
private Transform waypointsLinesParent;

// Start is called before the first frame update
void Awake()
{
waypointsLinesParent = GameObject.Find("Curved Lines").transform;

if (generateNewPositions || (linesWaypoints.Count == 0 && amountOfLines > 0))
{
GenerateLinesWaypoints();
}
}

// Update is called once per frame
void Update()
{

}

private void GenerateLinesWaypoints()
{
for (int i = 0; i < amountOfLines; i++)
{
if (randomPositions)
{
var randPosX = UnityEngine.Random.Range(minRandRange, maxRandRange);
var randPosY = UnityEngine.Random.Range(minRandRange, maxRandRange);
var randPosZ = UnityEngine.Random.Range(minRandRange, maxRandRange);

if(linesWaypointsPrefab != null)
{
var LineWaypoint = Instantiate(linesWaypointsPrefab,
new Vector3(randPosX, randPosY, randPosZ), Quaternion.identity, waypointsLinesParent);

LineWaypoint.name = "Curved Line Point";
LineWaypoint.tag = "Curved Line Point";
}
}
else
{
if (linesWaypointsPrefab != null)
{
var LineWaypoint = Instantiate(linesWaypointsPrefab,
new Vector3(i, i, i), Quaternion.identity, waypointsLinesParent);

LineWaypoint.name = "Curved Line Point";
LineWaypoint.tag = "Curved Line Point";
}
}
}
}
}
``````

And last the script that should update in real time in run time the curved line/s positions and the lines positions between each curved point :

``````using UnityEngine;
using System.Collections;
using System.Collections.Generic;

(RequireComponent( typeof(LineRenderer) ))
public class CurvedLineRenderer : MonoBehaviour
{
//PUBLIC
public float lineSegmentSize = 0.15f;
public float lineWidth = 0.1f;
(Tooltip("Enable this to set a custom width for the line end"))
public bool useCustomEndWidth = false;
(Tooltip("Custom width for the line end"))
public float endWidth = 0.1f;
public bool showGizmos = true;
public float gizmoSize = 0.1f;
public Color gizmoColor = new Color(1,0,0,0.5f);
//PRIVATE
private CurvedLinePoint() linePoints = new CurvedLinePoint(0);
private Vector3() linePositions = new Vector3(0);
private Vector3() linePositionsOld = new Vector3(0);

// Update is called once per frame
public void Update ()
{
if (ResetLineRendererPositions.hasReseted == false)
{
GetPoints();
SetPointsToLine();
}
}

public void GetPoints()
{
//find curved points in children
linePoints = this.GetComponentsInChildren<CurvedLinePoint>();

linePositions = new Vector3(linePoints.Length);
for (int i = 0; i < linePoints.Length; i++)
{
linePositions(i) = linePoints(i).transform.position;
}
}

public void SetPointsToLine()
{
//create old positions if they dont match
if( linePositionsOld.Length != linePositions.Length )
{
linePositionsOld = new Vector3(linePositions.Length);
}

//check if line points have moved
bool moved = false;
for( int i = 0; i < linePositions.Length; i++ )
{
//compare
if( linePositions(i) != linePositionsOld(i) )
{
moved = true;
}
}

//update if moved
if( moved == true )
{
LineRenderer line = this.GetComponent<LineRenderer>();

//get smoothed values
Vector3() smoothedPoints = LineSmoother.SmoothLine( linePositions, lineSegmentSize );

//set line settings
line.positionCount = smoothedPoints.Length;
line.SetPositions( smoothedPoints );
line.startWidth = lineWidth;
line.endWidth = useCustomEndWidth ? endWidth : lineWidth;
}
}

void OnDrawGizmosSelected()
{
Update();
}

void OnDrawGizmos()
{
if( linePoints.Length == 0 )
{
GetPoints();
}

//settings for gizmos
foreach( CurvedLinePoint linePoint in linePoints )
{
linePoint.showGizmo = showGizmos;
linePoint.gizmoSize = gizmoSize;
linePoint.gizmoColor = gizmoColor;
}
}
}
``````

The result in the end is some cubes in this case 5 that are connected with lines and a transform that move on the positions of the lines not between the curved points(Cubes) but moving between the positions of the lines :

The problem is with the last script. When the game is running and then when I’m selecting one of the curved points(Cube) and drag it around in the scene window I see it changing it’s position and the line also change but in fact it’s not changing the positions of the line and the position of the curved point in the moving script the first script.

The moving platform is keep moving on the old positions as before and never moving on the new positions.

In this screenshot I moved the fourth curved point(Cube) dragged it around to the right top but the platform is still moving on the old line positions of the fourth curved point(Cube) position it was before I moved it.

I want to do that when I change the curved points(Cubes) and it’s changing also the lines positions that it will update the transform that should move on this positions.

If I’m not mistaken the last script should do it but it’s not.

In the last script in the Update hasReseted is false all the time :

``````public void Update ()
{
if (ResetLineRendererPositions.hasReseted == false)
{
GetPoints();
SetPointsToLine();
}
}
``````

even if I set for a second the hasReseted to true and then to false again and it’s clearing the LineRenderer all lines and positions and re generating them over again the transform platform will keep moving on the old positions.

## algorithms – Finding all pairs of points with no point in between

Suppose there are $$n$$ points $$p_1,p_2,dots,p_n$$ with color red or blue on a line. We want to find all pairs $$(p_i,p_j)$$ whose color is distinct and such that there are no points between them. If there are $$k$$ pairs with the described property, design an algorithm with $$O(nlog k)$$ that uses idea of divide and pruning.

I think if we check all points we can solve this problem, but running time will exceed $$O(nlog k)$$.

I think for solving this problem we can use projective geometry duality, but I am stuck. Any help would be appreciated.

## nt.number theory – Is there a planar rational point set within which the distance of any two points is an irrational number?

i.e. could we find a subset $$Xsubset mathbb{R}^2$$ such that $$Xsubset mathbb{Q}^2$$ and that for any $$x,yin X$$ the distance $$|x-y|$$ is an irrational number?

I’m considering the following assertion of which I’m not sure :

Given finite rational points $$p_1,p_2,dots,p_n$$ , and an open ball $$D$$ on the plane, there is a rational point $$xin D$$ such that $$|x-p_i|in mathbb{R}backslash mathbb{Q}$$ for $$i=1,2,dots,n$$.

But this assertion accounts to be the following seemingly number-theoretic problem:

Given $$n$$ pairs $$(a_i,b_i) (i=1,2,dots,n)$$ of positive integers such that $$a_i^2+b_i^2$$ is not square of any integer. Could we find an integer $$Ngeq 2$$ such that the integral pairs $$(Na_i+1,Nb_i)$$ still satisfy the previous property(i.e. $$(Na_i+1)^2+(Nb_i)^2$$ is not square of any integer).

BTW the distribution of the Pythagorean triples might help.