Prime numbers which contain 123: Difference between revisions

m
(→‎{{header|J}}: brief explanation)
m (→‎{{header|Wren}}: Minor tidy)
 
(9 intermediate revisions by 7 users not shown)
Line 10:
 
=={{header|11l}}==
<langsyntaxhighlight lang="11l">F is_prime(a)
I a == 2
R 1B
Line 35:
c++
print()
print(‘Found ’c‘ "123" primes less than 1000000’)</langsyntaxhighlight>
 
{{out}}
Line 52:
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<langsyntaxhighlight lang="algol68">BEGIN # find primes whose decimal representation contains 123 #
INT max prime = 1 000 000;
# sieve the primes to max prime #
Line 83:
OD;
print( ( newline, "Found ", whole( p123 count, 0 ), " ""123"" primes below ", whole( UPB prime, 0 ), newline ) )
END</langsyntaxhighlight>
{{out}}
<pre>
Line 97:
=={{header|Arturo}}==
 
<langsyntaxhighlight lang="rebol">upTo100K: select select 2..99999 => odd? => prime?
upTo1M: upTo100K ++ select select 100001..999999 => odd? => prime?
 
Line 106:
 
print ""
print ["'123' Numbers < 1000000:" size select upTo1M => contains123?]</langsyntaxhighlight>
 
{{out}}
Line 119:
 
=={{header|AWK}}==
<syntaxhighlight lang="awk">
<lang AWK>
# syntax: GAWK -f PRIME_NUMBERS_WHICH_CONTAIN_123.AWK
BEGIN {
Line 150:
return(1)
}
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 164:
 
=={{header|BASIC256}}==
<langsyntaxhighlight BASIC256lang="basic256">global columna
print "Prime numbers which contain 123"
print
Line 201:
endif
next n
end subroutine</langsyntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
 
bool isPrime( int number ) {
if ( number < 2 ) {
return false ;
}
int stop = std::sqrt( static_cast<double>( number ) ) ;
for ( int i = 2 ; i <= stop ; ++i )
if ( number % i == 0 )
return false ;
return true ;
}
 
bool condition( int n ) {
std::string numberstring { std::to_string( n ) } ;
return isPrime( n ) && numberstring.find( "123" ) != std::string::npos ;
}
 
int main( ) {
std::vector<int> wantedPrimes ;
for ( int i = 1 ; i < 100000 ; i++ ) {
if ( condition( i ) )
wantedPrimes.push_back( i ) ;
}
int count = 0 ;
for ( int i : wantedPrimes ) {
std::cout << i << ' ' ;
count++ ;
if ( count % 10 == 0 ) {
std::cout << std::endl ;
}
}
count = wantedPrimes.size( ) ;
for ( int i = wantedPrimes.back( ) + 1 ; i < 1000000 ; i++ ) {
if ( condition ( i ) )
count++ ;
}
std::cout << std::endl ;
std::cout << "There are " << count << " such numbers below 1000000!\n" ;
return 0 ;
}</syntaxhighlight>
{{out}}
<pre>
1123 1231 1237 8123 11239 12301 12323 12329 12343 12347
12373 12377 12379 12391 17123 20123 22123 28123 29123 31123
31231 31237 34123 37123 40123 41231 41233 44123 47123 49123
50123 51239 56123 59123 61231 64123 65123 70123 71233 71237
76123 81233 81239 89123 91237 98123
There are 451 such numbers below 1000000!
</pre>
 
=={{header|Clojure}}==
<syntaxhighlight lang="clojure">
(ns primes-found-app
(:require [clojure.string :as str])
(:gen-class))
 
(defn is-prime? [n]
(if (< 1 n)
(empty? (filter #(= 0 (mod n %)) (range 2 n)))
false))
 
(defn get-prime-numbers [n]
(filter is-prime? (take n (range))))
 
(defn numbers-to-str [xs]
(map #(str %) xs))
 
(defn is-includes-123? [s]
(str/includes? s "123"))
 
(defn solution [number]
(->>
(get-prime-numbers number)
(numbers-to-str)
(filter is-includes-123?)))
 
(defn main []
(let [result (count (solution 1000000))]
(prn (solution 100000))
(format "There are %d primes that contain '123' below 1000000." result)
))
 
(main)
 
</syntaxhighlight>
{{out}}
<pre>
("1123" "1231" "1237" "8123" "11239" "12301" "12323" "12329" "12343" "12347" "12373" "12377" "12379" "12391" "17123" "20123" "22123" "28123" "29123" "31123" "31231" "31237" "34123" "37123" "40123" "41231" "41233" "44123" "47123" "49123" "50123" "51239" "56123" "59123" "61231" "64123" "65123" "70123" "71233" "71237" "76123" "81233" "81239" "89123" "91237" "98123")
"There are 451 primes that contain '123' below 1000000."
</pre>
 
=={{header|CLU}}==
<langsyntaxhighlight lang="clu">isqrt = proc (s: int) returns (int)
x0: int := s/2
if x0=0 then return(s) end
Line 246 ⟶ 343:
stream$putl(po, "\nThere are " || int$unparse(count)
|| " primes that contain '123' below 1,000,000.")
end start_up</langsyntaxhighlight>
{{out}}
<pre> 1123 1231 1237 8123 11239 12301 12323 12329 12343 12347
Line 254 ⟶ 351:
76123 81233 81239 89123 91237 98123
There are 451 primes that contain '123' below 1,000,000.</pre>
 
=={{header|Delphi}}==
{{works with|Delphi|6.0}}
{{libheader|SysUtils,StdCtrls}}
 
 
<syntaxhighlight lang="Delphi">
 
procedure ShowPrimesWith123(Memo: TMemo);
var N,Sum,Cnt1,Cnt2: integer;
var NS,S: string;
begin
Cnt1:=0;
Cnt2:=0;
Sum:=0;
for N:=123 to 1000000-1 do
if IsPrime(N) then
begin
NS:=IntToStr(N);
if Pos('123',NS)>0 then
begin
Inc(Cnt1);
if N<100000 then
begin
Inc(Cnt2);
S:=S+Format('%6d',[N]);
If (Cnt2 mod 8)=0 then S:=S+CRLF;
end;
end;
end;
Memo.Lines.Add(S);
Memo.Lines.Add('Count < 100,000 = '+IntToStr(Cnt2));
Memo.Lines.Add('Count < 1,000,000 = '+IntToStr(Cnt1));
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
1123 1231 1237 8123 11239 12301 12323 12329
12343 12347 12373 12377 12379 12391 17123 20123
22123 28123 29123 31123 31231 31237 34123 37123
40123 41231 41233 44123 47123 49123 50123 51239
56123 59123 61231 64123 65123 70123 71233 71237
76123 81233 81239 89123 91237 98123
Count < 100,000 = 46
Count < 1,000,000 = 451
Elapsed Time: 147.996 ms.
 
</pre>
 
 
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)].
<langsyntaxhighlight lang="fsharp">
// Numbers containing 123. Nigel Galloway: July 14th., 2021
let rec fN g=if g%1000=123 then true else if g<1230 then false else fN(g/10)
primes32()|>Seq.takeWhile((>)100000)|>Seq.filter fN|>Seq.iter(printf "%d "); printfn ""
printfn "Count to 1 million is %d" (primes32()|>Seq.takeWhile((>)1000000)|>Seq.filter fN|>Seq.length)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 271 ⟶ 419:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
<langsyntaxhighlight lang="factor">USING: assocs formatting grouping io kernel literals math
math.functions math.functions.integer-logs math.primes
math.statistics sequences sequences.extras sequences.product
Line 306 ⟶ 454:
unzip cum-sum [ commas ] map swap zip
[ "Found %7s such primes under %s.\n" printf ] assoc-each
] time</langsyntaxhighlight>
{{out}}
<pre>
Line 326 ⟶ 474:
 
=={{header|FreeBASIC}}==
<langsyntaxhighlight lang="freebasic">
Dim Shared As Integer column
 
Line 360 ⟶ 508:
Print !"\n\n\Encontrados "; column; " n£meros primos por debajo de"; limite
Sleep
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 376 ⟶ 524:
 
Encontrados 451 números primos por debajo de 1000000
</pre>
 
 
 
=={{header|FutureBasic}}==
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
 
local fn IsPrime( n as long ) as BOOL
long i
BOOL result = YES
if ( n < 2 ) then result = NO : exit fn
for i = 2 to n + 1
if ( i * i <= n ) and ( n mod i == 0 )
result = NO : exit fn
end if
next
end fn = result
 
 
local fn PrimeWith123( limit as long )
long i, column = 1
CFStringRef numStr
NSLog( @"Prime numbers less than 100,000 which contain '123':\n" )
for i = 1 to limit
numStr = fn StringWithFormat( @"%lu", i )
if ( fn IsPrime( i ) ) and ( fn StringContainsString( numStr, @"123" ) )
NSLog( @"%-6lu\b", i )
if column == 10 then column = 0 : NSLog( @"" )
column++
end if
next
end fn
 
fn PrimeWith123( 100000 )
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Prime numbers less than 100,000 which contain '123':
 
12373 12377 12379 12391 17123 20123 22123 28123 29123 31123
31231 31237 34123 37123 40123 41231 41233 44123 47123 49123
50123 51239 56123 59123 61231 64123 65123 70123 71233 71237
76123 81233 81239 89123 91237 98123
</pre>
 
Line 382 ⟶ 578:
{{trans|Wren}}
{{libheader|Go-rcu}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 426 ⟶ 622:
}
fmt.Println("\nFound", count, "such primes under", climit, "\b.")
}</langsyntaxhighlight>
 
{{out}}
Line 440 ⟶ 636:
 
Found 451 such primes under 1,000,000.
</pre>
 
=={{header|Haskell}}==
<syntaxhighlight lang="haskell">
import Data.List ( isInfixOf )
 
isPrime :: Int -> Bool
isPrime n
|n < 2 = False
|otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root]
where
root :: Int
root = floor $ sqrt $ fromIntegral n
condition :: Int -> Bool
condition n = isPrime n && isInfixOf "123" ( show n )
 
solution :: [Int]
solution = filter condition [2..99999]</syntaxhighlight>
{{out}}
<pre>
[1123,1231,1237,8123,11239,12301,12323,12329,12343,12347,12373,12377,12379,12391,17123,20123,22123,28123,29123,31123,31231,31237,34123,37123,40123,41231,41233,44123,47123,49123,50123,51239,56123,59123,61231,64123,65123,70123,71233,71237,76123,81233,81239,89123,91237,98123]
</pre>
 
=={{header|J}}==
<langsyntaxhighlight Jlang="j"> p:I.1 2 3 +./@E."1/ 10 #.inv p:i.p:inv 1e5 NB. primes less than 1e5 containing decimal digit sequence 1 2 3
1123 1231 1237 8123 11239 12301 12323 12329 12343 12347 12373 12377 12379 12391 17123 20123 22123 28123 29123 31123 31231 31237 34123 37123 40123 41231 41233 44123 47123 49123 50123 51239 56123 59123 61231 64123 65123 70123 71233 71237 76123 81233 81239 89123 91237 98123
+/1 2 3 +./@E."1/ 10 #.inv p:i.p:inv 1e6 NB. count of primes less than 1e6 containing decimal digit sequence 1 2 3
451</langsyntaxhighlight>
 
<code>p:inv 1e5</code> is 9592 -- the number of primes less than 1e5. <code>p:i.9592</code> enumerates those primes (first is 2, last is 99991). <code>10 #.inv</code> converts this to the corresponding table of decimal digits (<code>0 0 0 0 2</code> for the first row, <code>9 9 9 9 1</code> for the last row). <code>1 2 3 +./@E."1 </code> identifies those rows containing the sequence <code>1 2 3</code>, and <code>I.</code> gets the indices of those rows and, finally, <code>p:</code> gets the prime numbers corresponding to those indices. Similarly, <code>+/</code> counts the rows with suitable primes.
Line 455 ⟶ 673:
 
For a suitable implementation of `is_prime`, see e.g. # [[Erd%C5%91s-primes#jq]].
<langsyntaxhighlight lang="jq">def count(stream): reduce stream as $i (0; .+1);
 
def digits: tostring | explode;
Line 468 ⟶ 686:
 
(1000000
| "\nThere are \(count(primes_with_123)) \"123\" primes less than \(.).")</langsyntaxhighlight>
{{out}}
(Abbreviated)
Line 487 ⟶ 705:
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Primes
 
function containstringinbase(N, str, base, verbose = true)
Line 498 ⟶ 716:
containstringinbase(1_000_000, "123", 10, false)
containstringinbase(1_000_000_000, "123", 10, false)
</langsyntaxhighlight>{{out}}
<pre>
Found 46 primes < 100000 which contain the string 123 in base 10 representation.
Line 513 ⟶ 731:
 
=={{header|Ksh}}==
<langsyntaxhighlight lang="ksh">
#!/bin/ksh
 
Line 557 ⟶ 775:
print ${parr[*]}
print ${#parr[*]} found under $MAX_SHOW
echo ; print ${primecnt} found under $MAX_COUNT</langsyntaxhighlight>
{{out}}<pre>1123 1231 1237 8123 11239 12301 12323 12329 12343 12347 12373 12377 12379
12391 17123 20123 22123 28123 29123 31123 31231 31237 34123 37123 40123 41231 41233 44123 47123
Line 566 ⟶ 784:
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">s1 = Select[Prime[Range[PrimePi[10^5]]], IntegerDigits/*(SequenceCount[#, {1, 2, 3}] &)/*GreaterThan[0]]
Length[s1]
 
Length[Select[Prime[Range[PrimePi[10^6]]], IntegerDigits/*(SequenceCount[#, {1, 2, 3}] &)/*GreaterThan[0]]]</langsyntaxhighlight>
{{out}}
<pre>{1123, 1231, 1237, 8123, 11239, 12301, 12323, 12329, 12343, 12347, 12373, 12377, 12379, 12391, 17123, 20123, 22123, 28123, 29123, 31123, 31231, 31237, 34123, 37123, 40123, 41231, 41233, 44123, 47123, 49123, 50123, 51239, 56123, 59123, 61231, 64123, 65123, 70123, 71233, 71237, 76123, 81233, 81239, 89123, 91237, 98123}
Line 576 ⟶ 794:
 
=={{header|Nim}}==
<langsyntaxhighlight Nimlang="nim">import sequtils, strutils
 
const N = 1_000_000 - 1 # Sieve of Erathostenes size.
Line 609 ⟶ 827:
var count = 0
for _ in primes123(1_000_000): inc count
echo "Found ", count, " “123” primes less than 1_000_000."</langsyntaxhighlight>
 
{{out}}
Line 624 ⟶ 842:
=={{header|Perl}}==
{{libheader|ntheory}}
<langsyntaxhighlight lang="perl">#!/usr/bin/perl
 
use strict;
Line 632 ⟶ 850:
my @hundredthousand = grep /123/, @{ primes(1e5) };
my $million = grep /123/, @{ primes(1e6) };
print "@hundredthousand\n\nmillion count is $million\n" =~ s/.{70}\K /\n/gr;</langsyntaxhighlight>
{{out}}
<pre>
Line 644 ⟶ 862:
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">m123</span><span style="color: #0000FF;">(</span><span style="color: #004080;">string</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">return</span> <span style="color: #7060A8;">match</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"123"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">s</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
Line 651 ⟶ 869:
<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;">"found %d &lt; 100_000: %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: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"found %d &lt; 1_000_000\n"</span><span style="color: #0000FF;">,{</span><span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">fn</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1_000_000</span><span style="color: #0000FF;">))})</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 660 ⟶ 878:
=={{header|PureBasic}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight PureBasiclang="purebasic">Procedure isPrime(v.i)
If v <= 1 : ProcedureReturn #False
ElseIf v < 4 : ProcedureReturn #True
Line 705 ⟶ 923:
PrintN(#CRLF$ + "Found " + Str(column) + " prime numbers below " + Str(limite))
Input()
CloseConsole()</langsyntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
Line 711 ⟶ 929:
=={{header|Python}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="python">
#!/usr/bin/python
 
Line 737 ⟶ 955:
prime(limite, False)
print("\n\nEncontrados ", columna, " números primos por debajo de", limite)
</syntaxhighlight>
</lang>
{{out}}
<pre>
Igual que la entrada de FreeBASIC.
</pre>
 
=={{header|Quackery}}==
 
<code>eratosthenes</code> and <code>isprime</code> are defined at [[Sieve of Eratosthenes#Quackery]].
 
<syntaxhighlight lang="Quackery"> 100000 eratosthenes
 
[ false swap
[ dup 122 > while
dup 1000 mod
123 = iff
[ dip not ]
done
10 / again ]
drop ] is contains123 ( n --> b )
 
[]
100000 times
[ i^ isprime if
[ i^ contains123 if
[ i^ join ] ] ]
[] swap witheach
[ number$ nested join ]
48 wrap$</syntaxhighlight>
 
{{out}}
 
<pre>1123 1231 1237 8123 11239 12301 12323 12329
12343 12347 12373 12377 12379 12391 17123 20123
22123 28123 29123 31123 31231 31237 34123 37123
40123 41231 41233 44123 47123 49123 50123 51239
56123 59123 61231 64123 65123 70123 71233 71237
76123 81233 81239 89123 91237 98123</pre>
 
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>my @p123 = ^∞ .grep: { (.is-primecontains: 123) && .contains: 123is-prime };
 
put display @p123[^(@p123.first: * > 1e5, :k)];
Line 753 ⟶ 1,005:
cache $list;
$title ~ $list.batch($cols)».fmt($fmt).join: "\n"
}</langsyntaxhighlight>
{{out}}
<pre>46 matching:
Line 769 ⟶ 1,021:
<br>the number of columns to be shown, &nbsp; and the decimal string that the primes must contain. &nbsp; A negative number for
<br>the number of columns suppresses the list of primes, &nbsp; but shows the total number of primes found.
<langsyntaxhighlight lang="rexx">/*REXX program finds & displays primes (in decimal) that contain the decimal digits 123.*/
parse arg hi cols str . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 100000 /*Not specified? Then use the default.*/
Line 811 ⟶ 1,063:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; sq.#= j*j /*bump # of Ps; assign next P; P square*/
end /*j*/; return</langsyntaxhighlight>
{{out|output|text=&nbsp; when using the default inputs:}}
<pre>
Line 832 ⟶ 1,084:
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
load "stdlib.ring"
row = 0
Line 853 ⟶ 1,105:
see nl + "Found " + row + " numbers" + nl
see "done..." + nl
</syntaxhighlight>
</lang>
{{out}}
<pre>
Line 871 ⟶ 1,123:
done...
</pre>
 
=={{header|RPL}}==
===Brute force===
≪ ALOG → max
≪ { } 1123
'''WHILE''' DUP max < '''REPEAT'''
NEXTPRIME
'''IF''' DUP →STR "123" POS '''THEN''' SWAP OVER + SWAP '''END'''
'''END''' NIP
≫ ≫ '<span style="color:blue">TASK</span>’ STO
{{out}}
<pre>
1: { 1123 1231 1237 8123 11239 12301 12323 12329 12343 12347 12373 12377 12379 12391 17123 20123 22123 28123 29123 31123 31231 31237 34123 37123 40123 41231 41233 44123 47123 49123 50123 51239 56123 59123 61231 64123 65123 70123 71233 71237 76123 81233 81239 89123 91237 98123 }
</pre>
Runs in 12 minutes 45 seconds on a HP-50g
 
===Lexicographic approach===
 
{| class="wikitable"
! RPL code
! Comment
|-
|
3 - DUP ALOG 1 - { } → ndigits maxleft results
≪ 0
'''DO'''
DUP DUP "" IFTE
ndigits OVER SIZE - ALOG 1 +
DUP 2 x 3 - '''FOR''' j
DUP "123" + j →STR TAIL + STR→
'''IF''' DUP ISPRIME? '''THEN''' 'results' STO+ '''ELSE''' DROP '''END'''
2 '''STEP'''
DROP 1 +
'''UNTIL''' DUP maxleft > '''END'''
DROP results
≫ ≫ '<span style="color:blue">PR123N</span>’ STO
|
<span style="color:blue">PR123N</span> ''( n_digits → { primes_with_123 } ) ''
n_digits -= 3 ; maxleft = 10^n_digits - 1
leftval = 0
loop
left = leftval == 0 ? "" ; leftval
tmp = 10^(n_digits - length(leftval)) + 1
for j = tmp to (tmp*2 - 3) step 2
n = left + "123" + j[2..]
add n to results if prime
next j
leftval++
end loop
display results (unsorted)
|}
4 <span style="color:blue">PR123N</span> 5 <span style="color:blue">PR123N</span> + SORT
Runs in 22 seconds on a HP-50g (35 times faster than brute force) - same results as above.
Finding the 451 primes under one million takes 4 minutes 30 seconds.
 
=={{header|Ruby}}==
<langsyntaxhighlight lang="ruby">require 'prime'
 
RE = /123/
puts Prime.each(100_000).select {|prime| RE.match? prime.to_s}.join(" "), ""
puts "#{Prime.each(1_000_000).count {|prime| RE.match? prime.to_s} } 123-primes below 1 million."
</syntaxhighlight>
</lang>
{{out}}
<pre>1123 1231 1237 8123 11239 12301 12323 12329 12343 12347 12373 12377 12379 12391 17123 20123 22123 28123 29123 31123 31231 31237 34123 37123 40123 41231 41233 44123 47123 49123 50123 51239 56123 59123 61231 64123 65123 70123 71233 71237 76123 81233 81239 89123 91237 98123
Line 884 ⟶ 1,192:
451 123-primes below 1 million.
</pre>
 
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">func numbers_with_subdigits(upto, base = 10, s = 123.digits(base)) {
Enumerator({|callback|
for k in (0 .. base**(upto.len(base) - s.len)) {
Line 917 ⟶ 1,224:
var count = numbers_with_subdigits(10**n).grep { .is_prime }.len
say "Found #{'%6s' % count.commify} such primes < 10^#{n}"
}</langsyntaxhighlight>
{{out}}
<pre>
Line 937 ⟶ 1,244:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
{{libheader|Wren-seq}}
The only number under 1,000 which can possibly satisfy the task description is 123 and that's clearly divisible by 3 and hence composite.
<langsyntaxhighlight ecmascriptlang="wren">import "./math" for Int
import "./fmt" for Fmt
import "/seq" for Lst
 
var limit = 1e5
Line 947 ⟶ 1,252:
var results = primes.where { |p| p < limit && p.toString.contains("123") }.toList
Fmt.print("Primes under $,d which contain '123' when expressed in decimal:", limit)
Fmt.tprint("$,7d", results, 10)
for (chunk in Lst.chunks(results, 10)) Fmt.print("$,7d", chunk)
Fmt.print("\nFound $,d such primes under $,d.", results.count, limit)
 
limit = 1e6
var count = primes.count { |p| p.toString.contains("123") }
Fmt.print("\nFound $,d such primes under $,d.", count, limit)</langsyntaxhighlight>
 
{{out}}
Line 969 ⟶ 1,274:
 
=={{header|XPL0}}==
<langsyntaxhighlight XPL0lang="xpl0">func IsPrime(N); \Return 'true' if N is a prime number
int N, I;
[if N <= 1 then return false;
Line 1,007 ⟶ 1,312:
];
CrLf(0); IntOut(0, Count); Text(0, " ^"123^" primes found below 1,000,000.");
]</langsyntaxhighlight>
 
{{out}}
Line 1,022 ⟶ 1,327:
=={{header|Yabasic}}==
{{trans|FreeBASIC}}
<langsyntaxhighlight lang="yabasic">
sub isPrime(v)
if v < 2 then return False : fi
Line 1,059 ⟶ 1,364:
print "\n\nEncontrados ", columna, " n£meros primos por debajo de ", limite
end
</syntaxhighlight>
</lang>
{{out}}
<pre>
9,476

edits