I prefer (#.^:_1) as it goes directly to numbers and is more general. f=:#.^:_1 +/10 f 12345 NB. Sum of digits 15 +/2 f 12345 NB. Count the one bits 6
On Fri, Apr 29, 2011 at 6:47 AM, Devon McCormick <[email protected]> wrote: > You need to turn the result back into numbers after doing the "filled copy" > (1j1#): > > ".1j1#":12345 > 1 2 3 4 5 > +/".1j1#":12345 > 15 > > 2011/4/29 Björn Helgason <[email protected]> > > > 1j1#":12345 > > > > 2011/4/29 bill lam <[email protected]> > > > > > one way is > > > ]a=. ".,.":12345 > > > 1 2 3 4 5 > > > +/a > > > 15 > > > > > > project euler? > > > > > > Птн, 29 Апр 2011, Daniel Roe писал(а): > > > > > > > > If we add up the digits of the number 12345 we get 1+2+3+4+5 = 15. > > > > I want to be able to do math upon the individual digits. > > > > How would I do that in J? > > > > Dan > > > > > > > > > ---------------------------------------------------------------------- > > > > For information about J forums see > http://www.jsoftware.com/forums.htm > > > > > > -- > > > regards, > > > ==================================================== > > > GPG key 1024D/4434BAB3 2008-08-24 > > > gpg --keyserver subkeys.pgp.net --recv-keys 4434BAB3 > > > ---------------------------------------------------------------------- > > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > > > > > > > -- > > Björn Helgason, Verkfræðingur > > Fornustekkum II > > 781 Hornafirði, > > t-póst: [email protected] > > gsm: +3546985532 > > twitter: @flugfiskur > > http://groups.google.com/group/J-Programming > > > > > > Tæknikunnátta höndlar hið flókna, sköpunargáfa er meistari einfaldleikans > > > > góður kennari getur stigið á tær án þess að glansinn fari af skónum > > /|_ .-----------------------------------. > > ,' .\ / | Með léttri lund verður | > > ,--' _,' | Dagurinn í dag | > > / / | Enn betri en gærdagurinn | > > ( -. | `-----------------------------------' > > | ) | (\_ _/) > > (`-. '--.) (='.'=) ♖♘♗♕♔♙ > > `. )----' (")_(") ☃☠ > > ---------------------------------------------------------------------- > > For information about J forums see http://www.jsoftware.com/forums.htm > > > > > > -- > Devon McCormick, CFA > ^me^ at acm. > org is my > preferred e-mail > ---------------------------------------------------------------------- > For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
