Skip to content

Instantly share code, notes, and snippets.

@Vaguery
Last active January 31, 2021 13:47
Show Gist options
  • Save Vaguery/c4a293b442a0f79f2475ac441a1cc993 to your computer and use it in GitHub Desktop.
Save Vaguery/c4a293b442a0f79f2475ac441a1cc993 to your computer and use it in GitHub Desktop.
The first 80 "super primes" (delete any single digit and the result is still a prime)
# see http://oeis.org/A051362
require "prime"
def subprimes(number)
digits = number.digits.reverse
digits.collect.with_index do |d,idx|
subset = digits.dup
subset.delete_at(idx)
subset.join.to_i.prime?
end
end
def all_prime?(number)
subprimes(number).inject(number.prime?) {|b,s| b && s}
end
puts Prime.lazy.select { |p| all_prime?(p) }.
each.take(80).force
23
37
53
73
113
131
137
173
179
197
311
317
431
617
719
1013
1031
1097
1499
1997
2239
2293
3137
4019
4919
6173
7019
7433
9677
10193
10613
11093
19973
23833
26833
30011
37019
40013
47933
73331
74177
90011
91733
93491
94397
111731
166931
333911
355933
477797
477977
633317
633377
665293
700199
719333
746099
779699
901499
901997
944777
962233
991733
1367777
1440731
1799999
2668999
3304331
3716633
4437011
5600239
6666437
6913337
7333331
7364471
7391117
13334117
22255999
33771191
38800999
@Vaguery
Copy link
Author

Vaguery commented Jan 31, 2021

Could make the code faster by short-circuiting the loop in subprimes(number)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment