Choose random number from non-continuous range - ruby-on-rails

I am trying to get a random number between 3, 4, and 26-29.
I have tried rand(3, 4, 26..29), but was unsuccessful. Theses are product id numbers that I am trying to assign object to randomly.
Any help is beneficially and welcomed.

There may be a nicer syntax, but this should do the trick :
([3,4]+(26..29).to_a).sample

Related

How to check multiple ranges for different values in Google Sheets

I'm trying to search 3 different ranges in a tab, and trying to display Yes if all three values (email address, name, x) are found in those ranges. Basically, trying to have the formula confirm that yes, all three of those inputs are somewhere in those ranges (order doesn't matter).
Maybe I should use query or regexmatch or something? Any help is appreciated
Tried this formula:
=IF(AND('Helper Calculations'!$I:$I=$A$1,'Helper Calculations'!$J:$J=L$1,'Helper Calculations'!$L:$L=$A2),"Yes","No")
Was expecting that if the search term in each of those cells ($A$1, L$1, $A2) is found somewhere in the corresponding ranges, then it would say Yes
You can try with this (you can change the use of asterisks by wrapping in AND:
=IF(COUNTIF('Helper Calculations'!$I:$I,$A$1)*COUNTIF('Helper Calculations'!$J:$J,L$1)*COUNTIF('Helper Calculations'!$L:$L=$A2),"YES,"NO")
try:
=INDEX(IF(('Helper Calculations'!I:I=A1)*
('Helper Calculations'!J:J=L1)*
('Helper Calculations'!L:L=A2), "Yes", "No"))
Took a bit more work than I expected, but I got this working. I needed to verify that all 3 values were correct in a single row (must all be correct on that one row, can't find the correct values on multiple rows).
In order to do that, I needed to use array formula, and then decided to use index match and concatenate for the 3 values.
Process described here: https://www.ablebits.com/office-addins-blog/google-sheets-index-match/
correct formula: =IF(ArrayFormula(INDEX('Helper Calculations'!$I:$I,MATCH(CONCATENATE($A$1,L$1,$A2),'Helper Calculations'!$I:$I&'Helper Calculations'!$J:$J&'Helper Calculations'!$L:$L, 0),))=$A$1,"Y"))

Assign point values to Sheets checkboxes and find sum

I am using Google Forms to create a survey with weighted answers. I've been able to make things work when there is just one possible correct answer - I made a separate tab with a set of answer tables with point values assigned, then used vlookup to call back and match the given response to the answer table and fetch the assigned point value.
=VLOOKUP(P2, Sheet2!$A$49:$B$50, 2, FALSE)
P2 is a value pulled from the "Form Responses" tab - in this case, a yes/no answer. Sheet 2 has a table for each question with the possible answers and the point values for each answer (A49=yes, A50=no)
However, for some of the questions, multiple answers are valid and I want to add up the total number of points for that given question. So for example:
What are your hobbies? and folks can choose from
Riding your bike
Playing football
Swimming
Going fishing
Painting
And the respective point values are 2, 2, 3, 4, 4
So then, if someone chose the "Swimming" and "Going fishing" checkboxes in the form, I'd get "7", and if someone chose "Riding your bike", "Playing football", and "Painting", I'd get "8".
I realize that the output from the Google form will list the chosen answers all in one cell (Playing football, Going fishing), so I'm not sure how to make it count each answer (especially since some of them are multi-word answers) and output the sum of the values.
VLOOKUP is not suitable in this case. try FILTER like:
=FILTER(Sheet2!B49:B50, Sheet2!A49:A50=P2)
then VLOOKUP it like:
=SUMPRODUCT(IFNA(VLOOKUP(FILTER(Sheet2!B49:B50, Sheet2!A49:A50=P2), sheetx!A:B, 2, 0)))
where sheetx!A:B is like:
Riding your bike
2
Playing football
2
Swimming
3
Going fishing
4
Painting
4
and if Sheet2!B49:B50 contains multiple comma+space separated values you will need to split them like:
=SUMPRODUCT(IFNA(VLOOKUP(FILTER(
IFERROR(SPLIT(Sheet2!B49:B50, ", ")), Sheet2!A49:A50=P2), sheetx!A:B, 2, 0)))

Find words and associate to a value in Google Sheets

I got a list of items with several values validated from a list. Each value is a word which I would like to associate with a number and attribute a score:
For instance: Michael's evaluation contains Proactive, two Not Technically Capable, and Quick Learner, so according to the Profile/Value table, Michael scored 4.
Here is the URL:
https://docs.google.com/spreadsheets/d/1DD2jnS0M1z1f6i7wHImbiiyDcLv-M2vq3fio1sry4Do/edit?usp=sharing
Thank you!
try:
=INDEX(MMULT(IFNA(VLOOKUP(B2:E12; A16:B26; 2; 0); 0); {1;1;1;1}))

Finding top 3 values along with their headers

I want to be able to look at two rows and retrieve the top 3 highest values(found in row 2) along with their header(found in row 1). Here is what I have:
I am using the Large formula to retrieve the values, however it only brings the value. Is there a way for me to also retrieve its header? If so how?
Thank you in advance!
UPDATE: I just attempted to use the Lookup formula doing, "=LOOKUP(A7,A2:F2,A1:F1)" however it returned Value 6 instead of value 4, same with other values.
In A6 try
=transpose(array_constrain(sort(transpose(A1:G2), 2, 0), 3, 2))
and see if that works?

Pick the greatest number in a range that is also less than the corresponding number in another range's row

I have two sets of data in columns A and B. I would like to pick the maximum value from column A which is also less than the value in the corresponding row in column B. I think I ought to be able to do this with the MAXIFS function but all the examples I can find compare against static values. I tried these options
=MAXIFS(A1:A10, B1:B10, "<")
=MAXIFS(A1:A10, B1:B10, A&"<"&B)
but neither of them worked as expected. In the first case, it is always 0 suggesting the condition is never met, in the second it gives an error.
I know that I could do this by creating a separate region of cells which first filter out the data that doesn't match the conditional and then simply pick the max from what remains but I'd rather do it in a single cell if possible.
Is there a syntax for this comparison and, if so, what is it?
To the best of my knowledge there isn't a way of getting it to work with MAXIFS.
You can write this
=maxifs(A:A,A:A,"<"&B:B)
and it will accept it, but it just uses the first value in column B and doesn't do a side-by-side comparison.
So you have to do it another way e.g. with a combination of Max and If:
=ArrayFormula(max(if(A:A<B:B,A:A)))
or you can use max with a filter or query:
=max(filter(A:A,A:A<B:B))
=max(query(A:B,"select A where A<B"))
=ARRAY_CONSTRAIN(ARRAYFORMULA(
IF(LEN(INDIRECT(ADDRESS(ROW(), COLUMN(B:B))))>0,
IF(INDIRECT(ADDRESS(ROW(), COLUMN(B:B)))<MAX($A$1:$A),
MAX($A$1:$A), LARGE(UNIQUE($A$1:$A), 2)), )), 1, 1)

Resources