I was not aware of this rosettacode task but by chance I was discussing
this problem with Thomas a couple of days ago.  A classic answer, due to
Gödel, is via the fundamental theorem of arithmetic but it is very
inefficient.



This is a slight variation of two verbs that I wrote some time ago:



   ( encode=. 11&#.@:>@:(,&:>/)@:(<@:(10&,)@:(10&#.^:_1)"0)@:x: )
11&#.@:>@:(,&:>/)@:(<@:(10&,)@:(10&#.^:_1)"0)@:x:
   ( decode=. 10&#.;._1@:(11&#.^:_1) )
10&#.;._1@:(11&#.^:_1)

   NB. This is the Python example,

   encode 1 2 3 10 100 987654321 135792468107264516704251 7x
10859468893418553562739357752202339093235635587121336

   decode 10859468893418553562739357752202339093235635587121336x
1 2 3 10 100 987654321 135792468107264516704251 7

   (-: decode@:encode) 1 2 3 10 100 987654321 135792468107264516704251 7x
1



On Thu, May 8, 2014 at 7:38 PM, Raul Miller <[email protected]> wrote:

>    A=: 1 2 3 10 100 987654321x
>    B=: 1+{:A
>    C=: B#.A
>    B #.inv C
> |nonce error
> |   B    #.inv C
>
> Hypothetically speaking, we want something that can find A, given B and C.
>
> Perhaps
>
>    A-:((>.B^.C)#B)#:C
> 1
>
> or
>
>    A-:B (((<.@%~,|){.),}.@])^:(<: {.)^:_ C
> 1
>
> I ran into this while playing with
> http://rosettacode.org/wiki/Index_finite_lists_of_positive_integers
>
> Currently, the J version is broken for the numeric list listed in the
> python solution, and that's just silly. I could fix it easily enough,
> but I've enough other things to do already.
>
> Thanks,
>
> --
> Raul
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to