/* Strange plus numbers (Rosetta code) in Picat. http://rosettacode.org/wiki/Strange_plus_numbers """ n is a strange plus number if the sum of the first two digits is prime and the sum of the second two digits is also prime. Where 100 < n < 500 """ This program was created by Hakan Kjellerstrand, hakank@gmail.com See also my Picat page: http://www.hakank.org/picat/ */ % import v3_utils. % import util. % import cp. main => go. go => L = [N : N in 100..500, S=N.to_string.map(to_int), prime(S[1]+S[2]), prime(S[2]+S[3])], Len = L.len, foreach({N,I} in zip(L,1..Len)) printf("%3d%s",N,cond(I mod 10 == 0, "\n", " ")) end, nl, println(len=Len), nl. go2 => L = [N : N in 100..500, S=N.to_string, s(S,1,2), s(S,2,3) ], Len = L.len, foreach({N,I} in zip(L,1..Len)) printf("%3d%s",N,cond(I mod 10 == 0, "\n", " ")) end, nl, println(len=Len), nl. s(S,I,J) => prime(sum(S[I..J].map(to_int))). % Another approach % Should be: /* 111 112 114 116 120 121 123 125 129 141 143 147 149 161 165 167 202 203 205 207 211 212 214 216 230 232 234 238 250 252 256 258 292 294 298 302 303 305 307 320 321 323 325 329 341 343 347 349 383 385 389 411 412 414 416 430 432 434 438 470 474 476 492 494 498 len = 65 */ go3 => P = [2, 3, 5, 7, 11, 13, 17], foreach(I in P, J in P) S = I.to_string ++ J.to_string, println([I,J,S,I+J]) end, nl.