Strange plus numbers: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Strange plus numbers en FreeBASIC)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(46 intermediate revisions by 21 users not shown)
Line 4:
 
Where &nbsp; &nbsp; 100 &nbsp; < &nbsp; '''n''' &nbsp; < &nbsp; 500
 
 
;Related task
Line 12 ⟶ 13:
{{trans|Python}}
 
<langsyntaxhighlight lang="11l">F is_strange_plus(n)
V xs = String(n).map(c -> Int(c))
R all(zip(xs, xs[1..]).map((a, b) -> a + b C (2, 3, 5, 7, 11, 13, 17)))
Line 22 ⟶ 23:
print(el, end' ‘ ’)
I L.index % 10 == 9
print()</langsyntaxhighlight>
 
{{out}}
Line 38 ⟶ 39:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498
</pre>
 
=={{header|Action!}}==
<syntaxhighlight lang="action!">BYTE Func IsStrangePlusNumber(INT i)
BYTE ARRAY primes=[0 0 1 1 0 1 0 1 0 0 0 1 0 1 0 0 0 1 0]
BYTE d,prev,first,sum
 
prev=255
first=1
WHILE i#0
DO
d=i MOD 10
IF prev#255 THEN
sum=d+prev
IF first=1 AND primes(sum)=0 THEN
RETURN (0)
FI
first=0
FI
prev=d
i==/10
OD
IF primes(sum)=0 THEN
RETURN (0)
FI
RETURN (1)
 
PROC Main()
INT i,count=[0]
 
FOR i=101 TO 499
DO
IF IsStrangePlusNumber(i) THEN
PrintI(i) Put(32)
count==+1
FI
OD
PrintF("%E%EThere are %I strange plus numbers",count)
RETURN</syntaxhighlight>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Strange_plus_numbers.png Screenshot from Atari 8-bit computer]
<pre>
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
 
There are 65 strange plus numbers
</pre>
 
=={{header|ALGOL 68}}==
Does not attempt to generalise beyond 3 digit numbers.
<syntaxhighlight lang="algol68">BEGIN # find numbers where the sum of the first 2 digits is prime and also #
# the sum of the second 2 digits is prime #
# considers numbers n where 100 < n < 500 #
PROC small prime = ( INT n )BOOL: n = 2 OR ( ODD n AND n /= 1 AND n /= 9 AND n /= 15 );
INT s count := 0;
FOR n FROM 101 TO 499 DO
INT v := n;
INT d1 = v MOD 10; v OVERAB 10;
INT d2 = v MOD 10; v OVERAB 10;
INT d3 = v;
IF small prime( d1 + d2 ) AND small prime( d2 + d3 ) THEN
print( ( " ", whole( n, -3 ) ) );
IF ( s count +:= 1 ) MOD 10 = 0 THEN print( ( newline ) ) FI
FI
OD
END</syntaxhighlight>
{{out}}
<pre>
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
</pre>
 
=={{header|ALGOL W}}==
{{Trans|ALGOL 68}}
<syntaxhighlight lang="pascal">begin % find numbers where the sum of the first 2 digits is prime and also %
% the sum of the second 2 digits is prime %
% considers numbers n where 100 < n < 500 %
logical procedure isSmallPrime ( integer value n ); n = 2 or ( odd( n ) and n not = 1 and n not = 9 and n not = 15 );
procedure divideBy ( integer value result n; integer value d ) ; n := n div d;
integer procedure inc ( integer value result n ); begin n := n + 1; n end;
integer sCount;
sCount := 0;
for n := 101 until 499 do begin
integer v, d1, d2, d3;
v := n;
d1 := v rem 10; divideBy( v, 10 );
d2 := v rem 10; divideBy( v, 10 );
d3 := v;
if isSmallPrime( d1 + d2 ) and isSmallPrime( d2 + d3 ) then begin
writeon( i_w := 3, s_w := 0, " ", n );
if inc( sCount ) rem 10 = 0 then write()
end if_small_primes
end for_n
end.
</syntaxhighlight>
{{out}}
<pre>
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
</pre>
 
=={{header|APL}}==
{{works with|Dyalog APL}}
<langsyntaxhighlight APLlang="apl">(∧⌿ 2 3 5 7 11 13 17 ∊⍨ 2 +⌿ 10 (⊥⍣¯1) X)/X←100+⍳399</langsyntaxhighlight>
 
{{out}}
Line 52 ⟶ 163:
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">------------------- STRANGE PLUS NUMBERS -----------------
 
-- isStrangePlus :: Int -> Bool
Line 251 ⟶ 362:
end tell
end if
end zipWith</langsyntaxhighlight>
{{Out}}
<pre>'Strange Plus' numbers found in range [100..500]
Line 266 ⟶ 377:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498</pre>
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">strangeNums: select 101..499 'x ->
and? -> prime? sum first.n:2 digits x
-> prime? sum last.n:2 digits x
 
loop split.every: 5 strangeNums 'x ->
print map x 's -> pad to :string s 3</syntaxhighlight>
 
{{out}}
 
<pre>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</pre>
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f STRANGE_PLUS_NUMBERS.AWK
BEGIN {
Line 294 ⟶ 430:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 307 ⟶ 443:
</pre>
 
=={{header|BASIC}}==
<syntaxhighlight lang="gwbasic">10 DEFINT A-Z
20 FOR I=100 TO 500
30 N=I
40 R=N MOD 10
50 IF N<10 THEN PRINT I,: GOTO 100
60 L=R
70 N=N\10
80 R=N MOD 10
90 IF INSTR("CDFHLNR",CHR$(L+R+65)) THEN 50
100 NEXT I</syntaxhighlight>
{{out}}
<pre> 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</pre>
 
=={{header|BCPL}}==
<syntaxhighlight lang="bcpl">get "libhdr"
 
let smallprime(n) = n=2 | n=3 | n=5 | n=7 | n=11 | n=13 | n=17
 
let strangeplus(n) =
n<10 -> true,
~smallprime(n rem 10 + (n/10) rem 10) -> false,
strangeplus(n / 10)
 
let start() be
$( let col = 0
for i = 100 to 500 if strangeplus(i)
$( writef("%I3 ",i)
col := col + 1
if col rem 10 = 0 then wrch('*N')
$)
wrch('*N')
$) </syntaxhighlight>
{{out}}
<pre>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</pre>
 
=={{header|BQN}}==
<syntaxhighlight lang="bqn">∘‿13⥊(∧´2‿3‿5‿7‿11‿13‿17∊˜(+˝∘⍉2↕•Fmt-'0'˙))¨⊸/100+↕400</syntaxhighlight>
{{out}}
<pre>┌─
╵ 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
┘</pre>
=={{header|C}}==
 
Generalized solution: a number is strange iff the sum of two consecutive digits is always prime. Numbers < 10 are considered non-strange.
 
<langsyntaxhighlight lang="c">#include <stdio.h>
 
static int p[19] = {0, 0, 1, 1, 0, 1, 0, 1, 0, 0,
Line 334 ⟶ 534:
}
return 0;
}</langsyntaxhighlight>
 
{{out}}
Line 345 ⟶ 545:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498</pre>
 
=={{header|C++}}==
{{trans|Java}}
<langsyntaxhighlight lang="cpp">#include <iostream>
#include <vector>
 
Line 387 ⟶ 588:
test(101, 499);
return 0;
}</langsyntaxhighlight>
{{out}}
<pre>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</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">small_prime = proc (n: int) returns (bool)
small_primes = sequence[int]$[2,3,5,7,11,13,17]
for p: int in sequence[int]$elements(small_primes) do
if n=p then return(true) end
end
return(false)
end small_prime
 
strange_plus = proc (n: int) returns (bool)
while n >= 10 do
d1: int := n // 10
n := n / 10
d2: int := n // 10
if ~small_prime(d1 + d2) then return(false) end
end
return(true)
end strange_plus
 
start_up = proc ()
po: stream := stream$primary_input()
col: int := 0
for i: int in int$from_to(100,500) do
if strange_plus(i) then
stream$putright(po, int$unparse(i), 4)
col := col + 1
if col // 10 = 0 then stream$putl(po, "") end
end
end
end start_up</syntaxhighlight>
{{out}}
<pre> 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</pre>
 
=={{header|COBOL}}==
<syntaxhighlight lang="cobol"> IDENTIFICATION DIVISION.
PROGRAM-ID. STRANGE-PLUS-NUMBERS.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 VARIABLES.
03 CANDIDATE PIC 999.
03 DIGITS REDEFINES CANDIDATE,
PIC 9 OCCURS 3 TIMES.
03 LEFT-PAIR PIC 99.
88 LEFT-PAIR-PRIME VALUES 2, 3, 5, 7, 11, 13, 17.
03 RIGHT-PAIR PIC 99.
88 RIGHT-PAIR-PRIME VALUES 2, 3, 5, 7, 11, 13, 17.
01 OUT.
03 ROW PIC X(40) VALUE SPACES.
03 PTR PIC 99 VALUE 1.
PROCEDURE DIVISION.
BEGIN.
PERFORM CHECK-STRANGE-NUMBER
VARYING CANDIDATE FROM 100 BY 1
UNTIL CANDIDATE IS GREATER THAN 500.
DISPLAY ROW.
STOP RUN.
 
CHECK-STRANGE-NUMBER.
ADD DIGITS(1), DIGITS(2) GIVING LEFT-PAIR.
ADD DIGITS(2), DIGITS(3) GIVING RIGHT-PAIR.
IF LEFT-PAIR-PRIME AND RIGHT-PAIR-PRIME,
PERFORM WRITE-STRANGE-NUMBER.
 
WRITE-STRANGE-NUMBER.
STRING CANDIDATE DELIMITED BY SIZE INTO ROW
WITH POINTER PTR.
ADD 1 TO PTR.
IF PTR IS GREATER THAN 40,
DISPLAY ROW,
MOVE SPACES TO ROW,
MOVE 1 TO PTR.</syntaxhighlight>
{{out}}
<pre>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</pre>
 
=={{header|Comal}}==
<syntaxhighlight lang="comal">0010 FUNC small'prime#(n#)
0020 RETURN n#=2 OR (n# MOD 2<>0 AND n#<>1 AND n#<>9 AND n#<>15)
0030 ENDFUNC small'prime#
0040 //
0050 FUNC strange'plus#(n#)
0060 dl#:=n# MOD 10
0070 WHILE n#>=10 DO
0080 dr#:=dl#
0090 n#:=n# DIV 10
0100 dl#:=n# MOD 10
0110 IF NOT small'prime#(dl#+dr#) THEN RETURN FALSE
0120 ENDWHILE
0130 RETURN TRUE
0140 ENDFUNC strange'plus#
0150 //
0160 ZONE 4
0170 col#:=0
0180 FOR i#:=100 TO 500 DO
0190 IF strange'plus#(i#) THEN
0200 PRINT i#,
0210 col#:+1
0220 IF col# MOD 10=0 THEN PRINT
0230 ENDIF
0240 ENDFOR i#
0250 PRINT
0260 END</syntaxhighlight>
{{out}}
<pre>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</pre>
 
=={{header|Cowgol}}==
<syntaxhighlight lang="cowgol">include "cowgol.coh";
 
sub small_prime(n: uint8): (p: uint8) is
var primes: uint32 := 0x228AC;
p := ((primes >> n) & 1) as uint8;
end sub;
 
sub strange_plus(n: uint16): (r: uint8) is
var dl := (n % 10) as uint8;
r := 1;
while n >= 10 and r != 0 loop
var dr := dl;
n := n / 10;
dl := (n % 10) as uint8;
r := r & small_prime(dl + dr);
end loop;
end sub;
 
var col: uint8 := 0;
var cand: uint16 := 100;
while cand < 500 loop
if strange_plus(cand) != 0 then
print_i16(cand);
col := col + 1;
if col == 10 then
print_nl();
col := 0;
else
print_char(' ');
end if;
end if;
cand := cand + 1;
end loop;
print_nl();</syntaxhighlight>
{{out}}
<pre>111 112 114 116 120 121 123 125 129 141
Line 398 ⟶ 767:
 
=={{header|Delphi}}==
{{libheader| System.SysUtils}}
{{Trans|Go}}
<syntaxhighlight lang="delphi">
<lang Delphi>
program Strange_plus_numbers;
 
Line 443 ⟶ 811:
writeln(#10, count, ' strange plus numbers in all.');
readln;
end.</langsyntaxhighlight>
 
=== Alternate solution ===
 
<syntaxhighlight lang="delphi">program StrangePlusNumbers;
 
const
m = 18;
 
var
pr: array [0..m] of Boolean;
n, k, a, b: Integer;
q: Boolean;
begin
// prime sieve
for n := 0 to m do
begin
q := n > 1;
for k := 2 to n - 1 do
if n mod k = 0 then q := False;
pr[n] := q
end;
 
k := 0;
for n := 101 to 499 do
begin
a := n div 10; // first two digits
b := n mod 100; // last two digits
if pr[a div 10 + a mod 10] and
pr[b div 10 + b mod 10] then
begin
Write(n);
Inc(k);
if k mod 10 = 0 then Writeln else Write(' ')
end
end
end.</syntaxhighlight>
 
{{out}}
 
<pre>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</pre>
 
=={{header|Draco}}==
<syntaxhighlight lang="draco">proc small_prime(word n) bool:
word primes = 0x8A2B;
n>=2 and primes >> (n-2) & 1 = 1
corp
 
proc strange_plus(word n) bool:
word dl, dr;
bool pair_prime;
dl := n % 10;
while
dr := dl;
n := n / 10;
dl := n % 10;
pair_prime := small_prime(dl + dr);
pair_prime and n >= 10
do od;
pair_prime and n < 10
corp
 
proc main() void:
byte col;
word cand;
col := 0;
for cand from 101 upto 499 do
if strange_plus(cand) then
write(cand:4);
col := col + 1;
if col = 10 then writeln(); col := 0 fi
fi
od
corp</syntaxhighlight>
{{out}}
<pre> 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</pre>
 
=={{header|F_Sharp|F#}}==
This task uses [[Extensible_prime_generator#The_functions|Extensible Prime Generator (F#)]].<br>
<langsyntaxhighlight lang="fsharp">
// Strange numbers. Nigel Galloway: February 25th., 2021
let pD=[0..99]|>List.map(fun n->(n/10,n%10))|>List.filter(fun(n,g)->isPrime(n+g))
pD|>List.filter(fun(n,_)->n>0)|>List.map(fun(n,g)->(n,pD|>List.filter(fun(n,_)->n=g)))
|>List.collect(fun(n,g)->g|>List.map(fun(g,k)->n*100+g*10+k))|>List.filter((>)500)|>List.iter(printf "%d ");printfn ""
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 460 ⟶ 916:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<langsyntaxhighlight lang="factor">USING: grouping grouping.extras io kernel math math.primes
math.ranges math.text.utils prettyprint sequences ;
 
Line 470 ⟶ 926:
100 500 (a,b) [ strange+? ] filter dup
10 group [ [ pprint bl ] each nl ] each nl
length pprint " strange plus numbers found." print</langsyntaxhighlight>
{{out}}
<pre>
Line 488 ⟶ 944:
=={{header|Forth}}==
{{trans|C}}
<langsyntaxhighlight lang="forth">create isprime false , false , true , true , false ,
true , false , true , false , false , false , true ,
false , true , false , false , false , true , false ,
Line 520 ⟶ 976:
 
main
bye</langsyntaxhighlight>
 
{{out}}
Line 536 ⟶ 992:
=={{header|FreeBASIC}}==
{{trans|AWK}}
<langsyntaxhighlight lang="freebasic">
Function isPrime(valor As Integer) As Boolean
If valor <= 1 Then Return False
Line 561 ⟶ 1,017:
Print !"\n\n"; k; " n£meros m s extra¤os encontrados."
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 577 ⟶ 1,033:
</pre>
 
=={{header|Fōrmulæ}}==
 
{{FormulaeEntry|page=https://formulae.org/?script=examples/Strange_plus_numbers}}
 
'''Solution'''
 
[[File:Fōrmulæ - Strange plus numbers 01.png]]
 
[[File:Fōrmulæ - Strange plus numbers 02.png]]
 
[[File:Fōrmulæ - Strange plus numbers 03.png]]
 
=={{header|Go}}==
{{trans|Wren}}
<langsyntaxhighlight lang="go">package main
 
import "fmt"
Line 611 ⟶ 1,078:
}
fmt.Printf("\n%d strange plus numbers in all.\n", count)
}</langsyntaxhighlight>
 
{{out}}
Line 629 ⟶ 1,096:
 
=={{header|Haskell}}==
<langsyntaxhighlight lang="haskell">import Data.List (intercalate)
import Data.List.Split (chunksOf)
 
Line 653 ⟶ 1,120:
unlines
(unwords <$> chunksOf 10 (show <$> xs))
]</langsyntaxhighlight>
{{Out}}
<pre>"Strange Plus" numbers found in range [100..500]
Line 668 ⟶ 1,135:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498</pre>
 
=={{header|J}}==
 
Definitions:
<syntaxhighlight lang="j">digits=: 10&#.inv"0
strangeplus=: 100&< * 500&> * (2&{. * ::0:&(1&p:)&(+/) _2&{.)@digits</syntaxhighlight>
 
Example:
<syntaxhighlight lang="j"> I.strangeplus i.500
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</syntaxhighlight>
 
 
=={{header|Java}}==
 
<langsyntaxhighlight lang="java">public class Strange {
private static final boolean[] p = {
false, false, true, true, false,
Line 698 ⟶ 1,176:
}
}
}</langsyntaxhighlight>
 
<syntaxhighlight lang="text">java Strange 101 499</langsyntaxhighlight>
 
{{out}}
Line 711 ⟶ 1,189:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
 
See e.g. [[Erd%C5%91s-primes#jq]] for a suitable implementation of `is_prime`.
<syntaxhighlight lang="jq">def nwise($n):
def n: if length <= $n then . else .[0:$n] , (.[$n:] | n) end;
n;
 
def is_strange:
def sum($i): (.[$i:$i+1]|tonumber) + (.[$i+1:$i+2]|tonumber);
tostring
| length > 2 and (sum(0) | is_prime) and (sum(1) | is_prime) ;
 
def task:
[range(101; 500)
| select(is_strange)]
| nwise(10)
| join(" ");
task</syntaxhighlight>
{{out}}
<pre>
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
</pre>
 
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">let
smallprimes = [2, 3, 5, 7, 11, 13, 17] # 0 <= all of these primes <= 18
paired_digit_sums(n) = (d = digits(n); [sum(p) for p in zip(d[1:end-1], d[2:end])])
Line 723 ⟶ 1,234:
end
end
</langsyntaxhighlight>{{out}}
<pre>
111 112 114 116 120 121 123 125 129 141 143 147 149
Line 734 ⟶ 1,245:
=={{header|Kotlin}}==
{{trans|Java}}
<langsyntaxhighlight lang="scala">val p = arrayOf(
false, false, true, true, false,
true, false, true, false, false,
Line 773 ⟶ 1,284:
fun main() {
test(101, 499)
}</langsyntaxhighlight>
{{out}}
<pre>111 112 114 116 120 121 123 125 129 141
Line 783 ⟶ 1,294:
474 476 492 494 498 </pre>
 
=={{header|MAD}}==
<syntaxhighlight lang="mad"> NORMAL MODE IS INTEGER
 
INTERNAL FUNCTION(X)
ENTRY TO SMLPRM.
THROUGH TEST, FOR VALUES OF P = 2, 3, 5, 7, 11, 13, 17
TEST WHENEVER P.E.X, FUNCTION RETURN 1B
FUNCTION RETURN 0B
END OF FUNCTION
 
INTERNAL FUNCTION(NN)
ENTRY TO STGPLS.
N = NN
NX = N / 10
DA = N - NX * 10
STEP DB = DA
N = NX
NX = N / 10
DA = N - NX * 10
WHENEVER .NOT.SMLPRM.(DA + DB), FUNCTION RETURN 0B
WHENEVER N.L.10, FUNCTION RETURN 1B
TRANSFER TO STEP
END OF FUNCTION
 
THROUGH TEST, FOR I = 100, 1, I.GE.500
TEST WHENEVER STGPLS.(I), PRINT RESULTS I
 
END OF PROGRAM</syntaxhighlight>
{{out}}
<pre style='height:50ex;'>I = 111
I = 112
I = 114
I = 116
I = 120
I = 121
I = 123
I = 125
I = 129
I = 141
I = 143
I = 147
I = 149
I = 161
I = 165
I = 167
I = 202
I = 203
I = 205
I = 207
I = 211
I = 212
I = 214
I = 216
I = 230
I = 232
I = 234
I = 238
I = 250
I = 252
I = 256
I = 258
I = 292
I = 294
I = 298
I = 302
I = 303
I = 305
I = 307
I = 320
I = 321
I = 323
I = 325
I = 329
I = 341
I = 343
I = 347
I = 349
I = 383
I = 385
I = 389
I = 411
I = 412
I = 414
I = 416
I = 430
I = 432
I = 434
I = 438
I = 470
I = 474
I = 476
I = 492
I = 494
I = 498</pre>
=={{header|Maple}}==
<langsyntaxhighlight lang="maple">select(n->(u->isprime(add(u[1..2])) and isprime(add(u[2..3])))(convert(n,base,10)),[$101..499]);</langsyntaxhighlight>
 
{{out}}
Line 794 ⟶ 1,399:
383, 385, 389, 411, 412, 414, 416, 430, 432, 434, 438, 470,
474, 476, 492, 494, 498]</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">Select[Range[101, 499], PrimeQ[Total[IntegerDigits[#][[;; 2]]]] && PrimeQ[Total[IntegerDigits[#][[2 ;;]]]] &]
Length[%]</syntaxhighlight>
{{out}}
<pre>{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</pre>
 
=={{header|Modula-2}}==
<syntaxhighlight lang="modula2">MODULE StrangePlusNumbers;
FROM InOut IMPORT WriteCard, WriteLn;
 
VAR i, col: CARDINAL;
 
PROCEDURE SmallPrime(n: CARDINAL): BOOLEAN;
BEGIN
RETURN (n=2) OR (n=3) OR (n=5) OR (n=7) OR (n=11) OR (n=13) OR (n=17)
END SmallPrime;
 
PROCEDURE StrangePlus(n: CARDINAL): BOOLEAN;
VAR l, r: CARDINAL;
BEGIN
r := n MOD 10;
WHILE n>=10 DO
l := r;
n := n DIV 10;
r := n MOD 10;
IF NOT SmallPrime(l+r) THEN RETURN FALSE END
END;
RETURN TRUE
END StrangePlus;
 
BEGIN
col := 0;
FOR i := 100 TO 500 DO
IF StrangePlus(i) THEN
WriteCard(i, 4);
INC(col);
IF col MOD 10 = 0 THEN WriteLn END
END
END;
WriteLn;
END StrangePlusNumbers.</syntaxhighlight>
{{out}}
<pre> 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</pre>
 
=={{header|Nim}}==
<syntaxhighlight lang="nim">const Primes = {2, 3, 5, 7, 11, 13, 17}
 
proc digits(n: 100..999): array[3, int] =
[n div 100, n div 10 mod 10, n mod 10]
 
var count = 0
for n in 101..<500:
let d = n.digits
if d[0] + d[1] in Primes and d[1] + d[2] in Primes:
inc count
stdout.write n, if count mod 13 == 0: '\n' else: ' '</syntaxhighlight>
 
{{out}}
<pre>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</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">use strict;
use warnings;
use feature 'say';
Line 805 ⟶ 1,481:
my $n = my @SP = grep { my @d = split ''; is_prime $d[0]+$d[1] and is_prime $d[1]+$d[2] } $low+1 .. $high-1;
say "Between $low and $high there are $n strange-plus numbers:\n" .
(sprintf "@{['%4d' x $n]}", @SP[0..$n-1]) =~ s/(.{80})/$1\n/gr;</langsyntaxhighlight>
{{out}}
<pre>Between 100 and 500 there are 65 strange-plus numbers:
Line 815 ⟶ 1,491:
=={{header|Phix}}==
Using the same approach as [[Strange_numbers#Phix]], so this should similarly scale/count easily to the 28-digit range.
<!--<syntaxhighlight lang="phix">(phixonline)-->
<lang Phix>constant poss = apply(true,sq_sub,{{get_primes(-7)},tagset(9,0)}),
<span style="color: #008080;">constant</span> <span style="color: #000000;">poss</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">sq_sub</span><span style="color: #0000FF;">,{{</span><span style="color: #7060A8;">get_primes</span><span style="color: #0000FF;">(-</span><span style="color: #000000;">7</span><span style="color: #0000FF;">)},</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">9</span><span style="color: #0000FF;">,</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)}),</span>
nxts = apply(true,filter,{poss,{"in"},{{0,9}},{"[]"}})
<span style="color: #000000;">nxts</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">apply</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">filter</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">poss</span><span style="color: #0000FF;">,{</span><span style="color: #008000;">"in"</span><span style="color: #0000FF;">},{{</span><span style="color: #000000;">0</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9</span><span style="color: #0000FF;">}},{</span><span style="color: #008000;">"[]"</span><span style="color: #0000FF;">}})</span>
 
function strange_plus(integer left, sequence digits, res={}, part={})
<span style="color: #008080;">function</span> <span style="color: #000000;">strange_plus</span><span style="color: #0000FF;">(</span><span style="color: #004080;">integer</span> <span style="color: #000000;">left</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">sequence</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">res</span><span style="color: #0000FF;">={},</span> <span style="color: #000000;">part</span><span style="color: #0000FF;">=</span><span style="color: #008000;">""</span><span style="color: #0000FF;">)</span>
for i=1 to length(digits) do
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">digits</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span>
integer di = digits[i]
<span style="color: #004080;">integer</span> <span style="color: #000000;">di</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">digits</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">]</span>
if left=1 then
<span style="color: #004080;">string</span> <span style="color: #000000;">pn</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">part</span><span style="color: #0000FF;">&</span><span style="color: #000000;">di</span><span style="color: #0000FF;">+</span><span style="color: #008000;">'0'</span>
string fmt = join(repeat("%d",length(part)+1),"")
<span style="color: #008080;">if</span> <span style="color: #000000;">left</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">then</span>
res = append(res,sprintf(fmt,part&di))
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">append</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pn</span><span style="color: #0000FF;">)</span>
else
<span style="color: #008080;">else</span>
res = strange_plus(left-1,nxts[di+1],res,part&di)
<span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">strange_plus</span><span style="color: #0000FF;">(</span><span style="color: #000000;">left</span><span style="color: #0000FF;">-</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">nxts</span><span style="color: #0000FF;">[</span><span style="color: #000000;">di</span><span style="color: #0000FF;">+</span><span style="color: #000000;">1</span><span style="color: #0000FF;">],</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #000000;">pn</span><span style="color: #0000FF;">)</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end for
<span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
return res
<span style="color: #008080;">return</span> <span style="color: #000000;">res</span>
end function
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
sequence res = strange_plus(3,tagset(4)) -- (3 digit numbers beginning 1..4)
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">strange_plus</span><span style="color: #0000FF;">(</span><span style="color: #000000;">3</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">4</span><span style="color: #0000FF;">))</span> <span style="color: #000080;font-style:italic;">-- (3 digit numbers beginning 1..4)</span>
printf(1,"%d strange_plus numbers found: %s\n",{length(res),join(shorten(res,"",5),",")})</lang>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"%d strange_plus numbers found: %s\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">),</span><span style="color: #7060A8;">join</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">shorten</span><span style="color: #0000FF;">(</span><span style="color: #000000;">res</span><span style="color: #0000FF;">,</span><span style="color: #008000;">""</span><span style="color: #0000FF;">,</span><span style="color: #000000;">5</span><span style="color: #0000FF;">),</span><span style="color: #008000;">","</span><span style="color: #0000FF;">)})</span>
<!--</syntaxhighlight>-->
{{out}}
<pre>
65 strange_plus numbers found: 111,112,114,116,120,...,474,476,492,494,498
</pre>
 
=={{header|Picat}}==
<syntaxhighlight lang="picat">main =>
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)</syntaxhighlight>
 
{{out}}
<pre>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</pre>
 
 
=={{header|PL/I}}==
<syntaxhighlight lang="pli">StrangePlusNumbers: procedure options(main);
smallPrime: procedure(n) returns(bit);
declare n fixed;
return(n=2 | n=3 | n=5 | n=7 | n=11 | n=13 | n=17);
end smallPrime;
 
strangePlus: procedure(nn) returns(bit);
declare (n, nn, d1, d2) fixed;
do n=nn repeat(n/10) while(n>=10);
d1 = mod(n,10);
d2 = mod(n/10,10);
if ^smallPrime(d1+d2) then return('0'b);
end;
return('1'b);
end strangePlus;
 
declare (i, seen) fixed;
seen = 0;
do i=100 to 500;
if strangePlus(i) then do;
put edit(i) (F(4));
seen = seen + 1;
if mod(seen,10) = 0 then put skip;
end;
end;
end StrangePlusNumbers;</syntaxhighlight>
{{out}}
<pre> 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</pre>
 
=={{header|PL/M}}==
<syntaxhighlight lang="pli">100H:
BDOS: PROCEDURE(F,A); DECLARE F BYTE, A ADDRESS; GO TO 5; END BDOS;
EXIT: PROCEDURE; GO TO 0; END EXIT;
PRINT: PROCEDURE(S); DECLARE S ADDRESS; CALL BDOS(9,S); END PRINT;
DECLARE TRUE LITERALLY '0FFH', FALSE LITERALLY '0';
 
/* PRINT NUMBER */
PRINT$NUM: PROCEDURE(N);
DECLARE (N, P) ADDRESS, C BASED P BYTE;
DECLARE S(6) BYTE INITIAL('.....$');
P = .S(5);
DIGIT:
P = P-1;
C = '0' + N MOD 10;
IF (N := N/10) > 0 THEN GO TO DIGIT;
CALL PRINT(P);
END PRINT$NUM;
 
/* SEE IF NUMBER IS A SMALL PRIME (<=18) */
SMALL$PRIME: PROCEDURE(N) BYTE;
DECLARE N BYTE;
RETURN N=2 OR N>2 AND SHR(8A2BH, N-2);
END SMALL$PRIME;
 
/* SEE IF A NUMBER IS A STRANGE PLUS NUMBER */
STRANGE$PLUS: PROCEDURE(N) BYTE;
DECLARE N ADDRESS;
DECLARE (D$LEFT, D$RIGHT) BYTE;
D$RIGHT = N MOD 10;
DO WHILE N >= 10;
D$LEFT = D$RIGHT;
N = N/10;
D$RIGHT = N MOD 10;
IF NOT SMALL$PRIME(D$LEFT + D$RIGHT) THEN RETURN FALSE;
END;
RETURN TRUE;
END STRANGE$PLUS;
 
/* CHECK NUMBERS IN RANGE 100..500 */
DECLARE CAND ADDRESS, COL BYTE INITIAL(0);
DO CAND = 100 TO 500;
IF STRANGE$PLUS(CAND) THEN DO;
CALL PRINT$NUM(CAND);
IF (COL := COL + 1) = 10 THEN DO;
CALL PRINT(.(13,10,'$'));
COL = 0;
END;
ELSE CALL PRINT(.' $');
END;
END;
CALL EXIT;
EOF</syntaxhighlight>
{{out}}
<pre>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</pre>
 
=={{header|Python}}==
Using [https://docs.sympy.org/latest/modules/ntheory.html sympy.isprime]
 
<langsyntaxhighlight 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
Line 849 ⟶ 1,648:
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]
>>> </langsyntaxhighlight>
 
 
Or, as we may not need to wake up '''sympy''' just to check membership of {2, 3, 5, 7, 11, 13, 17}:
 
<langsyntaxhighlight lang="python">'''Strange Plus Numbers'''
 
 
Line 912 ⟶ 1,711:
# MAIN ---
if __name__ == '__main__':
main()</langsyntaxhighlight>
{{Out}}
<pre>"Strange Plus" numbers in range [100..500]
Line 925 ⟶ 1,724:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498</pre>
 
=={{header|Quackery}}==
 
<syntaxhighlight lang="Quackery"> [ ' [ 2 3 5 7 11 13 17 ]
find 7 < ] is prime ( n --> b )
 
[ 10 /mod
swap 10 /mod
tuck + prime not iff
[ 2drop false ] done
+ prime ] is strange+ ( n --> b )
 
[] 399 times
[ i^ 101 +
dup strange+ iff
join else drop ]
dup size echo
say " strange plus numbers:"
cr cr
witheach
[ echo
i^ 10 mod 9 = iff cr else sp ]</syntaxhighlight>
 
{{out}}
 
<pre>65 strange plus numbers:
 
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
</pre>
 
=={{header|R}}==
 
<syntaxhighlight lang="rsplus"># Primes up to 18
pr <- sapply(1:18, \(n) n > 1 && all(n %% seq(2, length.out = n - 2) > 0))
 
is.strange <- function(n) {
a <- as.integer(strsplit(as.character(n), "")[[1]])
pr[a[[1]] + a[[2]] + 1] && pr[a[[2]] + a[[3]] + 1]
}
 
a <- 101:499
a[sapply(a, is.strange)]</syntaxhighlight>
 
{{out}}
 
<pre> [1] 111 112 114 116 120 121 123 125 129 141 143 147 149 161 165 167 202 203 205 207 211 212 214
[24] 216 230 232 234 238 250 252 256 258 292 294 298 302 303 305 307 320 321 323 325 329 341 343
[47] 347 349 383 385 389 411 412 414 416 430 432 434 438 470 474 476 492 494 498</pre>
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>unit sub MAIN ($start = 100, $end = 500);
put +$_, " matching numbers from $start to $end:\n", $_ given
($start .. $end).hyper(:256batch,:8degree).grep: { all .comb.rotor(2 => -1).map: { .sum.is-prime } };</langsyntaxhighlight>
{{out}}
<pre>65 matching numbers from 100 to 500:
Line 935 ⟶ 1,788:
 
=={{header|REXX}}==
<langsyntaxhighlight lang="rexx">/*REXX pgm lists strange+ integers (within a range); sum of adjacent dec. digs is prime.*/
parse arg LO HI . /*obtain optional arguments from the CL*/
if LO=='' | LO=="," then LO= 101 /*Not specified? Then use the default.*/
Line 957 ⟶ 1,810:
say # ' strange plus numbers found between ' LO " and " HI ' (inclusive)'
say
say strip($)</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 969 ⟶ 1,822:
=={{header|Ring}}==
 
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
 
Line 995 ⟶ 1,848:
ok
next
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 1,006 ⟶ 1,859:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498
</pre>
 
=={{header|RPL}}==
{{works with|HP|49}}
≪ { }
<span style="color:red">101 499</span> '''FOR''' n
n <span style="color:red">10</span> IDIV2 SWAP <span style="color:red">10</span> IDIV2
'''IF''' ROT OVER + ISPRIME? UNROT + ISPRIME? AND '''THEN''' n + '''END'''
'''NEXT'''
≫ '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
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}
</pre>
 
=={{header|Ruby}}==
{{trans|Kotlin}}
<langsyntaxhighlight lang="ruby">$p = [
false, false, true, true, false,
true, false, true, false, false,
Line 1,047 ⟶ 1,913:
end
 
test(101, 499)</langsyntaxhighlight>
{{out}}
<pre>111 112 114 116 120 121 123 125 129 141
Line 1,056 ⟶ 1,922:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498</pre>
 
=={{header|Seed7}}==
<syntaxhighlight lang="seed7">$ include "seed7_05.s7i";
 
const func boolean: prime (in integer: number) is
return number in {2, 3, 5, 7, 11, 13, 17};
 
const func boolean: strange (in var integer: number) is func
result
var boolean: strange is TRUE;
begin
while number > 9 and strange do
if not prime(number rem 10 + number div 10 rem 10) then
strange := FALSE;
end if;
number := number div 10;
end while;
end func;
 
const proc: main is func
local
var integer: n is 0;
var integer: count is 0;
begin
for n range 101 to 499 do
if strange(n) then
write(n <& " ");
incr(count);
if count rem 13 = 0 then
writeln;
end if;
end if;
end for;
end func;</syntaxhighlight>
{{out}}
<pre>
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
</pre>
 
=={{header|SETL}}==
<syntaxhighlight lang="setl">program strange_plus_numbers;
$ a sum of two digits is never >18
primes := {2, 3, 5, 7, 11, 13, 17};
 
strangeplus := {
n : n in [101..499]
| lowpairsum(n) in primes and highpairsum(n) in primes
};
 
loop for n in strangeplus do
putchar(lpad(str n, 5));
if (i +:= 1) mod 10 = 0 then print; end if;
end loop;
print;
 
proc lowpairsum(n);
return n mod 100 div 10 + n mod 10;
end proc;
 
proc highpairsum(n);
return lowpairsum(n div 10);
end proc;
end program;</syntaxhighlight>
{{out}}
<pre> 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</pre>
 
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">100..500 -> map { .digits }.grep {|d|
is_prime(d[-1]+d[-2]) && is_prime(d[-2]+d[-3])
}.map{ .digits2num }.slices(10).each { .join(' ').say }</syntaxhighlight>
{{out}}
<pre>
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
</pre>
 
=={{header|V (Vlang)}}==
{{trans|Go}}
<syntaxhighlight lang="v (vlang)">fn is_prime(n int) bool {
return n == 2 || n == 3 || n == 5 || n == 7 || n == 11 || n == 13 || n == 17
}
fn main() {
mut count := 0
mut d := []int{}
println("Strange plus numbers in the open interval (100, 500) are:\n")
for i := 101; i < 500; i++ {
d = d[..0]
mut j := i
for j > 0 {
d << j%10
j /= 10
}
if is_prime(d[0]+d[1]) && is_prime(d[1]+d[2]) {
print("$i ")
count++
if count%10 == 0 {
println('')
}
}
}
if count%10 != 0 {
println('')
}
println("\n$count strange plus numbers in all.")
}</syntaxhighlight>
 
{{out}}
<pre>
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.
</pre>
 
=={{header|VTL-2}}==
<syntaxhighlight lang="vtl2">10 C=0
20 N=101
30 K=N
40 K=K/10
50 L=%
60 K=K/10
70 L=L+%
80 R=%+K
90 L=(L=2)+(L=3)+(L=5)+(L=7)+(L=11)+(L=13)+(L=17
100 R=(R=2)+(R=3)+(R=5)+(R=7)+(R=11)+(R=13)+(R=17
110 #=L*R*150
120 N=N+1
130 #=N<500*30
140 #=999
150 ?=N
160 $=32
170 C=C+1
180 #=C/10*0+0<%*!
190 ?=""
200 #=!</syntaxhighlight>
{{out}}
<pre>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 </pre>
 
=={{header|Wren}}==
Simple brute force is adequate for this.
<langsyntaxhighlight ecmascriptlang="wren">var primes = [2, 3, 5, 7, 11, 13, 17]
var count = 0
var d = []
Line 1,077 ⟶ 2,109:
}
if (count % 10 != 0) System.print()
System.print("\n%(count) strange plus numbers in all.")</langsyntaxhighlight>
 
{{out}}
Line 1,098 ⟶ 2,130:
A 16-bit solution for NASM under DOS. Assemble with <code>nasm -fbin strange.asm -o strange.com</code>. The prime sieve up to 18 is hard-coded.
 
<syntaxhighlight lang="text"> org 100h
 
mov cx, 10 ; cl is used for division, ch to count numbers printed on a line
Line 1,145 ⟶ 2,177:
 
p db 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0
k equ $-p</langsyntaxhighlight>
 
{{out}}
Line 1,156 ⟶ 2,188:
389 411 412 414 416 430 432 434 438 470
474 476 492 494 498</pre>
 
=={{header|XPL0}}==
<syntaxhighlight lang="xpl0">func StrangePlus(N);
int N, A, B, S;
[N:= N/10;
A:= rem(0);
loop [N:= N/10;
B:= rem(0);
S:= A+B;
if S#2 & S#3 & S#5 & S#7 & S#11 & S#13 & S#17 then return false;
if N = 0 then return true;
A:= B];
];
 
int Cnt, N;
[Cnt:= 0;
for N:= 100 to 500-1 do
if StrangePlus(N) then
[Cnt:= Cnt+1;
IntOut(0, N);
if rem(Cnt/20) = 0 then CrLf(0) else ChOut(0, ^ )];
]</syntaxhighlight>
 
{{out}}
<pre>
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
</pre>
9,476

edits