summary refs log tree commit diff homepage
path: root/2020
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-12-04 01:20:11 -0500
committerJune McEnroe <june@causal.agency>2020-12-04 01:20:11 -0500
commite581bf63c493385c01291e988d3961363ec8d6a3 (patch)
tree53411e74608966142fd15a60cc020f5998fed224 /2020
parentSolve day 3 part 2 (diff)
downloadaoc-e581bf63c493385c01291e988d3961363ec8d6a3.tar.gz
aoc-e581bf63c493385c01291e988d3961363ec8d6a3.zip
Solve day 4 part 1
The read builtin returning 1 for EOF when the last line doesn't end with
a newline tripped me up. Only a problem because I like to just
copy the input and use pbpaste, I guess.
Diffstat (limited to '2020')
-rw-r--r--2020/day04-1.sh30
1 files changed, 30 insertions, 0 deletions
diff --git a/2020/day04-1.sh b/2020/day04-1.sh
new file mode 100644
index 0000000..afac196
--- /dev/null
+++ b/2020/day04-1.sh
@@ -0,0 +1,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
a href='/src/commit/www/photo.causal.agency/2024-09-14/lens?id=16992208ec0549fdbc776da35c9f799126d15d89&follow=1'>Add photos from September 14June McEnroe 2024-09-24Add photos from September 12June McEnroe 2024-09-24Add photos from September 7June McEnroe 2024-09-24Allow not having descriptionsJune McEnroe 2024-09-23Automatically select the last used lens for a bodyJune McEnroe 2024-09-19Add photos from September 5June McEnroe 2024-09-15Add some more film stocks to the listJune McEnroe 2024-09-13Add photos from September 2June McEnroe 2024-09-13Add Fomapan 200 to films listJune McEnroe 2024-09-10Add August 29 picnic photosJune McEnroe 2024-09-08Apply some bold to trips renderingJune McEnroe 2024-09-08Render trips hopefully more efficientlyJune McEnroe 2024-09-08Allow removing bodies and lensesJune McEnroe 2024-09-08Limit body width so it looks less silly on desktopJune McEnroe 2024-09-07Handle no film being loadedJune McEnroe 2024-09-07Fancy up the text a littleJune McEnroe