thomas_2023/day_1/part2.fish

61 lines
1.1 KiB
Fish
Raw Normal View History

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