aoc22

2022 Advent of Code
git clone https://git.parazyd.org/aoc22
Log | Files | Refs

02.sh (954B)


      1 #!/bin/sh
      2 
      3 pc_score=0
      4 me_score=0
      5 
      6 while read -r line; do
      7 	pc="${line% *}"
      8 	me="${line#* }"
      9 
     10 	# A => rock, 1
     11 	# B => paper, 2
     12 	# C => scissors, 3
     13 	# X => lose
     14 	# Y => draw
     15 	# Z => win
     16 	case "${pc}${me}" in
     17 	AX)
     18 		pc_score=$(( pc_score + 1 + 6 ))
     19 		me_score=$(( me_score + 3 + 0 ))
     20 		;;
     21 	BX)
     22 		pc_score=$(( pc_score + 2 + 6 ))
     23 		me_score=$(( me_score + 1 + 0 ))
     24 		;;
     25 	CX)
     26 		pc_score=$(( pc_score + 3 + 6 ))
     27 		me_score=$(( me_score + 2 + 0 ))
     28 		;;
     29 	AY)
     30 		pc_score=$(( pc_score + 1 + 3 ))
     31 		me_score=$(( me_score + 1 + 3 ))
     32 		;;
     33 	BY)
     34 		pc_score=$(( pc_score + 2 + 3 ))
     35 		me_score=$(( me_score + 2 + 3 ))
     36 		;;
     37 	CY)
     38 		pc_score=$(( pc_score + 3 + 3 ))
     39 		me_score=$(( me_score + 3 + 3 ))
     40 		;;
     41 	AZ)
     42 		pc_score=$(( pc_score + 1 + 0 ))
     43 		me_score=$(( me_score + 2 + 6 ))
     44 		;;
     45 	BZ)
     46 		pc_score=$(( pc_score + 2 + 0 ))
     47 		me_score=$(( me_score + 3 + 6 ))
     48 		;;
     49 	CZ)
     50 		pc_score=$(( pc_score + 3 + 0 ))
     51 		me_score=$(( me_score + 1 + 6 ))
     52 		;;
     53 	esac
     54 done
     55 
     56 echo "$me_score"