Figuring out how to work out n-turple questions? - math

Just as a side note, this isn't asking someone to help with homework it's just a example question in my lecture notes that i'm not grasping and would greatly appreciate if someone could explain to me how exactly to work it out.
It says simply this:
Let G = {3,5,7}. Write down some examples of 4-tuples.
Thank you to anyone who tries to help, this is mathematics to understand a systems unit :)

Your collection G is a set, which is unordered and non-repeating, containing three elements. You want some 4-tuples, which is an ordered collection of possibly-repeating elements, and there must be 4 elements.
We show tuples by using parentheses around the collection, while a set like G is written using braces (curly brackets). Some examples of 4-tuples using the elements of G are
(3, 3, 3, 3)
(3, 3, 3, 5)
(3, 3, 3, 7)
(3, 3, 5, 3)
...
(7, 7, 7, 5)
(7, 7, 7, 7)
That list of mine was in a particular order, called the lexigraphical order. Since there are 4 elements and each element has 3 choices regardless of the other choices, the total number of 4-tuples is
3x3x3x3 = 81
As another answer implied, your question is somewhat ambiguous. I assumed that each 4-tuple was to have elements taken from your set G, but your question did not actually say that. It does seem to be implied, however.

A 4-tuple, in math, is any vector populated with 4 objects. An example of a 4-tuple is {1, 5, 3, 7}.
Without more context, I can't use the fact that G = {3, 5, 7}.

Related

Create Vector of Length n in Julia

I want to create a vector/array of length n to be filled afterwards.
How can I do that?
And does it have to be filled already with something?
For example if you want a Vector of Ints of length 10 you can write
v = Vector{Int}(undef, 10)
And more general for an Array of Ints of dimensions (2, 3, 4)
a = Array{Int}(undef, (2, 3, 4))
Note that this fills the Vector/Array with garbage values, so this can be a bit dangerous. As an alternative you can use
v = Vector{Int}()
sizehint!(v, 10)
push!(v, 1) # add a one to the end of the Vector
append!(v, (2, 3, 4, 5, 6, 7, 8, 9, 10)) # add values 2 to 9 to the end of the vector
sizehint! is not necessary, but it can improve performance, because it tells Julia to expect 10 values.
There are other functions such as zeros, ones or fill that can provide a Vector/Array with already filled in data.

Print all values greater than some value without using booleans in R?

anyone got any idea how to print element greater than some value from a set without using booleans?
E.g., suppose I have the set x, which includes the elements (1, 4, 6, 3, 5, 2, 9).
Obviously, we can print all the values of x greater than 5 using the following code:
x[x>5]
But this way of coding uses booleans (it uses TRUE, FALSE etc.)
But is there any way to do this using solely integers?
I was thinking about some sort of loop that would start contain the number of elements, and then do
x[c(variable)]
but I don't know really.
Please help?

Absolute difference between a vector and a number in R

I'm new to R and I would be very grateful for an answer to my question:
I've got a vector: c(9, 11, 2, 6, 10) and the number 4 (or a vector c(4))
I want to generate a vector with the absolute difference between the first and the second one, which should look like this: c(5, 7, 2, 2, 6)
How do I do this? I can't get it to work with diff(), even after reading through the help (?diff()).
Any help is appreciated :)
x <- c(9, 11, 2, 6, 10)
abs(x - 4)
#[1] 5 7 2 2 6
abs finds the absolute value of a vector. '4' will be recycled when subtracted from x. If you have multiple values to be subtracted, they will also be recycled with a warning unless they are the same length as x.
You ran into problems with diff because it isn't designed for scalar subtraction (what you are attempting). It is better suited to finding the difference within a vector.

Picking fair teams - and the math to prove it

Application: similar to picking playground teams.
I must divide a collection of n sequentially ranked elements into two teams of n/2. The teams must be as "even" as possible. Think of "even" in terms of playground teams, as described above. The rankings indicate relative "skill" or value levels. Element #1 is worth 1 "point", element #2 is worth 2, etc. No other constraints.
So if I had a collection [1,2,3,4], I would need two teams of two elements. The possibilities are
[1,2] & [3,4]
[1,3] & [2,4]
[1,4] & [2,3]
(Order is not important.)
Looks like the third option is the best in this case. But how can I best assess larger sets? Average/mean is one approach, but that would result in identical rankings for the following candidate pair which otherwise seem uneven:
[1,2,3,4,13,14,15,16] & [5,6,7,8,9,10,11,12]
I can use brute force to evaluate all candidate solutions for my problem domain.
Is there some mathematical/statistical approach I can use to verify the "evenness" of two teams?
Thanks!
Your second, longer example, does not seem uneven (or unfair) to me. In fact, it accords with what you seem to think is the preferred answer for the first example.
Therein lies the non-programming-related nub of your problem. What you have are ordinal numbers and what you want are cardinal numbers. To turn the former into the latter you have to define your own mapping, there is no universal, off-the-shelf approach.
You might, for example, compare each element of the 2 sets in turn, eg a1 vs b1, a2 vs b2, ... and regard the sets as even enough if the number of cases where a is better than b is about the same as the number of cases where b is better than a.
But for your application, I don't think you will do better than use the playground algorithm, each team leader chooses the best unchosen player and turns to choose alternate. Why do you need anything more complicated ?
The numbers represent rankings? Then no, there is no algorithm to get fair teams, because there's not enough information. It could be that even the match-up
[1] & [2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]
is stacked against the large-team. This would be the case, for example, for chess-teams, if the difference between [1] and [2] was large.
Even the matchup you mentioned as being "unfair":
[1,2,3,4,13,14,15,16] & [5,6,7,8,9,10,11,12]
Could be completely fair in a game like baseball. After all, players 13-16 still need to bat!
So, probably the most fair thing to do would be to just pick teams randomly. That would also avoid any form of "gaming" the system (like my friends and I did in gym class in high school :) )
I don't think there's enough information to determine an answer.
What does it really mean for someone to be #1 vs #2? Are they 50% better, or 10% better or 1% better? How much better is #1 vs #5? It's really the algorithm to assign a value that needs to be accurate, and the distribution algorithm needs to reflect this properly.
For example, like I said, if you have Kobe Bryant mixed in with a bunch of high school basketball kids, what would the relative values be? Because in basketball, Kobe Bryant could single-handedly beat all the high school kids. So would his rank be #1, and the rest of the kids be #1000+?
As well, you have to assume that the value determination takes into account the size of a team. Does the team only need 2 players? Or does it need 10? In latter case, then in your second example, the 2nd team seems okay because the top 4 players would be playing with 6 much worse players, which could affect the success.
If all you are doing is distributing values, and if the notion of "fairness" is built into the value system, then the mean values seem to be a fair way to distribute the players.
You need an iterative ranking approach, with automated picking to produce evenly ranked teams on each iteration. This works even when the mix of participants changes to some extent over time. I created a tool to do just this for my 5-a-side group and then opened it up to allcomers if you google for "Fair Team Picker"
The pattern from above.
Team A: 1, 4, 5, 8, 9, 12, 13, 16
Team B: 2, 3, 6, 7, 10, 11, 14, 15
Snakes through the list using the pattern
A-B-B-A; A-B-B-A; etc.
This selection is pretty easy to code. Place all the ordered list of players into pairs. Reverse every odd # pair (assumes 1st pair is 0th group).
However, there is a "better" way to make teams using the Thue-Morse algorithm. For a more in-depth description of of this algorithm see: https://www.youtube.com/watch?v=prh72BLNjIk
Aren't the teams equal if each "round" of picking is simply done in reverse order of the preceding round? If there are 10 players whose talent is 1-10 and we are creating 5 teams (2 players each), the first round through, the first pick would obviously pick the best player (talent level 10). Then next pick would be 9, and so on. The 5th pick would get the play with the talent level of 6. In the second round, the pick order is reversed, so the team that just got talent level 6 would pick talent level 5 (the highest left) and so on until the captain who picked first in the 1st round would get the last player (talent level 1). Thus each team has a talent level of 11, with one team having 10 and 1, the next having 9 and 2, and so on. This would work for as many players/teams as there are.
Firs one selects 1. From then on they take turns choosing 2.
Assuming:
An even number of elements to choose
Every chooser gives the same value to each element
The value of the elements is very similar but different
Lower is better
[BEST] Firs one selects 1. From then on they take turns choosing 2:
16 items average
Team 1: 1, 4, 5, 8, 9, 12, 13, 16 8.5
Team 2: 2, 3, 6, 7, 10, 11, 14, 15 8.5
14 items average
Team 1: 1, 4, 5, 8, 9, 12, 13 7.42857
Team 2: 2, 3, 6, 7, 10, 11, 14 7.57143
Choosing first 1, second 2 and then 1 each:
16 items average
Team 1: 1, 4, 6, 7, 10, 11, 14, 15 8.875
Team 2: 2, 3, 5, 8, 9, 12, 13, 16 8.125
14 items average
Team 1: 1, 4, 5, 8, 9, 12, 13 7.42857
Team 2: 2, 3, 6, 7, 10, 11, 14 7.57143
[WORST] Comparing with selecting 1 each:
16 items average
Team 1: 1, 3, 5, 7, 9, 11, 13, 15 8
Team 2: 2, 4, 6, 8, 10, 12, 14, 16 9
16 items average
Team 1: 1, 3, 5, 7, 9, 11, 13 7
Team 2: 2, 4, 6, 8, 10, 12, 14 8

Getting Unique Number Combinations

Is it possible without using exponentiation to have a set of numbers that when added together, always give unique sum?
I know it can be done with exponentiation (see first answer): The right way to manage user privileges (user hierarchy)
But I'm wondering if it's possible without exponentiation.
No, you can only use exponentiation, because the sum of lower values have to be less than the new number to be unique: 1+2=3 < 4, 1+2+4=7 < 8.
[EDIT:]
This is a laymen's explanation, of course there are other possibilities, but none as efficient as using exponentials of 2.
There's a chance it can be done without exponentation (I'm no math expert), but not in any way that's more efficient than exponentation. This is because it only takes one bit of storage space per possible value, and as an added plus you can use boolean operators to do useful stuff with the values.
If you restrict yourself to integers, the numbers have to grow at least as fast as an exponential function. If you find a function that grows faster (like, oh, maybe the Ackermann function) then the numbers produced by that will probably work too.
With floating-point numbers, you can keep adding unique irreducible roots of primes (sqrt(2), sqrt(3), sqrt(5), ...) and you will always get something unique, up until you hit the limits of floating-point precision. Not sure how many unique numbers you could squeeze out of it - maybe you should try it.
No. To see this directly, think about building up the set of basis values by considering at each step the smallest possible positive integer that could be included as the next value. The next number to add must be different from all possible sums of the numbers already in the set (including the empty sum, which is 0), and can't combine with any combination of numbers already present to produce a duplicate. So...
{} : all possible sums = {0}, smallest possible next = 1
{1} : all possible sums = {0, 1}, smallest possible next = 2
{1, 2} : all possible sums = {0, 1, 2, 3}, smallest possible next = 4
{1, 2, 4} : a.p.s. = {0, 1, 2, 3, 4, 5, 6, 7}, s.p.n. = 8
{1, 2, 4, 8} ...
And, of course, we're building up the binary powers. You could start with something other than {1, 2}, but look what happens, using the "smallest possible next" rule:
{1, 3} : a.p.s. = {0, 1, 3, 4}, s.p.n. = 6 (because 2 could be added to 1 giving 3, which is already there)
{1, 3, 6} : a.p.s. = {0, 1, 3, 4, 6, 7, 9, 10}, s.p.n = 11
{1, 3, 6, 11} ...
This sequence is growing faster than the binary powers, term by term.
If you want a nice Project-Euler-style programming challenge, you could write a routine that takes a set of positive integers and determines the "smallest possible next" positive integer, under the "sums must be unique" constraint.

Resources