The negative order integer challenge, but it's Prime Time!
Processing, 161 bytes
int p(int n){for(int k=1;++k<=sqrt(n);)if(n%k<1)return 0;return 1;}void t(int n){for(int i=1,j;i<=n;i++){if(p(i)<1)continue;for(j=i;j>0;j--)print(p(j)<1?"":j);}}
One function does the primality checking, the other does the printing. Call it by t(7)
Ungolfed
The first function does the primality checking. It returns an int
instead of a boolean
since this way more bytes are saved. (int
instead of boolean
, 0
instead of false
, 1
instead of true
)
int Q103891p(int n){
for(int k=1;++k<=sqrt(n);)
if(n%k<1)return 0;
return 1;
}
The second function prints out the string. It iterates through every number, if it is not a prime, skip to the next iteration. If it is a prime, it continues down to the printing inside another for
-loop. Again, if the number is prime, then we print it, otherwise not.
void Q103891(int n){
for(int i=1,j;i<=n;i++){
if(p(i)<1)continue;
for(j=i;j>0;j--)
print(p(j)<1?"":j);
}
}
Jelly, 12 bytes
ÆR;@1
ÇÇ€UVV
Try it online!
If it hadn't been for 1
s at all, my code would have just been ÆRÆRUVV
for 7 bytes.
Enhanced explanation:
ÇÇ€UVV Main link. Arguments: z.
Ç Run link1 on z.
Ç€ Run link1 on z's elements.
U Reverse z's elements.
V Flatten z.
V Concatenate z's elements.
ÆR;@1 Link 1. Arguments: z.
ÆR Range of primes [2..z].
1 Integer: 1.
;@ Concatenate x to y.
The Irish guy (called Dennis?) somehow outgolfed me lol.
Jelly, 9 bytes
ÆR1;;\UFV
Try it online!
How it works
ÆR1;;\UFV Main link. Argument: n
ÆR Prime range; yield all primes up to n.
1; Prepend the "prime" 1.
;\ Cumulative concatenation; yield all prefixes of the prime range.
U Upend; reverse each prefix.
F Flatten the resulting 2D array.
V Eval. This casts the integer array to string first, thus concatenating
the integers.