So there is this mathematical problem that I cannot solve. I will be happy if someone explains me the way that this needs to be solved with good explanation. So:
There are 10 balls in a bag - 3 white balls, 5 red balls and 2 blue balls. A guy is picking them up without seeing their color (all the balls are drawn at random). How many different ways there are for the guy to pick them up? And second question -> In how many cases there arent drawn two balls in the same color one after other?
For the first question i have a guess in the solvation. So there are 10 balls. If there is one vector with the size = 10, each ball will go in one place of this vector..
a1, a2, a3, ... , a10..
For a1 there are maximum 3 choises -> red, white and blue.. but what is next?
I will be glad if someone explains me with details.
Well, first you should know that Stack Overflow isn't really a site for discrete mathematics or similar areas. Try http://math.stackexchange.com. :)
But to answer your question:
You can draw 10 balls in 10! ways, right? However, you must exclude the numbers of same-color balls (because, obviously, drawing white ball no.1 and white ball no.2 is the same as drawing white ball no.2 and white ball no.1) - so, the number of ways is
10!/3!5!2!
For each permutation of ten (10!) there are 6 rearrangements of white balls, 120 rearrangements of red balls and 2 rearrangements of blue balls. So 10! has overcounted by 6x120x2 and the answer is just 10!/3!5!2!
Related
how I can measure distance of light to flower box? As I'm making a game where you can grow vegetables and I would like to make it so, that if lighting is more than 5 meters away, your vegetables wont grow. Also then when player picks up a light it would show distance to nearest flower box? They have their own tag of "flowerbox" and lights have their own "lights"
Thank you so much for your answers!
I could give you A solution, but it would make a lot more sense to craft a solution around your current work.
What you want to keep in mind is that if you're dealing with GameObjects in a 3D scene (something you didn't specify), you can find the distance between two objects by looking at their world positions (as opposed to their localPosition)
The distance between two GameObjects is simply:
var distance = (light.transform.position - flowerBox.transforn.position).magnitude;
That will give you a float value, which will be the distance in Unity units (defacto of 1 unit = 1 metre).
The magnitude docs are here.
This question already exists:
Do an SKAction if the colors of two sprites aren't the same? [duplicate]
Closed 6 years ago.
How can I check if, when I collide with an SKSpriteNode in the middle of two rectangles with a ball, the ball and the two rectangles are the same color?
For example, if my two rectangles are red, and my ball is blue, I want it to detect that the colors of my rectangle and the ball are different. If they are the same color, then I don't want anything to happen. If they aren't, I'll write the code that makes the player lose. But how can I detect the color difference when the ball collides the skspritenode located in the middle and in between the two rectangles?
My suggestion is that your change your "pair" of walls to become a trio of walls instead. This third wall should have a different categoryBitMask. (PhysicsCategory.wallSpace seems to fit with your current naming scheme.)
This "wallSpace" needs to be positioned between the two existing walls. It should be given the same color as its siblings through your color-change logic, but here comes the trick: set it's alpha to 0.
This way you can check for collisions between this invisible wall and your ball and perform actions based on the color-information.
I am new to Iphone. I want to draw a circle with different colors in it. And all the colors should cover equal area. Like if I want to have 10 different colors in it. Then each color should cover 1/10th area of the circle. I am not trying to draw a pie chart here. Also not trying to use 10 different colors. Just want 10 equal parts of circle and each part can be filled with colors.
I am trying to build a fortune wheel. Such that a smaller wheel is above the larger wheel. And then I want to drag them separately.
Also is it possible to do this with help of Core Animation?
Ambiguous question. If you draw a piechart with 10 equal areas then each will cover 1/10th of the area, thus fulfilling your request, no?
There are 360° in a circle, so divide that by 10 and each wedge should have a 36°. Now you just have to draw 10 wedges, and this page should help you:
http://www.raywenderlich.com/2106/core-graphics-101-arcs-and-paths
Since you say you don't want pie slices, do you want concentric rings instead?
And are you sure you want equal AREA? That will make the rings different thicknesses. The innermost ring will be fairly thick, and each ring as you go outward will be thinner. Much thinner, on the outer rings.
Our eyes are used to a bulls-eye formation, where each ring is the same thickness.
In any case, you should look at CAShapeLayer objects. You can create a shape layer for each ring that defines a closed path with 2 circles. There is something called the "winding rule" that lets you determine what happens when paths overlap. I think you'd want even-odd path winding (kCAFillRuleEvenOdd).
To make the rings equal area, you could do this:
First calculate the area of the whole circle. Divide by the number of rings. That's the desired area for each ring Let's call that area "a". Start from the center. The radius of that ring (a circle) will be sqrt(pi/a).
For each following ring you'll need to calculate the thickness of the ring based on the area of the outer circle minus the area of the inner circle that makes up the ring. You'll need to write an equation that solves for the outer radius given the desired area and the radius or the previous circle.
I have an image which looks like this:
I have a task in which I should circle all the bottles around their opening. I created a simple algorithm and started working it. My algorithm follows:
Threshold the original image
Do some morphological opening in it
Fill the empty holes
Separate the portion of the image using region props such that only the area equivalent to the mouth of the bottles is selected.
Find the centroid for each and draw circle around each bottle.
I did according to the algorithm above and but I have some portion of the image around which I draw a circle. This is because I have selected the area since the area of the mouth of bottle and the remained noise is almost same. And so I yielded a figure like this.
The processing applied on the image look like this:
And my final image after plotting the circle over the original image is like this:
I think I can deal with the extra circle, that is, because of some white portion of the image remained as shown in the figure 2 below. This can be filtered out using regionproping for eccentricity. Is that a good idea or there are some other approaches to this? How would I deal with other bottles behind the glass and select them?
Nice example images you provide for your question!
One thing you can use to detect the remaining bottles (if there are any) is the well defined structure of the placement of the bottles.
The 4 by 5 grid of the bottle should be relatively easy to locate, and when the grid is located you can test if a bottle is detected at each expected bottle location.
With respect to the extra detected bottle, you can use shape features like
eccentricity,
the first Hu moment
a ratio between the perimeter length squared over the area (which is minimized for a circle) details here
If you are able to detect the grid, it should be easy to located it as an outlier (far from an expected bottle location) and discard accordingly.
Good luck with your project!
I've used the same approach as midtiby's third suggestion using the ratio between area and perimeter called shape factor:
4π * Area /perimeter^2
to detect circles from a contour traced image (from the thresholded image) to great success;
http://www.empix.com/NE%20HELP/functions/glossary/morphometric_param.htm
Regarding the 4 unfound bottles, this is rather tricky without some a priori knowledge of what it is you're looking at (as discussed using the 4 x 5 grid, then looking from the centre of each cell). I did think that from the list of contours, most would be of the bottle tops (which you can test using the shape factor stuff), however, one would be of a large rectangle. If you could find the extremities of the rectangle (from the largest contour in terms of area), then remove it from the third image, you'd be left with partial circles. If you then contour traced those partial circles and used a mixture of shape factor/curve detection etc. may help? And yes, good luck again!
Does anyone know what kind of overhead CGRectContainsRect and CGRectIntersectsRect have?
I am trying to track and test a user gesture and am finding I am probably going to have to use a combination of both but not sure of the impact.
Imagine a grid of 5 squares and you want to test if the user drew a line from square 1 to 2.
Easy, CGRectContainsRect lets me know if the did draw only in square 1 and 2.
If they drew in say squares 1, 2 and 3 the same test would return false as CGRectContainsRect would say NO.
OK no lets say you want to test for drawing in squares 1,2 and 3 and the user only draws in square 1 and 2, CGRectContainsRect will return YES because rightly so the users stroke is within squares 1,2 and 3........but not actually in square 3 so a false reading is obtained!
You could iterate thru each of the 5 squares, checking CGRectIntersectsRect on each. For a larger array of squares this may become highly inefficient, but off the top of my head thats the best way I can think of.