Can the number reach 1 by repeatedly subtracting the largest prime less than it?
Retina, 31 bytes
.+
$*
+`1(?!(11+)\1+$)11+
1
^1$
Prints 0
(falsy) or 1
(truthy).
Try it online! (The first line enables a linefeed-separated test suite.)
Explanation
.+
$*
Convert input to unary by turning input N
into N
copies of 1
.
+`1(?!(11+)\1+$)11+
1
Repeatedly remove the largest prime less than the input. This is based on the standard primality test with regex.
^1$
Check whether the result is a single 1
.
Pyth, 18 15 14 bytes
Thanks to @Maltysen for -1 byte
#=-QefP_TUQ)q1
A program that takes input on STDIN and prints True
or False
as appropriate.
Try it online
How it works
#=-QefP_TUQ)q1 Program. Input: Q
# ) Loop until error statement (which occurs when Q<3):
UQ Yield [0, 1, 2, 3, ..., Q-1]
fP_T Filter that by primality
e Yield the last element of that
=-Q Q = Q - that
q1 Q is 1 (implicit variable fill)
Implicitly print
Old version with reduce, 18 bytes
qu-G*<HGH_fP_TSQQ1
Try it online
How it works
qu-G*<HGH_fP_TSQQ1 Program. Input: Q
SQ Yield [1, 2, 3, ..., Q]
fP_T Filter that by primality
_ Reverse it
u Reduce it:
Q with base case Q and
function G, H ->
<HG H<G
* H *H (yields H if H<G, else 0)
-G Subtract that from G
q 1 The result of that is 1
Implicitly print
Jelly, 9 8 bytes
’ÆRṪạµ¡Ḃ
Try it online! or verify all test cases.
How it works
’ÆRṪạµ¡Ḃ Main link. Argument: n
µ Combine all atoms to the left into a chain.
’ Decrement; yield n - 1.
ÆR Prime range; yield all primes in [2, ..., n -1].
Ṫ Tail; yield p, the last prime in the range.
If the range is empty, this yields p = 0.
ạ Compute the absolute difference of p and n.
¡ Call the chain to the left n times.
This suffices since each iteration decreases n, until one of the fixed
points (1 or 2) is reached.
Ḃ Bit; return the parity of the fixed point.