Anonymous user
Palindromic primes in base 16: Difference between revisions
m
→{{header|REXX}}: changed comments.
m (added highlighting.) |
m (→{{header|REXX}}: changed comments.) |
||
Line 76:
=={{header|REXX}}==
<lang rexx>/*REXX program finds and displays palindromic primes in base 16 for all N <
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi=
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
call genP /*build array of semaphores for primes.*/
w= 8 /*max width of a number in any column. */
Line 88 ⟶ 87:
finds= 0; idx= 1 /*define # of palindromic primes & idx.*/
$= /*hex palindromic primes list (so far).*/
do j=1 for
x= d2x(j); if x\==reverse(x) then iterate /*Hex value not palindromic? " " */
finds= finds + 1 /*bump the number of palindromic primes*/
Line 106 ⟶ 105:
lowerHex: return translate( arg(1), 'abcdef', "ABCDEF") /*convert hex chars──►lowercase.*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
genP: !.= 0;
@.1=2; @.2=3; @.3=5; @.4=7; @.5=11 /*define some low primes. */
!.2=1; !.3=1; !.5=1; !.7=1; !.11=1 /* " " " " flags. */
#=5; s.#= @.# **2 /*number of primes so far; prime². */
/* [↓] generate more primes ≤ high.*/
do j=@.#+2 by 2 to
parse var j '' -1 _; if _==5 then iterate /*J divisible by 5? (right dig)*/
if j// 3==0 then iterate /*" " " 3? */
Line 123 ⟶ 122:
{{out|output|text= when using the default inputs:}}
<pre>
index │ palindromic primes in base 16 that are <
───────┼───────────────────────────────────────────────────────────────────────────────────────────
1 │ 2 3 5 7 b d 11 101 151 161
11 │ 191 1b1 1c1
───────┴───────────────────────────────────────────────────────────────────────────────────────────
</pre>
|