Palindromic primes in base 16: Difference between revisions
m
syntax highlighting fixup automation
(Added AppleScript.) |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 6:
=={{header|11l}}==
<
I a == 2
R 1B
Line 20:
I h == reversed(h) & is_prime(n)
print(h, end' ‘ ’)
print()</
{{out}}
Line 29:
=={{header|Action!}}==
{{libheader|Action! Sieve of Eratosthenes}}
<
BYTE FUNC Palindrome(CHAR ARRAY s)
Line 88:
OD
PrintF("%EThere are %I palindromic primes",count)
RETURN</
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Palindromic_primes_in_base_16.png Screenshot from Atari 8-bit computer]
Line 99:
=={{header|ALGOL 68}}==
{{libheader|ALGOL 68-primes}}
<
# sieve the primes to 499 #
PR read "primes.incl.a68" PR
Line 145:
FI
OD
END</
{{out}}
<pre>
Line 153:
=={{header|AppleScript}}==
<
if ((n < 4) or (n is 5)) then return (n > 1)
if ((n mod 2 = 0) or (n mod 3 = 0) or (n mod 5 = 0)) then return false
Line 190:
end task
task()</
{{output}}
<
=={{header|Arturo}}==
<
and? -> prime? a
-> equal? digits.base:16 a reverse digits.base:16 a
]
print map select 1..500 => palindrome? 'x -> upper as.hex x</
{{out}}
Line 209:
=={{header|AWK}}==
<syntaxhighlight lang="awk">
# syntax: GAWK -f PALINDROMIC_PRIMES_IN_BASE_16.AWK
BEGIN {
Line 240:
return(rts)
}
</syntaxhighlight>
{{out}}
<pre>
Line 253:
=={{header|F_Sharp|F#}}==
This task uses [http://www.rosettacode.org/wiki/Extensible_prime_generator#The_functions Extensible Prime Generator (F#)]
<
let rec fN g=[yield g%16; if g>15 then yield! fN(g/16)]
primes32()|>Seq.takeWhile((>)500)|>Seq.filter(fun g->let g=fN g in List.rev g=g)|>Seq.iter(printf "%0x "); printfn ""
</syntaxhighlight>
{{out}}
<pre>
Line 262:
</pre>
=={{header|Factor}}==
<
sequences.extras ;
500 primes-upto [ >hex ] [ dup reverse = ] map-filter .</
{{out}}
<pre>
Line 287:
=={{header|FreeBASIC}}==
<
Function isprime(num As Ulongint) As Boolean
For i As Integer = 2 To Sqr(num)
Line 317:
Print !"\n\nEncontrados"; cont; " primos palindrómicos entre " & inicio & " y " & final
Sleep
</syntaxhighlight>
{{out}}
<pre>2 3 5 7 B D 11 101 151 161 191 1B1 1C1
Line 326:
=={{header|Go}}==
{{libheader|Go-rcu}}
<
import (
Line 358:
}
fmt.Println("\n\nFound", count, "such primes.")
}</
{{out}}
Line 378:
For a suitable implementation of `is_prime`, see e.g. [[Erd%C5%91s-primes#jq]].
<syntaxhighlight lang="jq">
# '''Preliminaries'''
Line 391:
| map(if . < 10 then 48 + . else . + 87 end)
end;
</syntaxhighlight>
'''The Task'''
<
def palindromic_primes_in_base_16:
(2, (range(3; infinite; 2) | select(is_prime)))
Line 400:
| [., ($hex|implode)] ;
emit_until(.[0] >= 500; palindromic_primes_in_base_16)</
{{out}}
<pre>
Line 420:
=={{header|Julia}}==
<
ispal(n, base) = begin dig = digits(n, base=base); dig == reverse(dig) end
Line 427:
foreach(s -> print(s, " "), palprimes(500, 16)) # 2 3 5 7 b d 11 101 151 161 191 1b1 1c1
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
Giving the base 10 numbers and the base 16 numbers:
<
BaseForm[%, 16]</
{{out}}
<pre>
Line 440:
=={{header|Nim}}==
<
func isPalindromic(s: string): bool =
Line 466:
echo "Found ", list.len, " palindromic primes in base 16:"
echo list.join(" ")</
{{out}}
Line 473:
=={{header|Perl}}==
<
and $h = sprintf "%x", $_ # convert to hex
and $h eq reverse $h # palindromic?
and print "$h " # much rejoicing
for 1..500;</
{{out}}
<pre>1 2 3 5 7 b d 11 101 151 161 191 1b1 1c1</pre>
=={{header|Phix}}==
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">function</span> <span style="color: #000000;">palindrome</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: #000000;">s</span><span style="color: #0000FF;">=</span><span style="color: #7060A8;">reverse</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>
<span style="color: #004080;">sequence</span> <span style="color: #000000;">res</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">filter</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;">sprintf</span><span style="color: #0000FF;">,{{</span><span style="color: #008000;">"%x"</span><span style="color: #0000FF;">},</span><span style="color: #7060A8;">get_primes_le</span><span style="color: #0000FF;">(</span><span style="color: #000000;">500</span><span style="color: #0000FF;">)}),</span><span style="color: #000000;">palindrome</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: %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: #000000;">res</span><span style="color: #0000FF;">)})</span>
<!--</
{{out}}
<pre>
Line 497:
See [[Palindromic primes#Quackery]] for rest of code. This is a trivial modification.
<
500 times
[ i^ isprime if
[ i^ digits palindromic if
[ i^ echo sp ] ] ]
base release</
{{out}}
Line 511:
=={{header|Raku}}==
Trivial modification of [[Palindromic_primes#Raku|Palindromic primes]] task.
<syntaxhighlight lang="raku"
given (^500).grep: { .is-prime and .base(16) eq .base(16).flip };</
{{out}}
<pre>13 matching numbers:
Line 519:
=={{header|REXX}}==
<
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 500 /*Not specified? Then use the default.*/
Line 560:
end /*k*/ /* [↑] only process numbers ≤ √ J */
#= #+1; @.#= j; sq.#= j*j; !.j= 1 /*bump # of Ps; assign next P; P²; P# */
end /*j*/; return</
{{out|output|text= when using the default inputs:}}
<pre>
Line 573:
=={{header|Ring}}==
<
load "stdlib.ring"
see "working..." + nl
Line 593:
see nl + "Found " + row + " palindromic primes in base 16" + nl
see "done..." + nl
</syntaxhighlight>
{{out}}
<pre>
Line 609:
=={{header|Seed7}}==
<
Line 644:
end if;
end for;
end func;</
{{out}}
<pre>
Line 651:
=={{header|Sidef}}==
<
var list = []
for (var p = 2; p <= upto; p = p.next_palindrome(base)) {
Line 663:
list.each {|p|
say "#{'%3s' % p}_10 = #{'%3s' % p.base(16)}_16"
}</
{{out}}
<pre>
Line 684:
{{libheader|Wren-math}}
{{libheader|Wren-fmt}}
<
import "/fmt" for Conv, Fmt
Line 698:
}
}
System.print("\n\nFound %(count) such primes.")</
{{out}}
Line 711:
=={{header|XPL0}}==
<
int N, I;
[if N <= 1 then return false;
Line 741:
Text(0, " such numbers found.
");
]</
{{out}}
|