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