aoc22

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

01.sh (925B)


      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, X => rock, 1
     11 	# B, Y => paper, 2
     12 	# C, Z => scissors, 3
     13 	case "${pc}${me}" in
     14 	AX)
     15 		pc_score=$(( pc_score + 1 + 3 ))
     16 		me_score=$(( me_score + 1 + 3 ))
     17 		;;
     18 	AY)
     19 		pc_score=$(( pc_score + 1 + 0 ))
     20 		me_score=$(( me_score + 2 + 6 ))
     21 		;;
     22 	AZ)
     23 		pc_score=$(( pc_score + 1 + 6 ))
     24 		me_score=$(( me_score + 3 + 0 ))
     25 		;;
     26 	BX)
     27 		pc_score=$(( pc_score + 2 + 6 ))
     28 		me_score=$(( me_score + 1 + 0 ))
     29 		;;
     30 	BY)
     31 		pc_score=$(( pc_score + 2 + 3 ))
     32 		me_score=$(( me_score + 2 + 3 ))
     33 		;;
     34 	BZ)
     35 		pc_score=$(( pc_score + 2 + 0 ))
     36 		me_score=$(( me_score + 3 + 6 ))
     37 		;;
     38 	CX)
     39 		pc_score=$(( pc_score + 3 + 0 ))
     40 		me_score=$(( me_score + 1 + 6 ))
     41 		;;
     42 	CY)
     43 		pc_score=$(( pc_score + 3 + 6 ))
     44 		me_score=$(( me_score + 2 + 0 ))
     45 		;;
     46 	CZ)
     47 		pc_score=$(( pc_score + 3 + 3 ))
     48 		me_score=$(( me_score + 3 + 3 ))
     49 		;;
     50 	esac
     51 done
     52 
     53 echo "$me_score"