Perl 6 , 54 53 52 51 ไบต์
{($_,{$_-($_-1...2).first: *.is-prime}...3>*)[*-1]==1}
{($_,{$_-($_-1...2).first: *.is-prime}...3>*).any==1}
{any($_,{$_-($_-1...2).first: *.is-prime}...3>*)==1}
{any($_,{$_-(^$_).grep(*.is-prime)[*-1]}...3>*)==1}
คำอธิบาย:
# bare block lambda with implicit parameter 「$_」
# used to generate all of the rest of the elements of the sequence
{
# create an any Junction of the following list
any(
$_, # initialize sequence with the inner block's argument
# bare block lambda with implicit parameter 「$_」
{
# take this inner block's argument and subtract
$_ -
( ^$_ ) # Range up-to and excluding 「$_」
.grep(*.is-prime)\ # find the primes
[ * - 1 ] # return the last value
}
... # keep doing that until
3 > * # the result is less than 3
# test that Junction against 「1」
# ( returns an 「any」 Junction like 「any(False, False, True)」 )
) == 1
}
ตัวอย่าง:
# show what is returned and if it is truthy
sub show ($_) {
# 「.&{…}」 uses the block as a method and implicitly against 「$_」
my $value = .&{any($_,{$_-(^$_).grep(*.is-prime)[*-1]}...3>*)==1}
say join "\t", $_, ?$value, $value.gist;
}
show 3; # 3 True any(False, True)
show 4; # 4 True any(False, True)
show 5; # 5 False any(False, False)
show 10; # 10 True any(False, False, True)
show 28; # 28 False any(False, False, False)
show 49; # 49 False any(False, False)
show 50; # 50 True any(False, False, True)