Hi Skip,

Try this:

lz=: 3 : 0

,' '([,.~ -.~"1) ":10#.^:_1 y

)


     lz 1 20 300 4000 50000

00001 00020 00300 04000 50000

Good Luck,

Dave

On 2/3/2019 2:15 PM, 'Skip Cave' via Programming wrote:
Paolo and Devon provided the named dyadic verbs Fill and lead0s that
perform the function I specified. Devon's verb has some extra bells and
whistles which I like.
Roger pointed out that the built-in format function 8!:2 allows a fill
option, but with my limited J expertise I wasn't able to turn Roger's
example into a named dyadic verb.
I liked R.E. Boss' approach, as it automatically sets the number of
characters, given the number of characters in the largest integer, as that
would work for my current problem. Again, however, I don't know how to turn
that verb into a named monadic verb.
All in all, I learned quite a lot from this exercise.

Skip


On Sun, Feb 3, 2019 at 2:36 AM Skip Cave <[email protected]> wrote:

What's the best way to add leading zeros to a set of integers. How to
design a verb f, that does the following:

    a =.  1 2 3 4 5 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000
5000
4 f a NB. make each integer a total of 4 digits using leading zeros.
0001 0002 0003 0004 0005 0010 0020 0030 0040 0050 0100 0200 0300 0400 0500
1000 2000 3000 4000 5000

Skip


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to