From eda7f5876355744a15a2a84a2dba7c6dcfc9a302 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 3 Dec 2023 00:59:01 -0500 Subject: [PATCH] Fuck shell and fuck regex and fuck twone --- day_1/hint1.txt | 4 ++++ day_1/hint2.txt | 7 ++++++ day_1/input.txt | 1 - day_1/part1.fish | 13 +++++++++++ day_1/part2.fish | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 day_1/hint1.txt create mode 100644 day_1/hint2.txt create mode 100755 day_1/part1.fish create mode 100755 day_1/part2.fish diff --git a/day_1/hint1.txt b/day_1/hint1.txt new file mode 100644 index 0000000..7bbc69a --- /dev/null +++ b/day_1/hint1.txt @@ -0,0 +1,4 @@ +1abc2 +pqr3stu8vwx +a1b2c3d4e5f +treb7uchet diff --git a/day_1/hint2.txt b/day_1/hint2.txt new file mode 100644 index 0000000..41aa89c --- /dev/null +++ b/day_1/hint2.txt @@ -0,0 +1,7 @@ +two1nine +eightwothree +abcone2threexyz +xtwone3four +4nineeightseven2 +zoneight234 +7pqrstsixteen diff --git a/day_1/input.txt b/day_1/input.txt index 5c22757..f888ae8 100644 --- a/day_1/input.txt +++ b/day_1/input.txt @@ -998,4 +998,3 @@ eight6kxqqdnqp three6blrfsgdqsxgkbqj3 eight1eighteight8 8four419eighteight1bpv - diff --git a/day_1/part1.fish b/day_1/part1.fish new file mode 100755 index 0000000..9adb2c6 --- /dev/null +++ b/day_1/part1.fish @@ -0,0 +1,13 @@ +set sum 0 +for line in $(cat input.txt) + set first $(string match -gr "(\d)" $line) + set last $(string match -gr "(\d)(?!.*\d)" $line) + echo $line + + set n $first$last + set sum $(math $sum + $n) + + echo "-" +end + +echo $sum diff --git a/day_1/part2.fish b/day_1/part2.fish new file mode 100755 index 0000000..a788dd2 --- /dev/null +++ b/day_1/part2.fish @@ -0,0 +1,60 @@ +function strtoint + set str $argv[1] + if [ $(string length $str) = 1 ] + echo $str + end + if [ $str = "one" ] + echo 1 + end + if [ $str = "two" ] + echo 2 + end + if [ $str = "three" ] + echo 3 + end + if [ $str = "four" ] + echo 4 + end + if [ $str = "five" ] + echo 5 + end + if [ $str = "six" ] + echo 6 + end + if [ $str = "seven" ] + echo 7 + end + if [ $str = "eight" ] + echo 8 + end + if [ $str = "nine" ] + echo 9 + end +end + +set sum 0 +for line in $(cat input.txt) + set nums "(?:one|two|three|four|five|six|seven|eight|nine|\d)" + # Fuck you + set nums_fuck "(?:ne|wo|hree|our|ive|ix|even|ight|ine|\d)" + set first $(string match -gr "($nums)" $line) + set last $(string match -gr "($nums)(?!.*$nums_fuck)" $line) + echo $line + echo $first + echo $last + + set first_n $(strtoint $first) + set last_n $(strtoint $last) + echo "-" + echo $first_n + echo $last_n + + set n $first_n$last_n + echo "-" + echo $n + set sum $(math $sum + $n) + + echo "---" +end + +echo $sum