A formula to determine if value is part of set

AndroidDev

I have a set of numbers that start at 2 and increment by 60. Given any value, I want to test if the value belongs to the set. For example, these numbers belong to the set:

2, 62, 122, 182, 242, etc.

These numbers do not belong to the set:

0, 1, 3...61, 63...121,123...181 etc

I'm looking for the shortest way that this can be tested using Kotlin.

Alex.T

Something as simple as this, should work.

val number = 62
val isPart = number % 60 == 2
println(isPart) //will print true

But if you really have an actual set, I'd just recommend to actually check if the number it is part of the set, because that would have a time complexity of O(1).

val ourSet = hashSetOf(2,62,122)//and so on
val number = 122
    
val isPart = number in ourSet
println(isPart) //will print true

//OR

val isPartSecondOption = ourSet.contains(number)
println(isPartSecondOption) //will print true

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Use cell value to determine a range in part of formula

Set a range to a formula then to a value

Excel formula to search three ranges to determine value

Change part of excel formula with a constant value

Hibernate @Formula set value at runtime

How can I use the following formula to determine the value of a variable?

formula to set value from common two columns

Dynamically set the parameter (value_if_true) of an IF formula

Use a cell value (text) as a part of a formula in Excel VBA

Formula to determine transparancy

Is the XSLT value in (set) syntax a part of XSLT standard?

Check if value in selection is part of set of other values

set only a part from a value .setValues

Replace part of formula

Using a variable in part of a formula

Set column cell value as formula in dynamic range Maatwebsite/Excel 2.1.0

Set negative value to show and treat it as ZERO combined with other formula

What formula will return a designated code for the highest value in a set of cells?

set the cell a formula looks at, based on a value in another cell?

Use a google sheets formula to set text value as italic

Formula to determine if X out of ANY Y cells have a certain value (Google Spreadsheet)

Conditional formatting Rule Type 'Use a formula to determine which cells to format' in a table looks at the value in the row the rule was determined

Excel formula to determine if specific text from a list is contained in a cell, then return a variable value from another list

Determine the part of chrono durations

Logically determine game outcome with formula

Formula to determine brightness of RGB color

Determine if formula will return #Ref! error

How to split a set of int data to determine the value of the last two digits?

Determine if any of the values in a set of variables match the value in another variable