alignmentprimescode-formattingj

Alignment issue when printing formatted prime numbers in J language


I am a relatively new programmer in J-Lang and recently discovered its efficacy in Code Golfing, where it excels in scoring. I am currently working on a coding problem that involves printing all prime numbers under 100. While I have successfully implemented the code for this task, I am encountering difficulties in formatting the output as desired.

I have referred to the documentation to gain a better understanding of the language, but there are several concepts that I find challenging to grasp. My primary focus is on solving the given problem rather than deeply immersing myself in the intricacies of the language.

The code I have written currently looks like this:

echo p:i.25 1

I was expecting the output to resemble the following:

2
3
5
7
11
13
...

However, the actual output is:

 2
 3
 5
 7
11
13

I have attempted to address the alignment issue by trying different prime modes:

echo [X] p:i.25 1

as well as experimenting with string formatting:

echo ":p:i.25 1

Unfortunately, none of these solutions have resolved my problem, and I am seeking assistance in achieving the desired left-aligned output. Any guidance or suggestions would be greatly appreciated.


Solution

  • You need to 'echo' the atomic results, therefore you should format (":) every item ("0) of p:

    echo ":"0 p:i.25
    2
    3
    5
    7
    11
    13
    ...