Day 2: Add Zsh solution part 2
This commit is contained in:
parent
1f329a9d23
commit
4eed3518d6
1 changed files with 26 additions and 0 deletions
26
02/solution_2.zsh
Executable file
26
02/solution_2.zsh
Executable file
|
@ -0,0 +1,26 @@
|
|||
#!/usr/bin/zsh
|
||||
|
||||
integer aim=0
|
||||
integer h=0
|
||||
integer v=0
|
||||
|
||||
IFS="
|
||||
"
|
||||
for line in "${(@f)}"$(<input.txt)
|
||||
{
|
||||
cmd=(${(s/ /)line})
|
||||
case $cmd[1] in
|
||||
down)
|
||||
((aim += $cmd[2]))
|
||||
;;
|
||||
up)
|
||||
((aim -= $cmd[2]))
|
||||
;;
|
||||
forward)
|
||||
((h += $cmd[2]))
|
||||
((v += aim * $cmd[2]))
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
print Answer: $((h * v))
|
Loading…
Reference in a new issue