Vector and integer variables

You want to split the integer ‘x’ into its constituent digits and then check whether each digit appears in ‘v’?

x = 123
digitsofx = digits(x) # returns [3,2,1]
x = 1232
digitsofx = unique(digits(x)) # returns [2,3,1]
x = 1223
v = [1,3,5,7]
digitsofx = unique(digits(x)) # [3,2,1]
all_digits_in_v = all(in(v), digitsofx) # false
v = [1,3,5,2,7]
all_digits_in_v = all(in(v), digitsofx) # true

If x = 111 do you want to check if there is at least one ‘1’ in ‘v’ or do you want to check if there are at least three '1’s in ‘v’?

the nice form all(in(v), digitsofx) is thanks to @DNF

2 Likes