Day - 4 of internship at Aartronix

- Let's start the day by making a script that uses printf and read commands.   
    using pattern printing for practice from simple 1D patterns to 2D patterns:

1D patterns :
    vertical lines
    horizontal lines

*Don't take spaces lightly during Shell scripting.

Today I completed 1st day of AdventOfCode 

In first part, I just added and substracted the value because it was simpler compared to part 2.

exec 3<$"day1-input"
dial=50
password=0
while read -u 3 -r line
do
if [ "${line:0:1}" = "R" ]
then
echo case of turn right $line
dial=$((dial+((${line:1:${#line}}))))
#if [ $dial -gt 100 ] ; then ((password++)) ; echo password : $password ; fi
dial=$(($dial % 100))
echo value of dial is $dial
if [ $dial -eq 0 ] ; then ((password++)) ; echo password : $password ; fi
fi
if [ "${line:0:1}" = "L" ]
then
echo case of turn left $line
dial=$((100 + $((dial-((${line:1:${#line}}))))))
#if [ $dial -lt 100 ] ; then ((password++)) ; echo password : $password ; fi
dial=$(($dial % 100))
echo value of dial is $dial
if [ $dial -eq 0 ] ; then ((password++)) ; echo password : $password ; fi
fi
done
echo $password

In part 2, I rewrote the whole script as it needed to count every time dial came to zero.


exec 3<$"day1-input"
dial=50
password=0
while read -u 3 -r line ; do
echo movement is : $line
if [ "${line:0:1}" = "R" ] ; then
for (( i=0 ; i<${line:1:${#line}} ; i++ )) ; do
echo dial : $dial
dial=$(( (dial + 1) % 100 ))
echo dial : $dial
if [ $dial = 0 ] ; then ((password++)) ; echo password:$password ; fi
done
fi
if [ "${line:0:1}" = "L" ] ; then
for ((i=0; i<${line:1:${#line}}; i++)) ; do
echo dial : $dial
dial=$(( (dial - 1 + 100) % 100 ))
if [ $dial = 0 ] ; then ((password++)) ; echo password:$password ; fi
done
fi
done
echo $password

Started code for day-2 of Advent of code.

Tomorrow i should be able to complete day-2 and day-3.

Comments

Popular posts from this blog

Day - 1 of internship at Aartronix