Nice explanation Daniel,

Tacit with hooks!

Xmas1t=: +/@#~ (= 1&|.)
Xmas2t=: +/@#~ (= -:@$ |. ])

Cheers, bob


> On Nov 30, 2017, at 10:43 PM, 'Pascal Jasmin' via Programming 
> <[email protected]> wrote:
> 
> tacit just enough to avoid repetition
> 
> +/ (#~ ] = 1 |. ] ) a
> +/ (#~ ] = -:@# |. ] ) a
> 
> 
> 
> 
> ________________________________
> From: Daniel Lyons <[email protected]>
> To: [email protected] 
> Sent: Friday, December 1, 2017 12:49 AM
> Subject: [Jprogramming] Advent of Code, Day 1 (spoilers)
> 
> 
> 
> The problem statement has to do with summing up digits in a large number if 
> the digit matches the following digit, with wraparound.
> 
> 
> My concept is to take the input as an array of single-digit numbers, compare 
> this to itself rotated forward a digit. Wherever those match up, the 
> following digit is a match. I can then copy to select the values that match 
> and then simply sum them up. It works out like this:
> 
> 
>   NB. First I want digits, so:
> 
>   a =. "."0 '<my big captcha string>'
> 
> 
>   NB. Part 1: the idea is to line up the input against itself, rotated right 
> one
> 
>   +/ a #~ a = 1 |. a
> 
> 
> This worked, and then the twist in problem 2 turned out to be easy to 
> compensate for: instead of hard-coding 1, calculate half the length of the 
> array:
> 
> 
>   NB. Part 2: rotate by half the length
> 
>   +/ a #~ a = (-: $ a) |. a
> 
> 
> I did not even try to define these as functions, since I was sure I'd lose 
> the plot trying to make them tacit and get frustrated.
> 
> 
> -- 
> 
> Daniel Lyons
> 
> 
> 
> 
> 
> ----------------------------------------------------------------------
> 
> For information about J forums see http://www.jsoftware.com/forums.htm
> ----------------------------------------------------------------------
> 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