Santa's previous password expired, and he needs help choosing a new one.
To help him remember his new password after the old one expires, Santa has devised a method of coming up with a password based on the previous one. Corporate policy dictates that passwords must be exactly eight lowercase letters (for security reasons), so he finds his new password by incrementing his old password string repeatedly until it is valid.
Incrementing is just like counting with numbers:
xx
, xy
, xz
, ya
, yb
, and so on. Increase the rightmost letter one step; if it was z
, it wraps around to a
, and repeat with the next letter to the left until one doesn't wrap around.
Unfortunately for Santa, a new Security-Elf recently started, and he has imposed some additional password requirements:
abc
, bcd
, cde
, and so on, up to xyz
. They cannot skip letters; abd
doesn't count.i
, o
, or l
, as these letters can be mistaken for other characters and are therefore confusing.aa
, bb
, or zz
.For example:
hijklmmn
meets the first requirement (because it contains the straight hij
) but fails the second requirement requirement (because it contains i
and l
).abbceffg
meets the third requirement (because it repeats bb
and ff
) but fails the first requirement.abbcegjk
fails the third requirement, because it only has one double letter (bb
).abcdefgh
is abcdffaa
.ghijklmn
is ghjaabcc
, because you eventually skip all the passwords that start with ghi
..., since i
is not allowed.Given Santa's current password (your puzzle input), what should his next password be?
Your puzzle input is vzbxkghb
.
In [1]:
Letters=: 'abcdefghijklmnopqrstuvwxyz'
BadLetters=: Letters i. 'iol'
getLetters=: {&Letters
antibase26=: (8#26)&#:
getPassword=: getLetters@antibase26
hasStraight=: [: +./ 3 (-: 0 1 2 + {.)\ ]
hasNoBad=: -.@(+./)@:e.&BadLetters
has2DoubleLetters=: ((1 < +/) *. 0 1 0 +./@E. ])@(2 =/\ ])
chkPassword=: hasStraight,hasNoBad,has2DoubleLetters
validPassword=: *./@chkPassword
nextPassword=: (>:^:([: -.@validPassword antibase26)^:(_))&.(getPassword^:_1)
tst=: 'abcdefgh'
input=: 'vzbxkghb'
echo 'Day11 Part1: ',": nextPassword input
In [2]:
echo 'Day11 Part2: ',": nextPassword >:&.(getPassword^:_1) nextPassword input