I didn't look very hard/hard enough!
M
On 03/02/2019 13:45, Roger Hui wrote:
1) I couldn't see that the format foreigns, 8!:0 - 8!:2, cater for
optional leading zeros
a =: 1 2 3 4 5 10 20 30 40 50 100 200 300 400 500 1000 2000 3000 4000
5000
,' ',.'r<0>4.' 8!:2 ,.a
0001 0002 0003 0004 0005 0010 0020 0030 0040 0050 0100 0200 0300 0400 0500
1000 2000 3000 4000 5000
On Sun, Feb 3, 2019 at 1:54 AM 'Mike Day' via Programming <
programm...@jsoftware.com> wrote:
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