Advertisement
SadBunny

AOC 2022 Day 6 parts 1+2 (AWK)

Dec 6th, 2022
1,668
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Awk 0.37 KB | Source Code | 0 0
  1. {
  2.     MARKER_SIZE = 4; # 14 for part 2;
  3.     while (n+=1) {
  4.             if (isCharsUnique(substr($0, n, MARKER_SIZE))) {
  5.                     print n + MARKER_SIZE - 1; break;
  6.             }
  7.     }
  8. }
  9.  
  10. func isCharsUnique(string,   i, ar) {
  11.     for (i=1;i<=length(string);i++) {
  12.             ar[substr(string, i, 1)] = 1;
  13.     }
  14.     return length(ar) == length(string);
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement