From f3371fffba9b2857fce35a06942e758c08b4bfa7 Mon Sep 17 00:00:00 2001 From: June McEnroe Date: Fri, 4 Dec 2020 01:38:48 -0500 Subject: Solve day 4 part 2 --- 2020/day04-2.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 2020/day04-2.sh (limited to '2020') diff --git a/2020/day04-2.sh b/2020/day04-2.sh new file mode 100644 index 0000000..5b3c2d3 --- /dev/null +++ b/2020/day04-2.sh @@ -0,0 +1,42 @@ +#!/bin/sh +valid=0 +check() { + [ \ + "${#byr}" -eq 4 -a "${byr}" -ge 1920 -a "${byr}" -le 2002 -a \ + "${#iyr}" -eq 4 -a "${iyr}" -ge 2010 -a "${iyr}" -le 2020 -a \ + "${#eyr}" -eq 4 -a "${eyr}" -ge 2020 -a "${eyr}" -le 2030 \ + ] || return 0 + case "${hgt}" in + (*cm) [ "${hgt%cm}" -ge 150 -a "${hgt%cm}" -le 193 ] || return 0 ;; + (*in) [ "${hgt%in}" -ge 59 -a "${hgt%in}" -le 76 ] || return 0 ;; + (*) return 0 ;; + esac + echo "${hcl}" | egrep -q '^#[0-9a-f]{6}$' || return 0 + case "${ecl}" in + (amb|blu|brn|gry|grn|hzl|oth) ;; + (*) return 0 ;; + esac + [ "${#pid}" -eq 9 ] || return 0 + return 1 +} +validate() { + check + valid=$((valid + $?)) + 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 -- cgit 1.4.1 26a0a72fac72604f930d62b4fa7d&follow=1'>diff
path: root/www/causal.agency/index.7 (unfollow)
Commit message (Expand)Author
2021-09-11Also defer printing comment for lone close-parensJune McEnroe
2021-09-10Publish "git-comment"June McEnroe
2021-09-10Add git comment --pretty optionJune McEnroe
2021-09-08Defer printing comment if line is blank or closing braceJune McEnroe
2021-09-08Up default min-repeat to 30 linesJune McEnroe
2021-09-08Handle dirty lines in git-commentJune McEnroe
2021-09-08Document and install git-commentJune McEnroe
2021-09-08Add repeat and all options to git-commentJune McEnroe
2021-09-08Add group threshold to git-commentJune McEnroe