summaryrefslogtreecommitdiffstats
path: root/2024
diff options
context:
space:
mode:
authorAleteoryx <alyx@aleteoryx.me>2024-12-04 00:43:56 -0500
committerAleteoryx <alyx@aleteoryx.me>2024-12-04 00:44:04 -0500
commitfbf1ad5d946eceb3fd75cf9ddfb977623019d549 (patch)
tree890d517994fd5bb04821a4f639007d064c60eec1 /2024
parent645bf066b803f6a5b62aba177f792269b92e5377 (diff)
downloadadventofcode-fbf1ad5d946eceb3fd75cf9ddfb977623019d549.tar.gz
adventofcode-fbf1ad5d946eceb3fd75cf9ddfb977623019d549.tar.bz2
adventofcode-fbf1ad5d946eceb3fd75cf9ddfb977623019d549.zip
2024.4 try 1, unfinished
Diffstat (limited to '2024')
-rwxr-xr-x2024/tcl/04.tcl63
-rw-r--r--2024/tcl/lib.tcl8
2 files changed, 71 insertions, 0 deletions
diff --git a/2024/tcl/04.tcl b/2024/tcl/04.tcl
new file mode 100755
index 0000000..2e1742f
--- /dev/null
+++ b/2024/tcl/04.tcl
@@ -0,0 +1,63 @@
+#!/bin/env tclsh
+
+source lib.tcl
+setup 4
+
+puts {Part 1: XMAS word search count}
+
+set height [llength $input]
+set width [string length [lindex $input 0]]
+set w2 [expr {$height * 2}]
+set w3 [expr {$height * 3}]
+set input [join $input ""]
+
+set xmas_hits 0
+
+for {set i 0} {$i < [string length $input]} {incr i} {
+ set start $xmas_hits
+ if {$width - ($i % $width) > 3 && [sindex $input $i $i+1 $i+2 $i+3] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+ if {$i % $width > 3 && [sindex $input $i $i-1 $i-2 $i-3] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+
+ if {$height - ($i / $width % $height) > 3 && [sindex $input $i $i+$width $i+$w2 $i+$w3] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+ if {$i / $width % $height > 3 && [sindex $input $i $i-$width $i-$w2 $i-$w3] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+
+ # down-right
+ if {$height - ($i / $width % $height) > 3 && $width - ($i % $width) > 3 && [sindex $input $i [expr {$i+$width+1}] [expr {$i+$w2+2}] [expr {$i+$w3+3}]] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+ # down-left
+ if {$height - ($i / $width % $height) > 3 && $i % $width > 3 && [sindex $input $i [expr {$i+$width-1}] [expr {$i+$w2-2}] [expr {$i+$w3-3}]] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+ # up-right
+ if {$i / $width % $height > 3 && $width - ($i % $width) > 3 && [sindex $input $i [expr {$i-$width+1}] [expr {$i-$w2+2}] [expr {$i-$w3+3}]] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+ # up-left
+ if {$i / $width % $height > 3 && $i % $width > 3 && [sindex $input $i [expr {$i-$width-1}] [expr {$i-$w2-2}] [expr {$i-$w3-3}]] == "XMAS"} {
+ puts $i
+ incr xmas_hits
+ }
+}
+
+puts "Count: $xmas_hits"
+
+puts ""
+puts {Part 2: }
+
+puts "2: $"
diff --git a/2024/tcl/lib.tcl b/2024/tcl/lib.tcl
index 698bb9a..2968072 100644
--- a/2024/tcl/lib.tcl
+++ b/2024/tcl/lib.tcl
@@ -39,3 +39,11 @@ proc regroup {pat {var input}} {
lappend list2 $cur
set list $list2
}
+
+proc sindex {str args} {
+ set ret {}
+ foreach arg $args {
+ append ret [string index $str $arg]
+ }
+ return $ret
+}