[Jprogramming] adventofcode 11

Ryan Eckbo eckbo at cim.mcgill.ca
Sat Dec 12 08:29:07 UTC 2015


You're right that it's buggy, because as Raul and Pascal have hinted at, 
'a' is acting as a 0
-- so each string is implicitly preceded by an 'a'.  Another consequence 
is that any password
beginning with an 'a' will be beheaded:

    inc 'z'  NB. 'z' equivalent to 'az'
ba
    inc 'axyz'  NB. beheaded
xza

One fix is to hardcode the number of letters:

    inc=: >:&.(26 26 26 26&#.)&.(alpha&i.)
    inc 'axyz'
axza


On 12 Dec 2015, at 14:49, Geoff Canyon wrote:

> On Fri, Dec 11, 2015 at 6:56 PM, Ryan Eckbo <eckbo at cim.mcgill.ca> 
> wrote:
>
>> inc=: >:&.(26&#.)&.(alpha&i.)
>>
>
> ​I get:
>
>  inc 'a'
> b
>  inc 'z'
> ba
>  inc 'y'
> z
>
> And my grasp of J isn't strong enough to figure out why. I came up 
> with
> this alternative that seems to work:
>
> inc =: ((26&|)@>:)&.(alpha&i.)
>
> Perhaps that could be simplified.
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm


More information about the Programming mailing list