]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
add day 6
authorClyne Sullivan <clyne@bitgloo.com>
Tue, 6 Dec 2022 12:30:40 +0000 (07:30 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Tue, 6 Dec 2022 12:30:40 +0000 (07:30 -0500)
day6/both.clj [new file with mode: 0644]
day6/part1.bas [new file with mode: 0644]

diff --git a/day6/both.clj b/day6/both.clj
new file mode 100644 (file)
index 0000000..817c17d
--- /dev/null
@@ -0,0 +1,10 @@
+(defn find-marker [data n]
+  (->> data
+       (partition n 1)
+       (map #(apply distinct? %))
+       (take-while false?)
+       (#(+ n (count %)))))
+
+(let [data (slurp "input")]
+    (doseq [ind [4 14]]
+      (println (find-marker data ind))))
diff --git a/day6/part1.bas b/day6/part1.bas
new file mode 100644 (file)
index 0000000..cb04c43
--- /dev/null
@@ -0,0 +1,61 @@
+REM Advent of Code 2022: Day 6, part 1
+REM Written in Applesoft BASIC
+
+ 5  HOME 
+ 10 A = 1000
+ 20 R = 0
+ 50  PRINT  CHR$ (4),"OPEN INPUT"
+ 60  PRINT  CHR$ (4),"READ INPUT"
+ 70  ONERR  GOTO 900
+ 100  PRINT "INITIALIZING COMMUNICATION SYSTEM";
+ 105 A = 350
+ 110  FOR I = 0 TO 6
+ 120  GOSUB 1000
+ 130  PRINT ".";
+ 140  NEXT I
+ 150  PRINT 
+ 200  PRINT "OPENING SIGNAL DATASTREAM";
+ 210  FOR I = 0 TO 6
+ 220  GOSUB 1000
+ 230  PRINT ".";
+ 240  NEXT I
+ 250  PRINT 
+ 260  PRINT 
+ 300  PRINT "SCANNING FOR START-OF-PACKET MARKER:"
+ 310  HTAB 1
+ 320  VTAB 8
+ 330  PRINT "||||";
+ 340  HTAB 1
+ 350  VTAB 10
+ 360  PRINT "||||";
+ 400  HTAB 1
+ 410  VTAB 9
+ 420  PRINT S$;
+ 430  IF  LEN (S$) >  = 4 GOTO 500
+ 440  GET C$
+ 450 S$ = C$ + S$
+ 455  IF  LEN (S$) > 40 THEN S$ =  MID$ (S$,1,40)
+ 460 A = 80
+ 470  GOSUB 1000
+ 475 R = R + 1
+ 480  GOTO 400
+ 500  HTAB 1
+ 510  VTAB 7
+ 530  IF  MID$ (S$,1,1) =  MID$ (S$,2,1) THEN  PRINT "/\  ";: GOTO 600
+ 540  IF  MID$ (S$,1,1) =  MID$ (S$,3,1) THEN  PRINT "/-\ ";: GOTO 600
+ 550  IF  MID$ (S$,1,1) =  MID$ (S$,4,1) THEN  PRINT "/--\";: GOTO 600
+ 560  IF  MID$ (S$,2,1) =  MID$ (S$,3,1) THEN  PRINT " /\ ";: GOTO 600
+ 570  IF  MID$ (S$,2,1) =  MID$ (S$,4,1) THEN  PRINT " /-\";: GOTO 600
+ 580  IF  MID$ (S$,3,1) =  MID$ (S$,4,1) THEN  PRINT "  /\";: GOTO 600
+ 590  PRINT "    ";
+ 595  GOTO 700
+ 600  GOTO 440
+ 620  VTAB 14
+ 700  HTAB 1
+ 710  VTAB 13
+ 720  PRINT "MARKER FOUND AT INDEX ";R;"."
+ 900  PRINT  CHR$ (4),"CLOSE"
+ 910  END 
+ 1000  FOR Z = 0 TO A: NEXT Z
+ 1010  RETURN 
+