diff options
author | Aleteoryx <alyx@aleteoryx.me> | 2024-12-03 03:53:49 -0500 |
---|---|---|
committer | Aleteoryx <alyx@aleteoryx.me> | 2024-12-03 03:56:22 -0500 |
commit | 645bf066b803f6a5b62aba177f792269b92e5377 (patch) | |
tree | 65c344f818db7f3aab7b765b401c3f0dbf466fdc /2024/tcl/lib.tcl | |
parent | 735b9fdf4535be1d721c59077e66def8b115d2ae (diff) | |
download | adventofcode-645bf066b803f6a5b62aba177f792269b92e5377.tar.gz adventofcode-645bf066b803f6a5b62aba177f792269b92e5377.tar.bz2 adventofcode-645bf066b803f6a5b62aba177f792269b92e5377.zip |
prep
Diffstat (limited to '2024/tcl/lib.tcl')
-rw-r--r-- | 2024/tcl/lib.tcl | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/2024/tcl/lib.tcl b/2024/tcl/lib.tcl index d816a25..698bb9a 100644 --- a/2024/tcl/lib.tcl +++ b/2024/tcl/lib.tcl @@ -1,9 +1,41 @@ -proc setup {n} { +proc setup {n {mode lines}} { puts "Advent of Code 2024 day $n Solution" puts "<https://adventofcode.com/2024/day/$n>" puts "" set n [string range 0$n end-1 end] upvar input input - set input [open input.$n.txt] + set fd [open input.$n.txt] + + switch -- $mode { + lines { + set input [split [string trim [read $fd]] "\r\n"] + close $fd + } + data { + set input [read $fd] + close $fd + } + fd { + set input $fd + } + } +} + +proc regroup {pat {var input}} { + upvar $var list + set list2 {} + set cur {} + foreach el $list { + if {[string match $pat $el]} { + if {$cur != {}} { + lappend list2 $cur + set cur {} + } + } else { + lappend cur $el + } + } + lappend list2 $cur + set list $list2 } |