I played around with this a bit more and arrived at something much faster than my initial approach which is in fact pretty slow.
Raul : 6!:2 'daten28601 5e6 $ 20180102' 1.40457 My first take : 6!:2 ' ff("0) 5e6 $ 20180102' 87.6379 My second take: 6!:2 'fff("0) 5e6 $ 20181122' 5.19095 ff =: 3 : '''-'' 4 7 } 1 1 1 1 2 1 2 1": 10#.inv y' fff =: 3 : '''0123456789-''{~0 0 0 0 10 0 0 10 0 0+10 10 10 10 1 10 10 1 10 10#: y' A variant on Raul's method is to use expand rather than copy (expand is slower though). b&#^:_1 where b is a boolean list is *Expand* (whose fill atom f can be specified by *fit*, b&#^:_1!.f or #^:_1!.f ) ]DYP=: -. (i.10)e.4 7 1 1 1 1 0 1 1 0 1 1 daten28602=: DYP #^:_1!.'-'"1 ":@,. On Wed, Apr 4, 2018 at 7:08 PM, Joe Bogner <joebog...@gmail.com> wrote: > Raul, that is great. I have used # thousands of times probably but > never encountered this use > > "The complex left argument a j. b copies a items followed by b fills. > The fit conjunction provides specified fills, as in #!.f ." > > http://www.jsoftware.com/help/dictionary/d400.htm > > > I'm glad I asked because something simple like this uncovers new ways > of thinking > > Jimmy - Same goes for yours too. Raul's approach is much speedier > however yours highlighted an interesting technique for the future. > > Thank you both > > On Wed, Apr 4, 2018 at 6:18 PM, Jimmy Gauvin <jimmy.gau...@gmail.com> > wrote: > > This might be fast : > > > > '-' 4 7 } 1 1 1 1 2 1 2 1 ": 10#.inv 20170209 > > > > 2017-02-09 > > > > > > On Wed, Apr 4, 2018 at 6:04 PM, Raul Miller <rauldmil...@gmail.com> > wrote: > > > >> Here's one approach: > >> > >> > > DXP=: (8#1) j. (i.8)e.3 5 > >> > > daten28601=: DXP #!.'-'"1 ":@,. > >> > >> > > 6!:2 'daten28601 (5e6 1 $ 20180102)' > >> 0.659381 > >> > >> -- > >> Raul > >> > >> On Wed, Apr 4, 2018 at 5:56 PM, Joe Bogner <joebog...@gmail.com> wrote: > >> > I'm curious if there is a speedier way to convert a date stored as a > >> > number like 20180101 or 20170228 to the ISO 8601 equivalent: > >> > > >> > This does OK > >> > > >> > datenumToISO =: 3 : 0 > >> > (4&{. , '-' , 2&{.@(4&}.) , '-' , _2&{.)"1 ": y > >> > ) > >> > > >> > datenumToISO 20180101 > >> > 2018-01-01 > >> > datenumToISO 20180228 > >> > 2018-02-28 > >> > > >> > > >> > But is slower than I'd like ... no big deal but just curious > >> > > >> > 6!:2 'datenumToISO (5e6 1 $ 20180102)' > >> > 4.29083 > >> > > >> > sprintf is slow > >> > > >> > dateNumToISO2 =: 3 : 0 > >> > '%d-%02d-%02d' sprintf ,:(0 100 100 #: y) > >> > ) > >> > > >> > (6!:2) 'dateNumToISO2 (1e5 # 20180102)' > >> > 2.34002 > >> > (6!:2) 'dateNumToISO2 (1e6 # 20180102)' > >> > 25.4977 > >> > > >> > > >> > 8!:2 shows promise but I can't figure out the formatting string to add > >> > a leading zero if it's possible > >> > > >> > (6!:2) '8!:2 (0 100 100 #: (5e6 # 20180102))' > >> > 1.4853 > >> > > >> > 'q<->,q<->,d' 8!:2 (0 100 100 #: (1 # 20180102)) > >> > 2018-1-2 > >> > ------------------------------------------------------------ > ---------- > >> > 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 > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm > ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm