[Jprogramming] AOC 10 - explicit to tacit

Raul Miller rauldmiller at gmail.com
Mon Dec 11 15:39:53 UTC 2017


Oh, yes, so did I:

require'convert'

knothash=:3 :0
  (0,0,i.256) knothash y
:
  pos=. 0{x
  skip=. 1{x
  list=. 2}.x
  for_len.y do.
    inds=.(#list)|pos+i.len
    list=. (|.inds{list) inds} list
    pos=. (#list)|pos+len+skip
    skip=. skip+1
  end.
  pos,skip,list
)

xor=:22 b.

denseknot=:3 :0
  asc=.(a.i.y),17, 31, 73, 47, 23
  sparse=. 2}.knothash&asc^:64]0 0,i.256
  ,hfd _16 xor/\ sparse
)

knothash takes numeric arguments, denseknot takes literal arguments

My original implementation of knothash just had (list) as an argument,
but I changed it for part 2.

FYI,

-- 
Raul


On Mon, Dec 11, 2017 at 8:07 AM, David Lambert <b49p23tivg at gmail.com> wrote:
> I took advantage of j's residue definition for negative values. My verb
> rewrites the list keeping the "current position pointer" at the head,
> thereby losing track of the front of the list.
>
> (list tally) | negative sum of all advancements
>
> computes the front of the list.
>
>
> parta=: $:&256 : (4 :0)  NB. LENGTHS parta N
>  list=. i.y
>  skip=. 0
>  for_length. x do.
>   list=. (length + skip) |. length (|.@:{.)`(i.@:[)`]} list
>   skip=. >: skip
>   echo length ; skip ; list
>  end.
>  i=.+/(,i.@:#)x
>  list ; i ; ((#list) | -i) ; */ (0 1 + ((#list) | -i)){,~list
> )
>
> On 12/11/2017 07:00 AM, programming-request at forums.jsoftware.com wrote:
>>
>> From: Jimmy Gauvin<jimmy.gauvin at gmail.com>
>> To:programming at jsoftware.com
>> Subject: [Jprogramming] AOC 10 - explicit to tacit
>> Message-ID:
>>
>> <CAELWGOeukWZeMZv6rq4BnE5Jb4UJdUYHtjTmydAWZkfwBai1vQ at mail.gmail.com>
>> Content-Type: text/plain; charset="UTF-8"
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


More information about the Programming mailing list