I've experimented with this sort of thing before.  It was when I had first
heard of J
and heard it compared to "line noise".  Since I was proficient in APL, I
wrote a little
random string executor in STSC APL and ran strings of varying length to see
how many
would give valid expressions.  Interestingly, I found a combination of three
characters which,
if they appeared in any line in the correct order - not even contiguously -
would allow the line
to avoid giving an error when executed.  I don't recall what the three magic
characters were.

So, I just tried this experiment with J using the following:

   ]CHARS=: 95{.32}.a.
!"#$%&'()*+,-./0123456789:;<=>[EMAIL PROTECTED]|}~

testRndStr=: 3 : 0
   'na sl'=. y NB. # of Attempts, String Lengths to try
   good1s=. ''
   while. 0<:na=. <:na do.
       try. ".rs=. CHARS{~?sl$#CHARS
       catch. rs=. '' end.
   good1s=. good1s,(0~:#rs)#<rs
   end.
   good1s
)
   $aa=. testRndStr 277 10
84
   84%277
0.3032491

NB. Surprisingly high percentage because of inclusion of letters:
   >3{.aa
R&tYE*fHr
UA|.y.L{q
p?0$GRD#S5

This gives a lot of grammatically correct strings with undefined tokens
which
J avoids treating as errors until they are evaluated with an argument.

Also, the reason I chose the odd number of 277 iterations above is that
running
this with one more iteration caused my session to terminate.  Modifying the
code to
write out each string before attempting to evaluate it revealed this as the
offending one:

q;1({Son T

This is because I have "q" defined in my default environment as "signoff".
I can eliminate all defined names like this:
4!:55&><"0 nl 0
4!:55&><"0 nl 1
4!:55&><"0 nl 2
4!:55&><"0 nl 3

Maybe I should run this with no alphabetic characters but, retaining them
gives results like the following
(after erasing all defined names except the few I need):

   (+/%#)([EMAIL PROTECTED]) &>10$<10000 5
5354.5
   (+/%#)([EMAIL PROTECTED]) &>10$<10000 10
3270
   (+/%#)([EMAIL PROTECTED]) &>10$<10000 20
1284.5
   (+/%#)([EMAIL PROTECTED]) &>10$<10000 40
247.2
   (+/%#)([EMAIL PROTECTED]) &>10$<10000 80
30.3
   (+/%#)([EMAIL PROTECTED]) &>10$<10000 160
10.7

So, as one would expect, the likelihood of generating a valid string
declines as the
length of the string.


On 9/25/07, Stuart Baker <[EMAIL PROTECTED]> wrote:
>
> I wonder what is the probability that a randomly selected string of a
> given length (maybe with an agreed proportion of non-alpha characters)
> is actually executable in J? What kind of probability distribution
> over increasing string length would you get? Overall it must be a lot
> higher than with most of the other languages - I have occasionally
> slumped over the keyboard late at night and accidentally entered
> gibberish - no Shakespeare yet, but occasionally something happens
> other than just getting an error...
>
> (another Stuart - Baker)
>
> On 9/23/07, Stuart Bruff <[EMAIL PROTECTED]> wrote:
> > Out of curiosity, how many of you would automatically try (as I did) to
> > interpret the following nonsense that appeared as the header from a
> piece of
> > spam I received?
> >
> > :[[(- .]]:!*:  +()!    *)[(:[ !  )+!*-!
> >
> > I initially thought it was a misplaced J Forum email.  I can't decide
> whether
> > it's sadder that I tried to interpret it, or that it took me about 3
> seconds to
> > realize it what it actually was :-(
> >
> > Stuart
> > ----------------------------------------------------------------------
> > For information about J forums see http://www.jsoftware.com/forums.htm
> >
> ----------------------------------------------------------------------
> 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

Reply via email to