ShareMyScreen/AdventOfCode/2022/06/TuningTrouble

From J Wiki
Jump to navigation Jump to search

The Problem << >>

This is almost trivial. I will use Infix 4 u\ y to look at successive groups of 4 characters, and find the first group of 4 that don't have repeated characters.

   4 + 1 i.~ 4 (=&# ~.)\ wd 'clippaste'
7

(=&# ~.) y executes as ((#y) = (#(~.y))) . For each infix, I see if the number of items in the infix equals the number of items in the nub of the infix. If so, all the characters are different. I will have processed the 4 characters of the infix plus one character for all preceding infixes.

For part 2, the only change is that the length 4 changes to 14. I could just make that change, but I prefer to pass the length in as an argument:

   14 ([ + 1 i.~  (=&# ~.)\) wd 'clippaste'  NB. executes as 14 + 1 i.~ 14 (=&# ~.)\ wd 'clippaste'