Fuck shell and fuck regex and fuck twone
This commit is contained in:
parent
8b2e59467b
commit
eda7f58763
5 changed files with 84 additions and 1 deletions
4
day_1/hint1.txt
Normal file
4
day_1/hint1.txt
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
1abc2
|
||||||
|
pqr3stu8vwx
|
||||||
|
a1b2c3d4e5f
|
||||||
|
treb7uchet
|
7
day_1/hint2.txt
Normal file
7
day_1/hint2.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
two1nine
|
||||||
|
eightwothree
|
||||||
|
abcone2threexyz
|
||||||
|
xtwone3four
|
||||||
|
4nineeightseven2
|
||||||
|
zoneight234
|
||||||
|
7pqrstsixteen
|
|
@ -998,4 +998,3 @@ eight6kxqqdnqp
|
||||||
three6blrfsgdqsxgkbqj3
|
three6blrfsgdqsxgkbqj3
|
||||||
eight1eighteight8
|
eight1eighteight8
|
||||||
8four419eighteight1bpv
|
8four419eighteight1bpv
|
||||||
|
|
||||||
|
|
13
day_1/part1.fish
Executable file
13
day_1/part1.fish
Executable file
|
@ -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
|
60
day_1/part2.fish
Executable file
60
day_1/part2.fish
Executable file
|
@ -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
|
Loading…
Reference in a new issue