summary refs log tree commit diff homepage
path: root/2020/day04-1.sh
blob: afac1964fe8ff8e16edd285723d7f31d89fb1880 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/sh
valid=0
validate() {
	[ \
		-n "${byr}" -a \
		-n "${iyr}" -a \
		-n "${eyr}" -a \
		-n "${hgt}" -a \
		-n "${hcl}" -a \
		-n "${ecl}" -a \
		-n "${pid}" \
	] && valid=$((valid + 1))
	unset byr iyr eyr hgt hcl ecl pid cid
}
while :; do
	read -r line
	last=$?
	if [ -n "${line}" ]; then
		for pair in $line; do
			var=${pair%:*}
			val=${pair#*:}
			eval "${var}=${val}"
		done
	else
		validate
	fi
	[ $last -ne 0 ] && break
done
validate
echo $valid