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
Python
Using sympy.isprime
<lang python>Python 3.8.5 (default, Sep 3 2020, 21:29:08) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license()" for more information. >>> from sympy import isprime
>>> [x for x in range(101,500)
if isprime(sum(int(c) for c in str(x)[:2])) and isprime(sum(int(c) for c in str(x)[1:]))]
[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] >>> </lang>
REXX
<lang rexx></lang>
Ring
<lang ring> load "stdlib.ring"
row = 0 see "Strange plus numbers are:"
for n = 100 to 500
flag = 1 str = string(n) for m = 1 to len(str)-1 num1 = number(str[m]) num2 = number(str[m+1]) pr = num1+num2 if not isprime(pr) flag = 0 exit ok next if flag = 1 row = row + 1 if (row-1) % 11 = 0 see nl else see " " + str ok ok
next </lang>
- Output:
Strange plus numbers are: 112 114 116 120 121 123 125 129 141 143 149 161 165 167 202 203 205 207 211 212 216 230 232 234 238 250 252 256 258 292 298 302 303 305 307 320 321 323 325 329 343 347 349 383 385 389 411 412 414 416 432 434 438 470 474 476 492 494 498
Wren
Simple brute force is adequate for this. <lang ecmascript>var primes = [2, 3, 5, 7, 11, 13, 17] var count = 0 var d = [] System.print("Strange plus numbers in the open interval (100, 500) are:\n") for (i in 101..499) {
d.clear() var j = i while (j > 0) { d.add(j % 10) j = (j/10).floor } if (primes.contains(d[0] + d[1]) && primes.contains(d[1] + d[2])) { System.write("%(i) ") count = count + 1 if (count % 10 == 0) System.print() }
} if (count % 10 != 0) System.print() System.print("\n%(count) strange plus numbers in all.")</lang>
- Output:
Strange plus numbers in the open interval (100, 500) are: 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 65 strange plus numbers in all.