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 < 1000500. */
parse arg hi cols . /*obtain optional argument from the CL.*/
if hi=='' | hi=="," then hi= 200500 /*Not specified? Then use the default.*/
if cols=='' | cols=="," then cols= 10 /* " " " " " " */
hidec= x2d(hi) /*obtain the decimal value of hi (hex).*/
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 hidechi; if \!.j then iterate /*J (decimal) not prime? Then skip.*/
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; hprimehip= max(hidechi, reversecopies(hidec9,length(hi))) /*placeholders for primes (semaphores).*/
@.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 hprimehip /*find odd primes from here on. */
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=&nbsp; when using the default inputs:}}
<pre>
index │ palindromic primes in base 16 that are < 200500
───────┼───────────────────────────────────────────────────────────────────────────────────────────
1 │ 2 3 5 7 b d 11 101 151 161
11 │ 191 1b1 1c1
───────┴───────────────────────────────────────────────────────────────────────────────────────────
 
Found 13 palindromic primes in base 16 that are < 200
</pre>