27
1
Challenge:
Given a number, take the largest prime strictly less than it, subtract it from this number, do this again to this new number with the biggest prime less than it, and continue doing this until it's less than 3. If it reaches 1, your program should output a truthy value, else, the program should output a falsey value.
Examples:
All of these should give a truthy value:
3
4
6
8
10
11
12
14
16
17
18
20
22
23
24
26
27
29
30
32
34
35
37
38
40
41
42
44
46
47
48
50
All of these should give falsey values:
5
7
9
13
15
19
21
25
28
31
33
36
39
43
45
49
Rules:
- You can either write a program or function.
- You can assume that the input is bigger than 2.
- Standard loopholes apply
- This is code-golf so the shortest answer wins!
related http://oeis.org/A175071
– flawr – 2016-09-11T14:10:59.93315-3=2, 2-(-2)=4, 4-3=1. (/wiseguy) – None – 2016-09-11T16:36:30.177
@Hurkyl -2 = -1×2, so it's not prime ;-) – ETHproductions – 2016-09-11T19:26:07.310
1@ETHProductions: Ah, but -1 is a unit; that factorization doesn't contradict the primality of -2 any more than 2=(-1)×(-2) does of 2. (or even 2=1×2) – None – 2016-09-11T19:31:40.510
@ETHproductions - just to clarify further, primes are numbers that cannot be expressed as the product of two or more other primes, but that also can't divide 1. If they can divide 1, they are called units, not primes. Both 1 and -1 are units. – Glen O – 2016-09-12T13:39:16.083
@Hurkyl - shame the question specifies "until it's less than 3". Otherwise, you'd be right. – Glen O – 2016-09-12T13:40:01.877
@GlenO Thanks for the explanation. Out of curiosity, does this mean that 1/2, -1/2, etc. are also units, or does this rule only apply to integers? – ETHproductions – 2016-09-12T13:55:17.153
@ETHproductions - it doesn't only apply to integers, but it doesn't apply to the rational numbers under the normal definitions of addition and multiplication. In fact, if you're considering the rational numbers (rather than the integers), then no number is prime. – Glen O – 2016-09-12T14:01:59.347
3@ETHproductions: The rational numbers are interesting because there are two very different approaches that are useful in practice! The rational numbers has no primes (not even 2!) because everything is a unit. However, you can also view the rationals as a construction made from the integers and study them using the primes of the integers. (e.g. anyone asking for the prime factorization of
9/10
as2^(-1) 3^2 5^(-1)
is thinking in terms of the latter) – None – 2016-09-12T17:15:56.983@Hurkyl Fascinating! Thanks for educating me. So by the latter thinking, is 1/p always prime if p is prime? – ETHproductions – 2016-09-13T01:09:18.997