Thanks, Raul
On 2019-02-05 8:09 a.m., Raul Miller wrote:
A more compact variant, in case anyone wants that (though, granted,
without safety measures):
d12a=: 0 1}.]":@+10x^[
4 d12a a
0001
0002
0003
0010
0020
0030
0100
0200
0300
0400
1000
2000
3000
A "safer" version would be:
d12b=
A more compact variant, in case anyone wants that (though, granted,
without safety measures):
d12a=: 0 1}.]":@+10x^[
4 d12a a
0001
0002
0003
0010
0020
0030
0100
0200
0300
0400
1000
2000
3000
A "safer" version would be:
d12b=: -@[{."1]":@+10x^[
(Same result, for this example, but properl
Phrases 13C gives
d12=: [:}."1[:": (10"_^[)+([:,.])
Format list y as x-wide col with leading 0s
a=: 1 2 3 10 20 30 100 200 300 400 1000 2000 3000
4 d12 a
0001
0002
0003
0010
0020
0030
0100
0200
0300
0400
1000
2000
3000
The column form serves well in making a number list for ticke
Hi Skip,
Try this:
lz=: 3 : 0
,' '([,.~ -.~"1) ":10#.^:_1 y
)
lz 1 20 300 4000 5
1 00020 00300 04000 5
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 spe
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 Ro
000
> >
> >
> > R.E. Boss
> >
> >
> > > -Oorspronkelijk bericht-
> > > Van: Programming
> > > Namens 'Mike Day' via Programming
> > > Verzonden: zondag 3 februari 2019 10:55
> > > Aan: programm...@jsoftware
0500
> 1000 2000 3000 4000 5000
>
>
> R.E. Boss
>
>
> > -Oorspronkelijk bericht-
> > Van: Programming
> > Namens 'Mike Day' via Programming
> > Verzonden: zondag 3 februari 2019 10:55
> > Aan: programm...@jsoftware.com
> > Onder
SC> What's the best way to add leading zeros to a set of integers.
The compatible way, going back to J Version 5, 1992:
Over-take from the end with {. and Fit !. it to specify the fill
element:
_4 {.!.'0' 'ab'
00ab
Apply the usual extra stuff to have that work on your numeric list:
_4&
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
> 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 500
pad=: [ ($&'0'@:(- #@:]) , ]) ":@:]
4 g"0 0 a
0001
0002
0003
0004
0005
0010
0020
0030
...
On Sun, 2/3/19, 'Skip Cave' via Programming wrote:
Subject: [Jprogramming] Adding leading zeros
To: "programm...@js
> 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
ndag 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
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
Dyad
Fill =: verb define
:
|. x $ |. (x$'0'), ": y
)
5 Fill "0 a
Transform item of a to string
Add max number of patter in this case '0', x function parameter holds the
max length
Revert the string ex
take the max length (x)
Revert again the string
Example
Call Fill with 5 max length
And "0 needed
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 003
16 matches
Mail list logo