/* Delicate prime numbers in Picat. https://twitter.com/QuantaMagazine/status/1624083296203288585 """ A prime number is “delicate” if, when you change any one of its digits to anything else, it loses its primality. This is the smallest digitally delicate prime. When you change any one of its digits, the number you get - 794,001, say - will be composite. https://quantamagazine.org/how-can-infinitely-many-primes-be-infinitely-far-apart-20220721/ [294,001] """ The definition is a little unclear. The delicatesness of a prime requires that all the changes will give a compisize number. Here are the delicate primes <= 10000000: 294001 505447 584141 604171 971767 1062599 1282529 1524181 2017963 2474431 2690201 3085553 3326489 4393139 5152507 5564453 5575259 6173731 6191371 6236179 6463267 6712591 7204777 7469789 7469797 7858771 7982543 8090057 8353427 8532761 8639089 9016079 9537371 9608189 9931447 This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ import util. main => go. go => foreach(N in 3..2..10000000,prime(N)) S = N.to_string.map(to_int), Len = S.len, Found = true, foreach(I in 1..Len, break(Found == false)) Before = [S[K].to_string : K in 1..I-1], After = [S[K].to_string : K in I+1..Len], foreach(J in 0..9, J != S[I], break(Found==false)) T = (Before ++ [J.to_string] ++ After).join('').to_int, if prime(T) then Found := false end end end, if Found == true then println(N) end end, nl.