[Jprogramming] Advent of code, Day 3 (spoilers probable)
Raul Miller
rauldmiller at gmail.com
Mon Dec 4 12:05:17 UTC 2017
I used Eugene's approach, also:
spiral =: ,~ $ [: /: }.@(2 # >:@i. at -) +/\@# <:@+: $ (, -)@(1&,)
aspiral=: (*: - |."1 at spiral)@>.@%:
steps=:3 :0"0
as=. aspiral y
+/|-/(($as)#:I.,1=as),($as)#:I.,y=as
)
steps 1 12 23 1024
0 3 2 31
FYI,
--
Raul
On Mon, Dec 4, 2017 at 2:02 AM, Brian Schott <schott.brian at gmail.com> wrote:
> I have only worked on part 1 so far.
> All my verbs are monadic and take the number in question as its argument.
>
>
> evenQ =. = <.&.-:
> size =. (+evenQ)@>.@%: NB. edge length
> border =. size-&*:_2+size NB. border length (number)
> lowest =. 1 _3 4& p. @ -:@<:@size NB. border's number which needs
> lowest # of moves
> least4 =. lowest+ (i. 4)*4%~border NB. border's 4 lowest # of moves
> least =. -:@<:@size NB. least # of moves
> addto =: least4<./@:(|@-)] NB. additional # of moves
> total =. least + addto
> total"0]1 12 23 1024
> 0 3 2 31
>
> I found the polynomial in `lowest` by studying the pattern of numbers 1 2
> 11 28 53
> as follows. (The fact that the 2nd differences are constantly 8 lead me to
> the
> solution.)
>
> 2-/\(^: 0 1 2)1 _3 4 p. i. 5
> 1 2 11 28 53
> _1 _9 _17 _25 0
> 8 8 8 0 0
>
>
> I had seen Eugene's evolute and now WRAP, so maybe the second part is
> doable, but I'm tired.
>
> --
> (B=) <-----my sig
> Brian Schott
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
More information about the Programming
mailing list