33
2
Given a list of positive integers, output whether every adjacent pair of integers in it shares a prime factor. In other words, output truthy if and only if no two neighboring integers in the list are co-prime.
In yet other terms: given a list of positive integers [a1 a2 … an], output whether
gcd(a1, a2) > 1 && gcd(a2, a3) > 1 && … && gcd(an−1, an) > 1.
The list will always contain at least two elements (n ≥ 2).
However…
This challenge is also restricted-source: the codepoints in your answer (whatever codepage it may be in) must satisfy the condition your program checks for.
For example, print 2
is a valid program. As a list of Unicode codepoints it is [112 114 105 110 116 32 50], which satisfies this condition: 112 and 114 share a factor of 2; and 114 and 105 share a factor of 3, etc.
However, main
can not occur in a valid program (sorry!), as the Unicode codepoints of m
and a
, namely 109 and 97, are coprime. (Thankfully, your submission needn’t be a full program!)
Your program isn’t allowed to contain codepoint 0.
Test cases
Truthy:
[6 21] -> 1
[502 230 524 618 996] -> 1
[314 112 938 792 309] -> 1
[666 642 658 642 849 675 910 328 320] -> 1
[922 614 530 660 438 854 861 357 477] -> 1
Falsy:
[6 7] -> 0
[629 474 502 133 138] -> 0
[420 679 719 475 624] -> 0
[515 850 726 324 764 555 752 888 467] -> 0
[946 423 427 507 899 812 786 576 844] -> 0
This is code-golf: the shortest code in bytes wins.
8For anyone attempting this challenge in a normal programming language, this is a list of characters that have prime codepoints in ASCII:
%)+/5;=CGIOSYaegkmq\DEL
. – Cristian Lupascu – 2017-08-13T13:48:00.423@Lynn Do Truthys have to be consistent? – H.PWiz – 2017-08-13T14:24:34.100
1@H.PWiz Nope! — – Lynn – 2017-08-13T14:25:41.760
I actually intended this to be doable for some normal (non-golf) langs, and I was feeling hopeful when I noticed that
print 2
was valid, but);=ae
being prime is really tough, I didn’t consider that… I wonder if something like Haskell can compete? – Lynn – 2017-08-13T14:56:14.560This restriction is easier than the reverse of this question, assume no-one use 0x02 byte. That question get nongolf valid answer in Mathematica, Logo, Haskell, Python, Perl, TI-BASIC. This one already got a Haskell, I think Mathematica is impossible, but Logo looks very likely to be possible, although I've not yet done constructing the solution.
– user202729 – 2017-10-05T16:13:36.663@user202729 In the end, the Logo solution turns out to be too tedious to write (similar to JSF), and certainly not very golfy. – user202729 – 2017-10-06T15:52:40.990