How do you know what form the data must be entered in?

I guess h would be better than g, but it looked like the data was boxed.

g=: 13 :'+/10#.inv ".(y=1|.y)#y'
   g '1111'
4
   h=: 13 :'+/((10#.inv y)=1|.10#.inv y)#10#.inv y'
   h 1111
4
   g
[: +/ 10 #.^:_1 [: ". ] #~ ] = 1 |. ]
   
h
[: +/ ((10 #.^:_1 ]) = 1 |. 10 #.^:_1 ]) # 10 #.^:_1 ]
   
g '3234455343'
12
   h 3234455343
12

I haven't tried these  before so I just tried to get an explicit definition 
from many other suggestions.  Somehow ^: popped up.

Linda


Linda

-----Original Message-----
From: Programming [mailto:[email protected]] On Behalf 
Of Joe Bogner
Sent: Friday, December 1, 2017 10:06 PM
To: [email protected]
Subject: Re: [Jprogramming] Advent of Code, Day 1 (spoilers)

A little late, but mine appears to be similar

day1a =: [: +/ "."0 @ (] #~ 1&|. = ])

day1b =: [: +/ "."0 @ (] #~ (|.~ (2%~#)) = ])



assert 3 -: day1a '1122'

assert 4 -: day1a '1111'


assert 6 -: day1b '1212'

assert 4 -: day1b '123425'

assert 12 -: day1b '123123'

assert 4 -: day1b '12131415'






On Fri, Dec 1, 2017 at 2:22 AM, robert therriault <[email protected]>
wrote:

> 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
>
----------------------------------------------------------------------
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