From 53014651e9b60bae28b295ffd20f39a476ed1c76 Mon Sep 17 00:00:00 2001 From: setop Date: Sun, 14 Apr 2024 01:16:42 +0200 Subject: [PATCH] day6, a set kills all --- d06/exec1.awk | 17 +++++++++++++++++ d06/exec2.awk | 2 +- d06/exec3.awk | 13 +++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 d06/exec1.awk create mode 100644 d06/exec3.awk diff --git a/d06/exec1.awk b/d06/exec1.awk new file mode 100644 index 0000000..3535407 --- /dev/null +++ b/d06/exec1.awk @@ -0,0 +1,17 @@ +{ N=0; # use -vW=4 or 14 + for (i=1; ; i++) { + window = substr($0,i,W) + # compare each char of the window to rest of the window + S = 0 # to count match + for (j=1; j j diff --git a/d06/exec3.awk b/d06/exec3.awk new file mode 100644 index 0000000..b189a77 --- /dev/null +++ b/d06/exec3.awk @@ -0,0 +1,13 @@ +{ # use -vW=4 or 14 + for (i=1; ; i++) { + window = substr($0,i,W) + for (j=1; j<=W; j++) { # populate a Set + A[substr(window,j,1)]=1 + } + if (length(A) == W) { + print i + W - 1 + next + } + delete A + } +} # O(N*W*log2(W)) \ No newline at end of file