some solutions posted on wiki,

n seems like a dangerous way to get the sectorID.  Relies on fixed length of 
field and id 3 digits long.  I don't know if that is a cause of error.


(p&> t)#(n&> t) is ok
(p # n)&> t is not

The first one applies # to vectors.  The 2nd to each cell.  This normally still 
works, but fills (0) are produced.


----- Original Message -----
From: Moon S <[email protected]>
To: programming <[email protected]>
Sent: Sunday, December 4, 2016 11:02 AM
Subject: [Jprogramming] [Jsoftware] AoC 2016 day 4

I have this code:

t =: cutLF CR-.~fread '04.dat'
a =: a.{~97+i.26                        NB. 'abc...z'
c =: 5{.a\:[:+/"1 a=/[:/:~_10}.'-'-.~]  NB. calculate checksum string
v =: c -: _1}._6&{.                     NB. checksums match = good string
n =: [:".3{._10{.]                      NB. extract number (id)
s =: 4 :'((26|x+])&.(_97+a.i.]))"0 y'   NB. shift cypher, n s 'str'
p =. +./@('north' E. n s ])             NB. if decrypted string contains
'north'
echo +/(n*v)&> t                        NB. sum of ids of good strings
echo +/(n*p)&> t                        NB. sum of ids of strings with
'north'
exit 0                                        NB. ^^^ we assume such string
is only one

It works, but I planned to use '#' instead of +/...*... for the second task.

Verb n takes a number from a string.
Verb p decrypts a string using the number and tells if it contains 'north'.
So far so good.
Noun t is the input data as boxed strings.
n&> t  gives numbers (like 111 222 333 444)
p&> t  gives a boolean vector (like 0 0 1 0)
The idea was to have something like "(p # n)&> t" but that didn't work.
(p&> t)#(n&> t) is ok
(p # n)&> t is not
Something wrong with ranks, I guess. Any idea how to use (p # n)?

Thank you.
Georgiy Pruss
----------------------------------------------------------------------
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