Xah Talk Show 2022-12-21 Advent of Code Day 6, in WolframLang, Live Coding
part 1
Given a string, find the first 4 sequence of characters that are all different. what is the last index of the character. (count start at 1)
examples:
b vwbj plbgvbhsrlpgdmjqwftvncz
→ 5np pdvj thqldpwncqszvftbrmjlhg
→ 6nznrnf rfnt jfmvfwmzdfjlvtqnbhcprsg
→ 10zcfzfwz zqfr ljwzlrfnpqdbhtmscgvjw
→ 11
x1 = "zcfzfwzzqfrljwzlrfnpqdbhtmscgvjw" Position[ Map[ Function[{x}, UnsameQ @@ StringPartition[x, 1] ], StringPartition[ x1, 4, 1 ]], True, {1}, 1] + 3
part 2
give a string, find the first sequence of 14 distinct characters, answer the last character's index. (index start at 1)
x1 = "mjqjpqmgbljsphdztnvjfqwrcgsmlb" x2 = StringPartition[ x1, 14, 1 ] Position[ Map[ Function[{x}, UnsameQ @@ StringPartition[x, 1] ], x2], True, {1}, 1] + 13 (* 19 *)