27
3
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
input numbers will not start with a 0
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.
2That's cool. Seems... declarative? Reads like you're just telling the language the specification. – Carcigenicate – 2017-03-15T14:20:00.573
3
@Carcigenicate Brachylog is indeed declarative, it is based on the declarative logic programming language Prolog.
– Fatalize – 2017-03-15T14:23:07.0532Prologs actually on my (increasingly) long list of languages to learn when I attain unlimited free time. There's too many cool languages! – Carcigenicate – 2017-03-15T14:26:43.933