diff options
Diffstat (limited to '2024/tcl')
-rwxr-xr-x | 2024/tcl/01.tcl | 33 | ||||
-rw-r--r-- | 2024/tcl/input.01.txt | 1000 | ||||
-rw-r--r-- | 2024/tcl/lib.tcl | 9 |
3 files changed, 1042 insertions, 0 deletions
diff --git a/2024/tcl/01.tcl b/2024/tcl/01.tcl new file mode 100755 index 0000000..462a7a9 --- /dev/null +++ b/2024/tcl/01.tcl @@ -0,0 +1,33 @@ +#!/bin/env tclsh + +source lib.tcl +setup 1 + +puts {Part 1: Find the sum of distances between pairs of numbers with the same ordinal in each list.} + +while {[gets $input line] != -1} { + lassign [regexp -inline -all {\d+} $line] ln rn + + lappend left_nums $ln + lappend right_nums $rn + + dict incr right_num_counts $rn +} + +close $input + +set left_nums [lsort -integer $left_nums] +set right_nums [lsort -integer $right_nums] + +foreach ln $left_nums rn $right_nums { + incr total1 [expr {abs($ln - $rn)}] + + if [dict exists $right_num_counts $ln] { + incr total2 [expr {$ln * [dict get $right_num_counts $ln]}] + } +} + +puts "Sum of distances: $total1" +puts "" +puts {Part 2: Find the "Similarity Score" of the lists.} +puts "Similarity Score: $total2" diff --git a/2024/tcl/input.01.txt b/2024/tcl/input.01.txt new file mode 100644 index 0000000..cf109b6 --- /dev/null +++ b/2024/tcl/input.01.txt @@ -0,0 +1,1000 @@ +80421 40193 +69841 31045 +47850 64065 +63141 52072 +32908 83033 +33395 25559 +78513 59127 +91270 76329 +65508 34159 +27139 15788 +13228 50396 +43186 29116 +55392 52441 +19309 68909 +72798 54258 +31590 11220 +32125 81946 +58099 50396 +16614 76682 +60604 12184 +21251 26105 +56053 96112 +47903 13396 +72956 11681 +66315 11220 +54499 96112 +38390 83884 +69211 52732 +69235 52441 +83831 49092 +25782 75523 +35417 15162 +45889 82918 +76191 97182 +95942 49643 +30121 83884 +86470 16217 +23572 11220 +69703 80739 +45792 21543 +76682 70230 +79585 83884 +64501 69361 +55546 92076 +43632 87826 +93309 17223 +73996 69071 +83466 42385 +73963 19398 +36643 98070 +43789 15788 +54302 70897 +83362 50227 +60881 66983 +61881 17864 +81520 52171 +99147 41180 +63427 16217 +50290 40193 +19315 20520 +84997 27666 +45495 40509 +81512 76682 +93459 11220 +28126 72353 +38227 11681 +49613 27677 +26858 40193 +16759 51946 +42145 90200 +64421 88733 +97361 16019 +32616 75596 +30875 90149 +82019 50759 +90554 83033 +42030 75763 +64459 32394 +45152 83884 +51375 48768 +71487 93793 +69694 84439 +97213 70998 +65471 90900 +69237 48307 +50672 58376 +61500 58064 +22831 76682 +63626 90356 +43195 87826 +67468 11770 +59753 97698 +34386 97698 +84851 23296 +96001 69910 +41418 13027 +82815 27666 +37012 17864 +45122 57830 +81552 44943 +18717 33011 +28726 87826 +29453 52441 +82398 24963 +47384 87826 +24205 50966 +80001 43568 +17033 21145 +74890 54233 +59065 58047 +33505 96112 +96403 34213 +35992 94345 +74353 27666 +59539 37101 +90355 71860 +86007 11220 +50733 76682 +75113 94664 +56735 87038 +27654 16492 +39478 47633 +70998 95331 +19885 38941 +47463 26105 +74771 28343 +56762 87773 +89980 35218 +35434 71473 +97275 53382 +97389 28343 +55060 11220 +83189 74164 +65464 75140 +15091 58376 +49752 94345 +55978 50227 +13991 40193 +58778 69071 +99285 16217 +37693 40193 +61282 71473 +34624 87374 +53881 13912 +67666 58376 +51235 52441 +80739 99593 +40193 97698 +94214 83205 +13145 72473 +88888 40193 +46957 96567 +92406 59738 +85389 13942 +55969 52441 +91426 46497 +92608 63775 +71473 24823 +51744 50396 +77645 42696 +34121 96112 +99775 96112 +89480 98660 +42647 95861 +35131 98522 +22031 76805 +10282 43806 +82323 65743 +79408 89179 +50692 85420 +89878 70998 +46431 17223 +99643 52441 +61276 68075 +14058 83884 +94292 17411 +92506 40193 +91012 17223 +51557 55254 +50846 96567 +20336 84821 +71617 81946 +40314 84439 +42990 89703 +62455 27446 +65790 94345 +57568 65105 +13052 79090 +30028 96128 +42028 58852 +47372 87826 +44459 90200 +67988 66776 +28313 84439 +52545 94345 +17108 37412 +16113 11681 +56064 54165 +60025 37314 +85545 11681 +68437 25575 +46677 20626 +53308 28343 +79483 70998 +54308 55727 +26755 69337 +73791 50227 +33565 83884 +35359 17223 +47840 26266 +50109 75074 +88842 39316 +84439 97698 +86029 96112 +39964 79122 +37828 69071 +73120 96567 +67688 50227 +61996 70230 +62643 82883 +99604 28343 +18054 76682 +52441 97698 +45131 58376 +32102 53380 +60963 53418 +73803 41652 +56361 70998 +74041 77517 +14940 84439 +80439 26105 +79199 83033 +41700 83033 +35229 65677 +64958 84439 +51246 78550 +23506 31244 +26237 40038 +49105 27712 +62117 37779 +76884 94345 +56414 62009 +88424 80739 +97192 15788 +70374 59226 +53515 76682 +85931 28343 +50925 38390 +51959 96567 +98082 28525 +37588 29342 +52624 37871 +28331 16217 +73762 94345 +73815 38390 +38573 25210 +88916 97698 +66917 28343 +47055 73500 +97902 34391 +16580 82128 +18015 91780 +77218 14792 +22251 37702 +62344 94345 +49811 73150 +43220 58572 +93889 76682 +70259 90173 +16985 26105 +93371 50227 +93434 49229 +97412 55737 +69071 39598 +70682 90271 +31536 30421 +81650 96112 +66094 70998 +94447 83052 +70230 87681 +69613 93387 +50227 85660 +32751 83903 +12441 41367 +64171 79090 +88431 75578 +33033 96567 +96305 79090 +17193 52441 +42766 27666 +30798 50396 +18160 14792 +86048 69517 +26894 10883 +72243 38390 +48910 96875 +80507 90612 +77344 83033 +11713 96112 +36810 50227 +91347 11220 +20755 76682 +50353 95421 +63754 63013 +22119 25388 +35010 38390 +39083 90678 +16379 13640 +47651 67154 +50798 71473 +64108 83884 +62368 85420 +87732 54461 +44496 74078 +50396 16217 +32142 94345 +12969 50227 +63851 24208 +59124 89844 +24929 21174 +55229 84439 +78807 15788 +58298 50396 +16926 96567 +83884 50396 +63542 49739 +76625 41626 +97382 32976 +40464 38390 +14575 10840 +63334 71473 +25579 40921 +71524 96567 +50616 93389 +81504 17864 +10618 32838 +65653 11681 +74217 76682 +17739 45245 +12975 56728 +92629 12987 +13610 68591 +24487 83033 +12475 81946 +31651 39134 +32359 81946 +41174 79359 +63548 65603 +55031 50396 +59183 58376 +74036 69252 +33977 71473 +39977 40407 +32033 40193 +90147 83033 +23940 30137 +67597 33156 +64295 99755 +72689 96112 +92379 83884 +59904 17864 +59250 54829 +31693 34134 +88853 97698 +46754 31254 +58208 11220 +98626 11220 +46741 70998 +36408 63013 +18581 87826 +63114 28343 +97394 81946 +93270 97698 +80744 59372 +97689 57651 +87482 58376 +11896 75807 +65025 96196 +15892 54686 +68939 24270 +16022 53606 +36023 85420 +95998 43637 +61265 38390 +79090 11220 +81946 99814 +63895 78782 +83527 90200 +51915 62980 +22548 20223 +58376 26608 +81705 24971 +99116 26106 +92178 77949 +98976 38390 +81016 28343 +52646 79090 +29911 88246 +23834 92181 +46484 89669 +68488 44503 +74484 29808 +89780 86262 +96112 75203 +51392 42994 +19800 23307 +49890 41317 +98098 94345 +57894 69730 +59120 93793 +86825 83884 +41981 84710 +69860 70998 +25576 35489 +42850 23083 +34439 85430 +91153 35450 +59806 16217 +87651 74318 +15466 76682 +94237 22001 +45392 47159 +35295 95111 +86122 88173 +28631 50396 +34798 26613 +61839 13468 +61723 96112 +14034 96112 +30006 16217 +14649 26145 +86294 80739 +32258 11681 +92857 50396 +86334 58376 +10895 84439 +63194 85936 +76887 96027 +68733 26105 +41207 63013 +28365 88512 +24732 38390 +67548 49710 +81155 48747 +41815 96112 +51642 69071 +62718 81572 +59606 98715 +74964 13588 +64466 17223 +96982 46340 +84527 94623 +69698 11220 +11144 23375 +57947 97698 +41007 80545 +11681 32334 +94807 43967 +54555 94345 +16363 93419 +65623 45980 +42388 45727 +48482 79090 +85324 81581 +59768 37611 +62042 11681 +90240 19425 +66983 24278 +98892 42679 +35839 35139 +17825 39236 +74183 28343 +94347 48434 +82766 84797 +12488 62200 +11529 58265 +82862 27666 +63390 87826 +87638 60767 +69964 71473 +94668 76682 +58958 52441 +75722 97743 +68139 11220 +58242 75810 +92586 40193 +29680 94345 +33347 73583 +74149 73747 +88092 94345 +82865 45901 +88894 38390 +40872 97309 +85420 93793 +80641 69071 +57680 79788 +50575 63583 +45838 28855 +77834 63196 +36094 58852 +93487 19648 +98316 79122 +89283 97494 +81283 78824 +78086 84439 +70708 27959 +64643 44369 +39933 56445 +68663 28343 +97698 10803 +79122 51608 +35053 96112 +88445 87826 +59362 81946 +58091 67264 +48218 93793 +64495 16994 +38395 71473 +61884 50396 +84809 84439 +90363 78607 +39707 76682 +66866 83033 +76807 80277 +98492 83033 +65436 84059 +69199 68798 +62230 83884 +51938 18013 +99036 22915 +20508 84439 +41393 50396 +47979 58852 +74140 70998 +42029 88646 +43056 14163 +96145 39532 +80632 64382 +56985 85420 +63903 41993 +11220 93712 +94345 15788 +43760 56901 +93453 58852 +35914 74746 +73054 44762 +45629 40193 +77231 55896 +77041 38390 +96658 74157 +46466 17606 +88020 77476 +51115 61806 +24234 81946 +17382 79090 +38939 78416 +55399 95124 +74933 97972 +17223 11832 +20126 25792 +84054 91443 +84057 96112 +88765 83033 +27933 54577 +48695 78824 +90200 51999 +74599 38503 +61441 90200 +66742 38390 +23353 26105 +37362 82425 +38602 44514 +41407 71473 +51001 62633 +98321 40630 +75078 11681 +68245 24288 +49051 14363 +36869 25312 +17659 47253 +74211 69071 +41285 22997 +89913 71473 +35951 34861 +67158 50396 +43938 15553 +72373 24972 +40926 97698 +63013 85420 +19477 71473 +79722 19841 +28842 83920 +14541 55730 +31500 75763 +51488 32218 +18889 96567 +57241 17864 +51819 47021 +21973 30568 +13743 10104 +87695 43875 +90862 27666 +16780 65150 +24792 58376 +28715 69071 +40287 78011 +59897 84439 +16124 83884 +34237 44208 +80709 83186 +12989 55204 +96071 63816 +78189 63337 +37586 98216 +19413 51370 +64986 70521 +93855 48927 +57998 25233 +42676 58360 +93905 29575 +18012 58243 +28846 54313 +97083 50396 +59982 20815 +95409 88260 +57482 70230 +69515 83884 +78295 69071 +72645 71473 +71966 28343 +98274 84439 +34068 28343 +96135 40193 +65836 15788 +23264 84439 +19621 51691 +75945 40091 +29573 47799 +14879 79090 +28207 38390 +11483 15774 +32877 80739 +36254 96567 +65116 27258 +14250 93650 +23902 96112 +89984 35958 +82242 33004 +12762 62900 +81194 99347 +72193 37712 +71644 74162 +46588 52441 +27739 70311 +35648 70998 +44410 87233 +46656 27666 +31914 71473 +90034 78824 +61968 83033 +36567 29131 +78387 67697 +33453 57266 +24915 40540 +70857 52975 +28343 81423 +92106 87378 +56025 82509 +32851 98692 +51436 97147 +70601 71473 +70452 33153 +39288 15788 +17976 11220 +15788 58376 +40113 53779 +25192 88120 +31980 98924 +80317 91384 +67936 10228 +14839 75691 +55689 75265 +28107 90207 +49283 17864 +27666 52539 +26105 26025 +71897 10363 +65171 58095 +87061 76361 +58586 84439 +90319 17223 +12401 11681 +60665 21206 +66454 77367 +58801 69471 +12007 11220 +59620 71043 +14269 33941 +84020 34182 +21849 61119 +19934 93793 +49226 64719 +59477 58376 +67180 38390 +69143 84212 +29611 69071 +74186 73216 +44892 47027 +88341 63662 +93425 27666 +58009 40217 +61426 88678 +14176 17223 +19374 19815 +15924 63644 +31338 90200 +20061 96567 +77739 17223 +39213 79090 +86112 44465 +59347 96112 +52900 88643 +49030 41964 +79160 96112 +60822 33345 +87682 46340 +92223 67780 +75763 68868 +58470 38390 +22344 11681 +60094 70230 +53703 65992 +60348 41120 +14792 81993 +53271 21427 +67055 17864 +64402 49401 +46340 71473 +67425 80739 +33676 91364 +20261 93934 +33464 45079 +47333 87047 +99552 33828 +46700 29241 +34066 38390 +63635 81946 +64943 90200 +93222 70855 +39852 27666 +54215 27846 +91837 81435 +13206 92486 +34097 89083 +67571 63013 +65552 28794 +93206 16217 +57258 46746 +12355 95783 +45193 39825 +78824 41374 +79640 28343 +33304 46968 +52405 53684 +80165 79090 +63764 98552 +50867 62235 +55169 67322 +17385 63412 +93847 84439 +86220 96567 +56922 26105 +93793 70998 +46061 15119 +60608 50227 +53721 82034 +37048 97113 +78634 17392 +16149 11220 +96567 17864 +67761 15242 +43531 45273 +28649 81808 +16807 11681 +35016 38390 +36328 15788 +47350 87826 +83703 76682 +96035 68596 +89445 40193 +39175 22115 +46972 69071 +86512 64757 +70145 30941 +92472 94345 +28607 84439 +97839 80739 +46293 22854 +39471 56487 +40895 81224 +79054 15540 +19112 99099 +87456 97698 +64947 93293 +46868 17223 +61194 51103 +94011 51317 +93446 67760 +51603 79090 +98462 32618 +87627 14792 +50434 28343 +80823 87826 +85968 11220 +70582 94611 +69082 69071 +82872 75587 +66992 93001 +16652 81390 +45397 67124 +48288 12534 +16683 60958 +28845 17300 +73108 85770 +10887 14000 +86564 58432 +73753 15788 +58200 60971 +14724 10521 +22429 86503 +15636 73714 +42007 50396 +83033 28343 +11018 17864 +84668 59520 +34407 50227 +21979 66729 +20788 97698 +88249 71473 +29698 76682 +18861 90200 +33097 18831 +84374 38460 +42337 49469 +96184 11220 +93246 50708 +59059 17223 +94799 11681 +94592 90061 +16217 87826 +15119 39287 +98585 71473 +96536 42853 +70453 24363 +98772 69071 +86608 28722 +96532 50396 +29434 83821 +45190 18432 +39085 52441 +14544 27666 +98167 83884 +40247 35796 +58852 95208 +63594 94345 +37166 70696 +37060 97185 +78269 17223 +31684 50764 +17864 52599 +24791 33385 +88009 94208 +44960 66939 +94307 25038 +97941 92450 +84015 83884 +18910 52086 +65496 17223 +40031 34551 +85606 91632 +61769 76682 +16593 90387 +18746 84938 +37661 78508 +74488 71473 +10696 57789 +73457 33795 +36702 93793 +50523 40193 +54560 97491 +31840 38390 +76940 40193 +16870 11681 +59273 30259 +87826 11069 +42351 47872 +46704 17864 +60979 83884 +13487 66385 +89414 94345 +95781 78824 +81388 50396 +76147 16961 +47912 27666 +38794 15498 +42095 60345 +50754 85082 +47680 11681 +74650 63013 +79979 27666 +93963 91067 +12526 51125 +15421 50227 +14489 17864 +19890 71473 +39148 69071 +35061 43580 +13873 78824 +65002 84439 +44196 70230 +91160 27666 +66243 17864 +68520 52987 +57313 11001 +97451 71232 +45491 88748 +72806 28343 +10935 96112 +26571 50227 +36588 11220 +97082 47405 +74083 76682 +13709 28343 +71565 60347 +67060 89690 +89812 68984 +64357 18200 +13576 86923 +17785 52441 +90523 87826 +48169 84439 +49404 96112 +38548 93793 +10365 50396 +85079 97698 +87583 95586 +63995 97698 +37765 62288 +96507 26105 +74440 19405 +96601 94432 +37066 38390 +42143 11552 +33431 27666 +77502 63356 +33810 52441 +14847 36105 +21823 66983 +57868 71473 +84231 27666 +87717 52441 +53162 97698 +35374 65715 +34570 26105 +20224 36282 +71791 40193 +18833 48330 +12194 83762 +92449 38390 +18772 71473 +59035 57762 +60408 76682 +62373 63013 +79934 40193 +82312 59106 +22944 72620 +15001 50192 +42041 93793 +27226 80739 +68012 30136 +22148 34448 +15624 94345 +79255 39850 +80907 18558 +92896 15318 +25411 94345 +33580 81946 +71575 70650 +47700 79090 +75865 16217 +48756 81946 +98547 75763 +23220 38390 +15241 79090 +18586 33917 +22280 40494 +35998 69327 +60853 95280 +38251 50396 +52525 87826 diff --git a/2024/tcl/lib.tcl b/2024/tcl/lib.tcl new file mode 100644 index 0000000..d816a25 --- /dev/null +++ b/2024/tcl/lib.tcl @@ -0,0 +1,9 @@ +proc setup {n} { + 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] +} |