From f5f2f6e64ad4f114fcf2d84150daaf7c72f8fee9 Mon Sep 17 00:00:00 2001 From: Fennel Kora Date: Tue, 6 Dec 2022 10:52:47 -0500 Subject: [PATCH] 2022 Day 6 Changes to be committed: new file: 2022/day06/Day06A.class new file: 2022/day06/Day06A.java new file: 2022/day06/day06_algo.txt --- 2022/day06/Day06A.class | Bin 0 -> 1442 bytes 2022/day06/Day06A.java | 29 +++++++++++++++++++++++++++++ 2022/day06/day06_algo.txt | 23 +++++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 2022/day06/Day06A.class create mode 100644 2022/day06/Day06A.java create mode 100644 2022/day06/day06_algo.txt diff --git a/2022/day06/Day06A.class b/2022/day06/Day06A.class new file mode 100644 index 0000000000000000000000000000000000000000..1a6c1d0565ab3a9627f07a21cc301f5d0fdab0ec GIT binary patch literal 1442 zcmah}QBxCF6#i~@!%a4e1_+>rSgg_}ArNS(Z4F>Gf=wF;H8e_@&aiAQu$t^JLl|+*T0+sSin6E z0Vo`*jv)FNqW6u5Mz&_yyV=tAePK$5zIn^GD%H3?)_5N0k}{Fg}E zJGc4Yqg4B-Cq_;KN6brSm|?UNr`IA?@oYwQoWpsBkS+FQ(Xs_YEZK?Z3(&#U5J6nW z7!nK->E!ne_lD~l2MlU5wVBuO9>zH?>3AQPyIK3%_*Rrs#B>@5rJXw@Dq)0@oB2Y) zcbvcn93SdPB1JOaG7e_0-e5RWwVKkhO<6H&EkXW4@<@Fb#w0QvQ#z)R?c%g~9yFz> zlXOmtq#JH)Lb9%r=#r8UMm-n8EW-tlyJ1S-Yksmn!xx%3CE;eqHlAZh5U7G;2;%a4dJJ`01?gxy}#9c1>tl!k0P< z_==(5s8-9ZM#J?LVL10Tw|_ixUi%lj(TGu@w6t%EhO``;@bgZU%6r!9q}5h^Te#~U z3|-U>i|$8~?`q%*ftRIWK3FjtzCA~oA+VX}_?D2~;liMmotA5gWttjlu6El@d*gyj zn4od?ehNqc^wGLPZwcBN?ZNa@uqX7uuu7|U?X6*yutv|G>0dM%D(&@O!8ZoO$}>bx z(Ek)e#mQrg9OJ@@vY6=G%A7vJY$lQ5TPL`9f-65F@iWqcGwL%0HWdH(qw+C6yQ`dF z@lat$Z+;{Hn@1R0Y473H%+xV%XPzHHEj}T>1Na8_s3sfu9$T~ndw77aDIbsOGz}pT zBC9aYL&IfypM{Rw=qDSEe52$YBA+N~ek@=H;n#?BaE?1H`x3!rj-@x0AARrE{o^Gt zItso7yU8gG#imj02qB4+LYPy^d^~-sRv+O?T-{n2OH<~tbbKy7Hun>P%HzWTCHKc6 zqxE<7F*&peUnCqLM%0FB9ibA8(uZQ03KXN>jT2!I&EP8p*egU>^iKroPuLYd#NEFE D^(;#( literal 0 HcmV?d00001 diff --git a/2022/day06/Day06A.java b/2022/day06/Day06A.java new file mode 100644 index 0000000..2bcb2cb --- /dev/null +++ b/2022/day06/Day06A.java @@ -0,0 +1,29 @@ +import java.util.Scanner; +import java.nio.file.Paths; +import java.io.IOException; +import java.util.Arrays; + +public class Day06A { + public static void main (String[] args) { + try (Scanner inputFile = new Scanner(Paths.get("input.txt"))) { + char[] signal = inputFile.nextLine().toCharArray(); + for (int i = 0; i + 3 < signal.length; i++) { + if (distinctValues(Arrays.copyOfRange(signal, i, i + 4))) { + System.out.printf("Characters processed: %d%n", i + 4); + System.exit(0); + } + } + } catch (IOException e ) {} + } + + public static boolean distinctValues(char[] arr){ + for (int i = 0; i < arr.length-1; i++) { + for (int j = i + 1; j < arr.length; j++) { + if (arr[i] == arr[j]) { + return false; + } + } + } + return true; + } +} diff --git a/2022/day06/day06_algo.txt b/2022/day06/day06_algo.txt new file mode 100644 index 0000000..055594d --- /dev/null +++ b/2022/day06/day06_algo.txt @@ -0,0 +1,23 @@ +=== Main === +Open file +initialize counter p +Read full string into a char array. BEEG array +Loop - for i = 0, i + 3 < array length, i++ + feed rolling 4-char snapshot into check function index range i to i+3 + if check true (no duplicates) + print p to screen + if check false (has duplicates) + increment p +End Loop + +=== Check function === Reads char array +Outer Loop - for i = 0, i < array length - 1, i++ + Inner Loop - for j = i+1, j < array length, j++ + if array[i] == array[j] + return false + End Inner Loop +End Outer Loop +return true + +For Part B, change i+4 in lines 11 and 12 to i+14 (or size of range needed) + \ No newline at end of file