There is special code for the digits of a number, using "."0@":
n =.<.@o. 10^50x
+/ "."0@": n
247
Answering Jabran's questions exactly:
+/ (~. * #/.~) 0&". , ' ' ,. ": n
247
+/ (~. * #/.~) 0&". , 1j1 # ": n
247
Henry Rich
On 3/21/2011 3:31 AM, Joey K Tuttle wrote:
> ]n =.<.@o. 10^50x
> 314159265358979323846264338327950288419716939937510
> ": n
> 314159265358979323846264338327950288419716939937510
> '0123456789' i. ": n
> 3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0 2 8
> 8 4 1 9 7 1 6 9 3 9 9 3 7 5 1 0
> +/ '0123456789' i. ": n
> 247
>
>
>
> At 10:55 AM +0400 11/03/21, Jabran Noor wrote:
>> I want to add up the digits in a long 50-digit number.
>>
>> Specifically, my question is
>>
>> 1. How to convert a number into a string... e.g. convert 12324343456456 into
>> a text format. I understand that using *":* works
>> 2. Now, in the output from 1, I want to insert a blank space between each
>> letter. I am struggling to do that. I tried reshaping etc but not getting
>> the desired results. What is one single verb which will do the trick for me.
>> 3. After that I will count the frequency of each number and multiply by the
>> number to get the total - This should not be difficult.
>>
>> Help with 2 would be very useful.
>>
>> Regards
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm