summary refs log tree commit diff homepage
path: root/2020/day04-1.sh
diff options
context:
space:
mode:
Diffstat (limited to '')
-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
> 2022-02-19Factor out window management to window.cJune McEnroe 2022-02-19Enable -Wmissing-prototypesJune McEnroe 2022-02-19Fix edit.[ch] license notice additional permissionsJune McEnroe 2022-02-19Run line editing testsJune McEnroe 2022-02-18Implement new line editing "library"June McEnroe 2022-02-18Simplify cursor positioning in inputJune McEnroe 2022-02-18Fix M-f orderingJune McEnroe 2022-02-12Move sandman build to scripts/MakefileJune McEnroe 2022-02-12Use compat_readpassphrase.c on LinuxJune McEnroe 2022-02-12Copy RPP defines from oconfigureJune McEnroe