Day 1
This commit is contained in:
12
01/01.sh
Executable file
12
01/01.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/bash
|
||||
|
||||
prev=0
|
||||
found=0
|
||||
while read current; do
|
||||
if [ $prev -gt 0 ] && [ $current -gt $prev ]; then
|
||||
found=$((found+1))
|
||||
fi
|
||||
prev=$current
|
||||
done
|
||||
|
||||
echo $found
|
||||
22
01/02.sh
Executable file
22
01/02.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
array=()
|
||||
while read line; do
|
||||
array+=($line)
|
||||
done
|
||||
array_length=${#array[@]}
|
||||
|
||||
prev=0
|
||||
found=0
|
||||
for i in $(seq $array_length); do
|
||||
if [ $((i-2)) -gt $array_length ]; then
|
||||
break
|
||||
fi
|
||||
current=$((array[i-1]+array[i]+array[i+1]))
|
||||
if [ $prev -gt 0 ] && [ $current -gt $prev ]; then
|
||||
found=$((found+1))
|
||||
fi
|
||||
prev=$current
|
||||
done
|
||||
|
||||
echo $found
|
||||
Reference in New Issue
Block a user