This may not be the best solution. f=.[:,[:|:' ',[:}.[:|:5":[:,.10000&+
f ,|:1 2 3 4 5*/10^0 1 2 3 0001 0002 0003 0004 0005 0010 0020 0030 0040 0050 0100 0200 0300 0400 0500 1000 2000 3000 4000 5000 Thank you. Bo. Den søndag den 3. februar 2019 12.27.59 CET skrev R.E. Boss <r.e.b...@outlook.com>: ,' '([,.~ -.~"1) ":10#.^:_1 a 0001 0002 0003 0004 0005 0010 0020 0030 0040 0050 0100 0200 0300 0400 0500 1000 2000 3000 4000 5000 R.E. Boss > -----Oorspronkelijk bericht----- > Van: Programming <programming-boun...@forums.jsoftware.com> > Namens 'Mike Day' via Programming > Verzonden: zondag 3 februari 2019 10:55 > Aan: programm...@jsoftware.com > Onderwerp: Re: [Jprogramming] Adding leading zeros > > Paolo has just beaten me to it, but I'll post this anyway. > > b NB. shorter than a, just to avoid line-wrapping > 1 10 100 1000 2 20 200 2000 3 30 300 3000 > > Monadic, with 4 and '000' embedded: > > (,@:((' ',~_4{.'000',":)"0)) b > 0001 0010 0100 1000 0002 0020 0200 2000 0003 0030 0300 3000 > > Dyadic - Essentially the same idea, but with 4 as a left argument: > > 4 (,@:((-@[ (' ',~ {.) ('0'#~[), ":@])"0)) b > 0001 0010 0100 1000 0002 0020 0200 2000 0003 0030 0300 3000 > > Note: > 0) for a sufficiently long numeric vector, you WILL need to deal with line- > wrapping! > 1) I couldn't see that the format foreigns, 8!:0 - 8!:2, cater for optional > leading > zeros > 2) NuVoc mentions the printf addon, which emulates C's printf. It was > contributed by Henry Rich, so he should be able to explain it when he gets on > line. > Cheers, > Mike > > On 03/02/2019 08:36, 'Skip Cave' via Programming 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 > > --- > This email has been checked for viruses by Avast antivirus software. > https://www.avast.com/antivirus > > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm