Random walk problem in matlab

Can you write to me code matlab to this problem? I try many times and dont succses Problem 2.1. First-passage time. The first-passage time (FPT) is defined as the time it takes for a random walker to reach a certain target position for the first time. Consider a special case of the first-passage time: the first-return time, i.e. the time at which the random walker first returns to the origin. Let us denote the probability that this would happen at time t as F(t). Using your random walk data from the previous week (or generating new data, if you prefer), please make a histogram of first-return times of 105 symmetric random walks with step size ∆x = 1. Please do it for random walks whose duration is 104 steps, and also 105 steps. Plot the probability F(t) as a function of time. Now do the same but on a log-log scale. Use this to infer how F(t) falls with time for t >> 1.

Combining TWO Monte Carlo algorithms to get a Las Vegas algorithm that solves the same problem

I came across a problem that I have no clue how to solve.

Consider two Monte Carlo algorithms, called A and B that both solve the same problem. A is true-biased and t-correct, while B is false-biased and z-correct. Show that you can combine both A and B to obtain a Las Vegas algorithm to solve the same problem.

Also, how would I find the best value of R, which is the probability of the las vegas algorithm to find the right answer? For this second part, how would I find this fictional value of R with no concrete example or data set, this question seems completely out of left field.

Thank you kindly for your time 🙂

Number of gifts received problem

Assume we have N kids who all like dogs. One day they go to the shelter and there are M dogs of unique breeds. Each kid has a favorite dog breed and a second favorite dog breed. They are also lined up in order. Then way the dogs are selected are as follows. For the first kid in line, if their first choice breed is available, take it and leave. Else if, first not available and second is, take it and leave. Else, leave crying with no dog lol. We want to find, for each 0 <= i <= N – 1, determine how many kids would get a dog if the owner if the first i kids were removed from the line.

Example. 4 kids, 2 dog breeds(denoted as 1 and 2). Let’s say all 4 kids have breed 1 as first choice and breed 2 as second choice. The output should be 2,2,2,1. Because, if we remove the first 0 kids from line, only 2 get dogs. If we remove first kid from line, still 2 get dogs. If we remove first 2 kids from line, 2 get dogs. If we remove first 3 from line, 1 gets a dog. This is a trivial case.

Obviously a solution would be to have a list of the the kids preferences and a set of the available dog breeds, and then for each i, start from the ith index of the list, refresh the dog set, and simulate it, but that would take O(NM) time. Is there a way to do this more cleverly and efficiently?

Players get frustrated when they couldn’t solve a hard diplomatic problem, how to get them to think out of the box

Problem:

Players got themselves into a diplomatic problem that they know is probably above their pay grade in terms of difficulty. They spent a session trying to figure out this problem with talking to people, and rolling different charisma checks in order to try to persuade people they probably had no business persuading (rolls were average, arguments weren’t extremely compelling). The party didn’t plan any grand schemes, any extraordinary strategies, no clever ideas on the spot, but rather tried very basic head first dialogue.

This has happened in the past in regards to combat, and the party has with a recent deadly encounter had to think out of the box more (one player even said: “guys we need to plan more and think less about just hacking and slashing sometimes”). Now it’s a more diplomatic problem that doesn’t seem as easy as rolling a single charisma check and hoping it works out.

In the end, the party did not manage to solve the diplomatic problem (although there is room in the future for them to try again with the upper hand), and one of the players said they did not enjoy the session. Player enjoyment is my top priority. But I also think dnd is best when there’s risk, when you can fail rolls, when the PCs don’t always win (not that I actively seek this out though).

How can I get the party to perform less linearly in dialogue-related problems?

An example problem:

P: If trying to out smart a bad person with a lot of influence in the town

A: There are options for framing the person, bribing people, seeking dirt on this person to find their weakness, tarnishing their reputation, trying to prove their wrong doing by seeking out evidence, and a bunch of other possibilities.

I’ve tried to have a brief session-0 talk again about if they want dialogue-related problems handicapped, and they didn’t seem to take to that, but rather felt like they tried everything and didn’t know what else to do. I also did a postmortem on this problem and tried to give different options they could have tried, but I get a feeling the players feel like they still tried everything and failed and the session was “a waste” (even though they still got exp, still got some loot, and got some more plot).

Kind of at a loss of how to tackle this issue that isn’t just: “Go watch some dnd podcasts to get ideas, or go read X, Y, and Z resource on the subject”.

What do you call a greedy algorithm that solves a combinatorial problem by optimizing the best k>1 choices altogether?

Suppose you have a problem which goal is to find the permutation of some set $ S$ given in input that minimizes an objective function $ f$ (for example the Traveling Salesman problem).

A trivial algorithm $ E(S)$ that find the exact solution enumerates all the permutations and outputs the one that minimizes $ f$ . Its time complexity is $ O(n!)$ where $ n$ is the size of $ S$ .

A trivial greedy algorithm $ G(S)$ that finds an approximation of the solution is:

 out[0] = select a good starting item from S according to some heuristic h_1. S = S - {out[0]} for i=1 to n-1 do:     out[i] = select the next best element using some heuristic h_2     S = S - {out[i]} return out 

Where $ h_1$ and $ h_2$ are two heuristics. Its complexity in time is $ O(n^2)$ assuming that $ h_2$ runs in constant time.

Sometimes I mix the two techniques (enumeration and greedy) by selecting at each step the best $ k$ items (instead of the best one) and enumerating all their permutations to find the one that locally minimizes $ f$ . Then I choose the best $ k$ items among the remaining $ n-k$ items and so on.

Here is the pseudocode (assuming $ n$ is a multiple of $ k$ ):

 for i in 0 to n/k do:     X = select the best k items of S according to some heuristic h     S = S - X     out[i*k ... (i+1)*k-1] = E(X) return out 

Where $ E(X)$ is algorithm that find the exact solution applied on a subset $ X \subset S$ rather than on the whole $ S$ . This last algorithm finds an approximate solution and has a time complexity of $ O(\frac{n}{k}(n \log k + k! ))$ assuming that $ h$ can be computed in constant time. This complexity can be comparable to $ O(n^2)$ if $ k$ is small although according to my experience the performances can be way better than the greedy approach.

I don’t think I invented this kind of optimization technique: do you know its name? Can you please include some theoretical references?

I know for sure it is not beam search, because beam search never mixes the best $ k$ solutions found at each step.

Thank you.

Sub domain Redirect problem [closed]

When using a sub domain it redirects to my default page/domain. This only happens when using HTTPS.. for example

https://forums.example.net – takes me to mydomain.net …BUT http://forums.example.net – takes me to the forums

I’m using Apache2 & Ubunutu 18.04 using my own VPS.

((sites-enabled)) 000-default.conf RewriteEngine on RewriteCond %{SERVER_NAME} =bans.raiderzmc.net [OR] RewriteCond %{SERVER_NAME} =status.raiderzmc.net [OR] RewriteCond %{SERVER_NAME} =raiderzmc.net [OR] RewriteCond %{SERVER_NAME} =forums.raiderzmc.net RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

vim: syntax=apache ts=4 sw=4 sts=4 sr noet

DocumentRoot /var/www/html/raiderzmc.net/ ServerName raiderzmc.net

<Directory /var/www/html/raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

RewriteEngine on RewriteCond %{SERVER_NAME} =raiderzmc.net RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

DocumentRoot /var/www/html/bans.raiderzmc.net/ ServerName bans.raiderzmc.net

<Directory /var/www/html/bans.raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

RewriteEngine on RewriteCond %{SERVER_NAME} =raiderzmc.net [OR] RewriteCond %{SERVER_NAME} =bans.raiderzmc.net [OR] RewriteCond %{SERVER_NAME} =forums.raiderzmc.net RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

DocumentRoot /var/www/html/forums.raiderzmc.net/ ServerName forums.raiderzmc.net

<Directory /var/www/html/forums.raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

RewriteEngine on RewriteCond %{SERVER_NAME} =raiderzmc.net [OR] RewriteCond %{SERVER_NAME} =forums.raiderzmc.net RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]

DocumentRoot /var/www/html/status.raiderzmc.net/ ServerName status.raiderzmc.net

<Directory /var/www/html/status.raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

SSL Config – 00-default-le-ssl

DocumentRoot /var/www/html/raiderzmc.net/ ServerName raiderzmc.net

<Directory /var/www/html/raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

Include /etc/letsencrypt/options-ssl-apache.conf ServerAlias forums.raiderzmc.net ServerAlias bans.raiderzmc.net ServerAlias status.raiderzmc.net SSLCertificateFile /etc/letsencrypt/live/bans.raiderzmc.net-0001/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/bans.raiderzmc.net-0001/privkey.pem DocumentRoot /var/www/html/forums.raiderzmc.net/ ServerName forums.raiderzmc.net

<Directory /var/www/html/forums.raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

DocumentRoot /var/www/html/bans.raiderzmc.net/ ServerName bans.raiderzmc.net

<Directory /var/www/html/bans.raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

DocumentRoot /var/www/html/status.raiderzmc.net/ ServerName status.raiderzmc.net

<Directory /var/www/html/status.raiderzmc.net/>     Options +Indexes +FollowSymLinks +MultiViews +Includes     AllowOverride FileInfo Options     Order allow,deny     allow from all </Directory> 

Is destructuring a heap (taking down a heap) also O(n) like building a heap? If so, can the selection problem be solved by this method in O(n) time?

If we can build up a heap with time O(n), can we take down a heap also by O(n)? (by delete-max repeatedly).

Intuitively, it may feel it is, because it is like the reverse of build it up.

If building a heap is O(n) in the worst case, including the numbers are all adding by ascending order, then taking the heap down is exactly the “reverse in time” operation, and it is O(n), but this may not be the “worst case” of taking it down.

If taking down a heap is really O(n), can’t the selection problem be solved by building a heap, and then taking it down (k – 1) time, to find the kth max number?

Router is the problem?

So when i am adding a massive number of sites to GSA without fail my internet access is  stopped.  I have to go back in to the router settings. Save the settings  and  it is restored. What can i do to stop this problem?

Need help with an interesting variant of the travelling salesman problem

I’m working on an assignment in my CS class and the gist of the problem is as follows.

A salesman has a map of some apartments (over 300 blocks). I am given the (x,y) coordinates of each block as well as the “money” he will earn by visiting each block. I need to find the shortest route for the salesman to take such that he will earn x amount of money. He does not have to visit all the blocks. At the end of the day he will have to return to the origin (0,0).

I used a greedy algorithm by finding the shortest possible path he can take at each step. E.g from the origin I find the block with the lowest euclidean distance from the origin. Lets say this block is (2,2). I then find the block with the lowest euclidean distance from (2,2) until I have x amount of money. Using this greedy algorithm I then performed a 2-opt local search to improve my solution further.

The problem lies here though: when I perform a 3-opt local search using the implementation from wikipedia (https://en.wikipedia.org/wiki/3-opt), I get a much worse result than either the greedy or the 2-opt. Is there something wrong with the wiki code and if not, what did I do wrong? Thanks.