Oh, sorry, thinko: you wanted the first digit, and I gave you the last digit.
So:
[: +/@:({."1) 10 #.^:_1 p:@:i.
Or you could do something along the lines of:
+/@:(<.@:% >:@:<.&.(10&^.))@:p:@:i.
Of course, I haven't tested any of this, but the fact that I can respond in
such a manner from my blackberry, on my commute, without the aid of a J
interpreter, may tell you something about tacit programming.
In other words: using tacit code, we are communicating.
-Dan
PS: Of course, we could also communicate using explicit code or Fortran or
even standard math notation; it would just be harder to read & write under
these constraints.
For example, tacit's concise notation allows the reader to quickly spot the bug
in my initial suggestion (last digit vs first), and similarly allows the writer
to concisely express abstract concepts like &.(10&^.) .
(And elegantly, if I'm allowed to editorialize)
Please excuse typos; composed on a handheld device.
-----Original Message-----
From: Björn Helgason <[email protected]>
Sender: [email protected]
Date: Tue, 16 Nov 2010 12:38:39
To: Programming forum<[email protected]>
Reply-To: Programming forum <[email protected]>
Subject: Re: [Jprogramming] tacit programming
That is not giving the correct answer 43 for the first 15 primes
(10 +/@:#: p:@:i.) 15
68
([: +/ [: > [: ".&.> [: [ [: {.&.> [: [ [: ":&.>@p: i.) 15
43
2010/11/16 Dan Bron <[email protected]>
> Björn wrote:
> > The objective is to get the first number from a list of primes.
> >
> > Is there a better way of getting the first number from a list of numbers
> > putting them each in a box than making it first a character and the
> taking
> > the first of each element making it a number and summing up the resulting
> > list?
>
> I've always preferred to ask for digits directly (numerically), rather than
> projecting into the string domain and returning to the numeric domain:
>
> 10 +/@:#: p:@:i.
>
> -Dan
>
>
> ----------------------------------------------------------------------
> 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
sími: +3544781286
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
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm