Need help:
I have a number (let's say 550) and need to create a perfect distributed SEQUENCE of length N where SUM of numbers will give this number (550).
Something like: 10, 20, 30, 40, 50, 60, 70, 80, 90, 100
The only input I have is the length of sequence and the final sum of it's numbers.
Thank you.
=INDEX(SEQUENCE(length;1;1)*2*sum/length/(length+1);;)
So here are some possible starting values (a) and increments (d) that satisfy the conditions where the number of terms n is 10 and the sum S is 550:
Using the formula
=MAKEARRAY(S/n,2,LAMBDA(r,c,if(c=1,r,2/(n-1)*(S/n-r))))
The formula is obtained by re-arranging the standard formula for an arithmetic progression to get d (the increment) in terms of a (the starting value, S (the sum) and n (the number of terms):
Here are the integer pairs using
=lambda(pairs,filter(pairs,index(pairs,,2)=int(index(pairs,,2))))(MAKEARRAY(S/n,2,LAMBDA(r,c,if(c=1,r,2/(n-1)*(S/n-r)))))
Here are the actual series using
=lambda(intpairs,makearray(rows(intpairs),n,lambda(r,c,index(intpairs,r,1)+(c-1)*index(intpairs,r,2))))(lambda(pairs,filter(pairs,index(pairs,,2)=int(index(pairs,,2))))(MAKEARRAY(S/n,2,LAMBDA(r,c,if(c=1,r,2/(n-1)*(S/n-r))))))
It can be verified that each series totals to 550.
Once you have the values of a and d, you can also use Sequence to generate the results:
=sequence(1,n,F10,G10)
if your issue is to divide value x into equal chunks y try:
=INDEX(SEQUENCE(B1, 1)*A1/B1)
or starting from 0:
=INDEX(SEQUENCE(B1, 1, 0)*A1/(B1-1))
Related
I have a google sheet that I am using to try and calculate leveling and experience points. Column A has the level and Column B has the exp needed to reach the next level. i.e. To get to Level 3 you need 600 exp.
A B
1 200
2 400
3 600
...
99 19800
In column I2 I have an integer for an amount of exp (e.g. 2000), in column J2 I want to figure out what level someone would be at if they started from 0.
Put this in column J and ddrag down as required. Rounddown(I2,-2) rounds I2 down to the nearest 100. Index match finds a match in column B and returns the value in column A of the matched row.
=index(A2:A100,match(ROUNDDOWN(I2,-2),B2:B100,0))
Using a helper column (for example Z): put =sum(B$1:B1) in cell Z1 and drag down. This will compute the sums required for each level. In J2, use the formula
=vlookup(I2, {B:B, Z:Z}, 2) + 1
which looks up I2 in column B, and returns the nearest match that is less than or equal to the search key. It adds 1 to find the level that would be reached, because your table has this kind of an offset to you: the entry against level N is about achieving level N+1.
You may want to put 0 0 on top of the table, to correctly handle the amounts under 200. Or treat them with a separate if condition.
Using algebra
In your specific scenario, the point amount required for level N can be computed as
200*(1+2+3+...+N-1) = 200*(N-1)*N/2 = 100*(N-1/2)^2 - 25
So, given x amount of points, we can find N directly with algebra:
N = floor(sqrt((x+25)/100)+1/2)
which means that the formula
=floor(sqrt((I2 + 25) / 100) + 1/2)
will have the desired effect in cell J2, without the need for an extra column and vlookup.
However, the second approach only works for this specific point values.
I have, say, in A1 a text containing a sorted (eventually reversed) list of integers separated by some not-digit-char - for example "10, 123, 230, 750, 1034, 2003, 10101"; in B1 I have an integer n; I need a formula not involving other cells that returns:
n if n belongs to the list in A1;
otherwise, if n is not bigger than the maximum value in A1, the value in A1 immediately bigger than n (e.g., for n = 567 the returned value must be 750);
otherwise, an error.
In my opinion, the only way to solve the problem concerns regexp substitution (that Google Sheet supports), but until now I can't find a reasonable way to proceed.
Someone has a (different) idea?
Please try:
=index(SORT(TRANSPOSE(SPLIT(A1,", ")),1,0),
MATCH(B1,SORT(TRANSPOSE(SPLIT(A1,", ")),1,0),-1))
in this formula I used search_type = -1 for match function:
MATCH(search_key, range, search_type)
search_key - The value to search for. For example, 42, "Cats", or
I24.
range - The one-dimensional array to be searched. If a range with both height and width greater than 1 is used, MATCH will return #N/A!.
search_type - [ OPTIONAL - 1 by default ] - The manner in which to
search.
1, the default, causes MATCH to assume that the range is sorted in ascending order and return the largest value less than or equal to
search_key.
0 indicates exact match, and is required in situations where range is not sorted.
-1 causes MATCH to assume that the range is sorted in descending order and return the smallest value greater than or equal to search_key.
Simplify the case
Suppose you have a cell with text sorted in descending:
The formula would be:
=index(SPLIT(A1,", "),MATCH(B1,SPLIT(A1,", "),-1))
Please try:
=if(isnumber(find(B1,A1)),B1,index(split(A1,","),match(B1,split(A1,","),1)+1))
Above won't work for numbers lower than the first, but if required could be expanded to:
=if(B1<1*left(A1,find(",",A1)-1),1*left(A1,find(",",A1)-1),if(isnumber(find(B1,A1)),B1,index(split(A1,","),match(B1,split(A1,","),1)+1)))
I am setting up a Golf index calculator and I need help taking the last 20 entries for an average. The formula is suppose to take the average of the smallest 10 numbers of the last 20 games played. So far all I have is:
average(small(i2:i21, 10))
I would not like to change the row numbers every time I put in a new entry.
The small function returns one element from a range - in your case, the 10th smallest element, not the 10 smallest elements. This doesn't help much here. For your purpose, the combination of sort (sort in increasing or decreasing order) with array_constrain (keep only a given number of elements) works well.
=average(array_constrain(sort(array_constrain(sort(filter({I2:I, row(I2:I)}, len(I2:I)), 2, false), 20, 1)), 10, 1))
or with linebreaks
=average(
array_constrain(
sort(
array_constrain(
sort(
filter({I2:I, row(I2:I)}, len(I2:I)),
2, false),
20, 1)
),
10, 1)
)
The array {I2:I, row(I2:I)} contains row numbers in the second column. Keeping only nonempty entries in I column, we sort by the row numbers in descending order. Then keep only the first 20 entries from I column. Sort again (by default: increasing), and keep 10 entries. Finally, average is taken.
I have a Google Spreadsheet of numbers. How do I take the maximum value from each column, and summarize them using only one formula? (No temp cells, no scripts.)
1 2 1
0 1 3
0 2 0
For the table above the result should be 6 (1+2+3, the maximum value of each column). But I'd like a solution that works for much larger tables, too.
As a more general question, I'd like to find out how I could fold 2D ranges into 1D arrays using an arbitrary operator (like MAX and SUM in this case).
Assuming your data in range A2:D, to get the maximum of every row (array output) try
=query(transpose(query(if(row(A2:D)>=transpose(row(A2:D)),transpose( A2:D)),"select max(Col1),max(Col2),max(Col3),max(Col4) ",0)),"Select Col2", 0)
If you need to process a lot of columns, this may be better
=ArrayFormula(QUERY(TRANSPOSE(QUERY(TRANSPOSE( A2:D) , "Select "&"MAX(Col"&JOIN( ", MAX(Col",ROW(INDIRECT( "YY1:YY"&ROWS(A2:A)))&")"))), "Select Col2", 0))
To sum, just wrap SUM() around the above formulas.
MAX by columns in A1:C3
=INDEX(QUERY({A1:C3},"Select "&"MAX(Col"&JOIN(", MAX(Col",SEQUENCE(COLUMNS(A1:C3))&")"),0),2)
MAX by rows in A1:C3
=TRANSPOSE(INDEX(QUERY(TRANSPOSE(A1:C3),"Select "&"MAX(Col"&JOIN(", MAX(Col",SEQUENCE(ROWS(A1:C3))&")"),0),2))
Substitute MAX with MIN to get the minimums.
I have some data that needs to be summed but I would like to set the maximum value at 20, so sum the values but the greatest number that would be returned is 20.
For example, let's say I have three columns labeled A, B, and C. If in row one, the values are 5, 5, 5, the sum should be 15. But if they are 10, 10, 10, I would like the "sum" to show 20 instead of 30.
I have been playing around the the GT() function, but I would not like to create a new column just for comparisons. I would like it all to be in one cell. What would be a simple way of doing this?
=MIN(20, SUM(A1:C1))
maybe? That's what I'd use in Excel...