Chance to crash? [closed] - math

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I looked at the game superloop.
You are a character which is either red, green, blue, or yellow. You get a shape assigned: either triangle, quad, pentagon, or circle.
You are traversing on one of three lanes on which are obstacles which are aligned to form a wall on the lanes. You can pass those obstacles if your character matches the shape or color.
The obstacles are all unique ( no one shares the color nor shape).
My question: Is there a chance to not pass through the barrier of obstacles?

I do not really get the question. However If you have one of 4 colors. Moreover you have one of 4 shapes so there are 16 combiations of your character.
To pass obstacle you have to be matched to its color or shape, so with 10 different obstacles there is 100% chance to pass . You are able to create 9 different obstacles character will not pass.
Lets say we use two groups of variables {1,2,3,4} and {a,b,c,d}. Character is 2c, so all the obstacles impassible to be passed are:
1a, 1b, 1d
3a, 3b, 3d
4a, 4b, 4d
10th combination will always match.
Mathematically if you have two groups of x and y elements there is no more than (x-1)(y-1) possibilities of "not passing", and in group of (x-1)(y-1)+1 unique "obstancles" you will always pass at least once.

Related

If I have N distinct points, how many different ways can I construct a set of distinct points? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 6 years ago.
Improve this question
Lets say that I have 2 groups of distinct points. I'm trying to find all the possible different ways to travel between these points. In one group we have P1,P2 and in the other group P3,P4. Any point can be a starting point and can only end in the opposing group. I want to find a way to formalize how to find all combinations of these points. Each group can have an N distinct number of points, but I chose for each group to have 2 points. These are all the possible set of points from these two groups:
Set 1: P1->P2->P3->P4
Set 2: P1->P2->P4->P3
Set 3: P2->P1->P3->P4
Set 4: P2->P1->P4->P3
Set 5: P3->P4->P2->P1
Set 6: P3->P4->P1->P2
Set 7: P4->P3->P2->P1
Set 8: P4->P3->P1->P2
The "->" denotes a path traveled. Therefore I have 8 distinct paths traveled. How do I formalize this though? I've tried thinking of exponents, and factorials... I'm a bit stuck right now.
You have a bipartite graph, with n vertices on each side.
Choose your starting point on the left: n options.
Choose your destination on the left: n-1 options.
Choose your next destination on the left: n-2 options remaining.
etc...
Then choose a destination on the right: n options.
Then choose your next destination on the right: n-1 options remaining.
etc...
Then multiply that out and also take into consideration the fact that you can start on the right-hand side instead of the left.
(Also... this question perhaps will be migrated to a math board.)

Algorithm that finds unique numbers that equal N(or an inputed number) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
language agnostic question but I wanted to know if anyone can provide guidance logically on how to create a set that through adding or subtracting could generate any number between 1 and N.
An idea.
If we used only summation, then the set consisting of powers of 2 less or equal than N would be such a minimal set. With subtraction, the powers of 3 seems to be an idea good enough for start. I suspect it may be minimal but don't have a proof.
My reasoning is the following. Suppose we have k numbers in the set. Then there are at most 3^k possible results we can get with summation and subtraction. (Note that those results contain negative integers. In fact, such a set of results is symmetric with respect to 0. And, usually, we'll get fewer than 3^k different results - some of them will simply repeat).
An example of "optimal" choice:
Let's take the first number equal to 1. Then the possible results are: -1, 0, 1. Next, take 3 - then we'll get all integers between -4 and 4. (Choice of number 2, instead of 3, is clearly inefficient.) Then, to obtain the next contiguous (and non-overlapping) sequence of integers we should take 9. And so on, until number N is reached.
We could use other numbers instead of powers of 3. In such a case, we should take care of gaps that will results in consecutive steps. And I doubt it would produce a set with fewer elements. (I may be wrong, though.)
Sort all numbers.
Remove duplicates that are next to each other (is current equal to previous?)
Add / Subtract the remains.

How to approach grid type problems? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.
How many such routes are there through a 20×20 grid?
In the 2x2 case you have 6 possible ways you say. (So I infer from that that you actually move from grid-point to grid-point rather than from cell to cell):
(r,r,d,d), (r,d,r,d), (r,d,d,r), (d,r,d,r), (d,d,r,r), (d,r,r,d).
Note that we always have 2 'd's and 2 'r's. And we always have 4 moves (_ , _, _, _).
Also note, that if you just place the 'r's at the 4 moves, then it is implicitly clear where the 'd's will go, i.e. if you put a 'r' at position 1 and 3 then you will have an 'd' at positions 2 and 4.
Hence you can think of it as: "how many ways are there to distribute 2 'd's to 4 possible positions?". You have to choose 2 elements out of 4.
This is the well known binomial coefficient (https://en.wikipedia.org/wiki/Binomial_coefficient) "n choose k". In your case "4 choose 2" (among the 4 choices pick 2) which happens to be 6.
So, now I leave it as an exercise to you: on a 20x20 grid what is your 'n' and what is your 'k'?
The other problem you might run into is how to actually compute the value. But I'm sure you'll figure it out. Just have a close look at the wikipedia page about the binomial coefficient, you might find something useful there.

General Graph Cycle Detection (Confirm my Answer please) [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
The problem:
An undirected graph is unicyclic if it contains exactly one cycle. Describe an O( |V| + |E| ) algorithm for determining whether or not a given graph, G is unicyclic.
My solution:
int i = 0
Run a modified DFS on G, where we increment i everytime we decide not to visit a vertex because it has already been visited.
After DFS is done, if i==1, graph is unicyclic.
I thought this solution would work but am wondering if there is a counter example that would prove it false. If anyone could clarify that would be great, Thanks.
Does your graph consists of a single connected component?
In this case just count vertices and edges and check |V| - |E| = 0
Otherwise count the number of connected components O(|V| + |E|),
and check |V| - |E| = number of connected components - 1.
Remark: having more than one connected component is a counterexample to your algorithm.
"Increment i everytime we decide not to visit a vertex because
it has already been visited."
I am quite unclear about what you are trying to do here.
Rather then this, how about this:
Perform DFS and count number of back edges.
A back edge is an edge that is from a node to itself (selfloop) or one of its
ancestor in the tree produced by DFS.
If number of back edges ==1 then unicycle else not.
To count number of back edges, follow this algorithm.
To detect a back edge, we can keep track of vertices currently in recursion stack of
function for DFS traversal. If we reach a vertex that is already in the recursion stack,
then there is a cycle in the tree. The edge that connects current vertex to the
vertex in the recursion stack is back edge

Scrabble - the best move [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I have made algorithm for scrabble . It uses strategy of highest score . But I do not think that is is the best way to play the game.
My question is: is there any advanced math for scrabble that suggests not the highest score word but an other one that will increase the probability to win?
Or in other words some different strategy then highest score?
I have my own ideas how it can be. For example, suppose there are two words that have almost the same score (s1 > s2) but lets say the second word does not open new way to 3W or 2W and even its score is less then the score of first one, than it is good to use the second word and not the first one.
From my experience with scrabble, you are correct in that you don't necessarily want to always suggest the highest scoring word. Rather, you want to suggest the best word. I don't think this requires a lot of advanced math to pull off.
Here are some suggestions:
In your current algorithm, rank all your letters, particularly consonants, by ease of use. For example, the letter "S" would have the highest ease of use because it is the most flexible. That is, when you play a given word and leave out the letter "S", you are essentially opening up the possibility for better word choices with the new letters than come into play on your next turn.
Balance out vowel and consonant usage in your words. As a regular scrabble player, I don't always play the best scoring word if the best scoring word doesn't use enough vowels. For example, if I use 4 letters than contain no vowels and I have 3 vowels left in my array of letters, chances are I am going to draw at least two vowels on my next turn, which would leave me with 5 vowels and 2 consonants, which chances are doesn't open up a lot of opportunity for high scoring words. It is almost always better to use more vowels than consonants in your words, especially the letter I. Your algorithm should reflect some of this when selecting the best word.
I hope this gives you a good start. Once your algorithm is able to select the best scoring word, you can fine tune it with these suggestions in order to be an overall better scorer in your scrabble games. (I am assuming this is some sort of AI you are creating)
My question is: is there any advanced math for scrabble that suggests not the highest score word but an other one that will increase the probability to win?
As ROFLwTIME mentioned, you need to also account for the letters that you haven't played.
In doing that accounting, you need to account for how letters interact with one another. For example, suppose you have a Q, a U, and five other letters. Suppose the best you can score playing both the Q and the U is 30 points, but you can score more by playing the U but leaving the Q unplayed. Unless that "more" is much more than 30, either play the word with the Q or find a third word that leaves both the Q and the U unplayed.
You also need to account for the opportunities the word you play creates for your opponents. A typical game theory strategy is to maximize your score while minimizing your opponents score, maximin for short. Playing a 20 point word that allows your opponent to play a 50 point word is not a good idea.

Resources