# Problem:

Your task is to decide if in a sequence of numbers, every number contains at least one of the digits of the number that preceded it.

For example, the following should return truthy:

[1, 12, 203, 0, 30]
^   ^ Contains a 0
^ Contains a 2
^ Contains a 1

The following should return falsey:

[1, 32, 23, 34]
^ Doesn't contain a 1, therefore false

Your submission can be a function or full program.

# Input:

Input can be any reasonable type of sequence. An array of numbers, an array of strings, a delimited string of numbers, etc.

Order matters however, so whatever structure you choose to accept as input obviously must have a definite ordering.

Input can be taken via the stdin or as an argument.

You can assume:

• all numbers will be non-negative integers

• input will always contain at least 2 numbers

# Output:

Output will be a truthy or falsey value (as defined by your language), representing whether or not the above specification is met.

Truthy/falsey values don't need to be consistent between tests.

It can either be output to the stdout or returned.

# Test Cases:

True cases:
[1, 1, 1, 11, 111, 11, 1]
[12, 23, 34, 45, 56]
[65, 54, 43, 32, 21]
[123, 29, 9, 59, 55, 52, 2017, 2]
[1234567890, 19, 95, 5012, 23]

False cases:
[1, 2, 3, 4, 5, 1, 11] (2 doesn't contain a 1)
[12, 23, 33, 45] (45 doesn't contain a 3)
[98, 87, 76, 11, 12, 23] (11 doesn't contain a 7 or 6)

This is code-golf, so the least number of bytes wins.

# Jelly, 5 4 bytes

f2\Ạ

Input is an array of strings.

Try it online!

### How it works

f2\Ạ  Main link. Argument: A (array of strings)

2\   Pairwise reduce by:
f       Filter, yielding all chars in the left string that appear in the right one.
Ạ  All; yield 1 if all strings are non-empty, 0 if not.

# Python 2, 48 bytes

lambda x:reduce(lambda a,b:set(a)&set(b)and b,x)

Try it online!

Print a empty set for False and the last element for True

# Retina, 25 20 bytes

(.).*¶(?=.*\1)

^.+$Try it online! Whenever we find a digit that also occurs in the next number, we remove the separator between those numbers (along with the digits in the former number, starting from the shared one, but that's irrelevant). The input is valid, if all separators have been remove in the process, which we check by making sure that the string can be matched as a single line. # Brachylog, 9 bytes {⊇ᵐ=∧?t}ˡ Try it online! Note that this not only works with a list of integers, but also with a list of strings or a list of lists. ### Explanation { }ˡ Left fold on the input: ⊇ᵐ= It is possible to find a number which is a subset of both input numbers ∧ (and) ?t The output is the second number (to continue the fold) • That's cool. Seems... declarative? Reads like you're just telling the language the specification. – Carcigenicate Mar 15 '17 at 14:20 • @Carcigenicate Brachylog is indeed declarative, it is based on the declarative logic programming language Prolog. – Fatalize Mar 15 '17 at 14:23 • Prologs actually on my (increasingly) long list of languages to learn when I attain unlimited free time. There's too many cool languages! – Carcigenicate Mar 15 '17 at 14:26 # JavaScript (ES6), 4744* 43 bytes Saved a byte thanks to @Neil x=>x.every(y=>y.match([${p}],p=y),p=1/19)

Takes input as a list of strings.

### Test snippet

let f =
x=>x.every(y=>y.match([${p}],p=y),p=1/19) let g = x => console.log("f([%s]): %s", x.join(", "), f(x.map(String))) g([1, 1, 1, 11, 111, 11, 1]) g([12, 23, 34, 45, 56]) g([65, 54, 43, 32, 21]) g([123, 29, 9, 59, 55, 52, 2017, 2]) g([123456789, 19, 95, 5012, 23]) g([1, 2, 3, 4, 5, 1, 11]) g([12, 23, 33, 45]) g([98, 87, 76, 11, 12, 23]) • Does [${p}] not work? – Neil Mar 15 '17 at 14:33
• @Neil Not for the first item of each array. – ETHproductions Mar 15 '17 at 14:34
• Ah, I see you found a workaround. I had got as far as a=>a.reduce((l,r)=>${l}.match([${r}])&&r) (which also works for numeric input). – Neil Mar 15 '17 at 14:38
• Perhaps you can remove the p&& if you set p=1/19? – Neil Mar 15 '17 at 20:12
• @Neil I, uh... well... That's genius, thanks :-) – ETHproductions Mar 15 '17 at 22:46

# 05AB1E, 10 bytes

ü‚vySå1åP

Try it online! or as a Test suite

Explanation

ü‚          # map pairing over each pair in input
v         # for each pair
y       # push as 2 separate elements on stack
Så     # check each digit in 2nd number for membership in first
1å   # check if any 1 exists in the resulting list
P  # product of stack
• €Sü.å - I wish this worked like I thought it would. – Magic Octopus Urn Mar 16 '17 at 19:27
• @carusocomputing: Yeah that would have been great. Or just ü.å or €Süå. – Emigna Mar 16 '17 at 19:54
• Why doesn't pairwise work with dot commands again? – Magic Octopus Urn Mar 16 '17 at 20:14
• @carusocomputing: It's only implemented to take the next byte as command. It doesn't take the dot into account. – Emigna Mar 16 '17 at 20:17

# CJam, 1815 14 bytes

Saved 4 bytes thanks to Martin Ender

l~Afb_1>.&:,:*

Try it online!

Explanation

l~              e# Read and eval the input
Afb           e# Convert each number to a list of digits
_          e# Duplicate the array
1>        e# Slice it after the first element
.&      e# Vectorized set intersection; take the set intersection of corresponding
e#  elements of the two arrays
:,    e# Get the length of each intersection
:*  e# Take the product of the whole array.
e#  Will be 0 if any intersection was empty.

-3 bytes thanks to @NickHansen! I really need to get better with those monad operators

-4 and -9 bytes thanks to @Laikoni and @nimi respectively!

and.(zipWith(any.flip elem)=<<tail)

This version takes the input as an array of strings, eliminating the need for show, but as far as I can see it works in largely the same way as the older version:

> 87
> 76
> 11
> 12
> 23' | ./digittest > /dev/null; echo $? 1 (1 here is falsey.) How it works: I'll demonstrate on the sample run above. The sed command converts the input into: grepx[98] <<<87 &&grepx[87] <<<76 &&grepx[76] <<<11 &&grepx[11] <<<12 &&grepx[12] <<<23 The tr command then converts this to the string: grep [98] <<<87 &&grep [87] <<<76 &&grep [76] <<<11 &&grep [11] <<<12 &&grep [12] <<<23 This string is a shell command for doing the desired operation, so I pipe that into sh and I'm done. • The file restriction is fine, although that's certainly an odd limitation. – Carcigenicate Mar 16 '17 at 13:49 ## Q, 57 bytes {r::();({r,::any(last x)in y;x,enlist y}\)($)0,x;all 1_r}
1. Initialises global r.
2. Converts input to array of strings.
3. Scans array checking that some character in last string is in current string.
4. Appends each result to r.
5. Returns 1 if all strings satisfy step 3 else returns 0.

Note: 0 appended to start of input array within function. This was done so that the comparison of the first element would be done enlisted. Otherwise, the last character of the first element is grabbed for comparison. Could do a type check however that adds 7 bytes over the current count.

• This looks like a similar approach to my Clojure answer. Neat looking language. – Carcigenicate Mar 20 '17 at 21:56