X-Git-Url: https://git.sommitrealweird.co.uk/advent-of-code-2020.git/blobdiff_plain/a2ce7bb47964e226d4b10b791a038ca1f1fa67d7:/day4/count_valid_passports_2.sh..fe0197cb1dc8f701b69ce52b9acb445351557c8d:/day04/static/gitweb.js diff --git a/day4/count_valid_passports_2.sh b/day4/count_valid_passports_2.sh deleted file mode 100644 index 88fc560..0000000 --- a/day4/count_valid_passports_2.sh +++ /dev/null @@ -1,163 +0,0 @@ -#!/bin/bash - -declare -a data -cur_data="" -seperator="" -valid_count=0 - -required_fields=(byr iyr eyr hgt hcl ecl pid) - -check_year() { - value=$1 - min=$2 - max=$3 - - if [ $value -ge $min ] && [ $value -le $max ]; then - exit 0 - fi - exit 1 -} - -check_height() { - value=$1 - units=${value:$((${#value}-2)):2} - value=${value:0:$((${#value}-2))} - case $units in - in) - if [ $value -ge 59 ] && [ $value -le 76 ]; then - exit 0 - fi - ;; - cm) - if [ $value -ge 150 ] && [ $value -le 193 ]; then - exit 0 - fi - ;; - *) - ;; - esac - exit 1 -} - -check_hair() { - value=$1 - - if [ ${value:0:1} != "#" ]; then - exit 1 - fi - - if [[ $value =~ /^[a-f0-9]{6}$/ ]]; then - exit 1 - fi - - exit 0 -} - -check_eyes() { - colour="$1" - case $colour in - amb|blu|brn|gry|grn|hzl|oth) - exit 0 - ;; - *) - exit 1 - ;; - esac - exit 1 -} - -check_data() { - local -n record=$1 - for x in ${!record[@]}; do - value=${record[$x]} - case $x in - byr) - if ! ( check_year $value 1920 2002 ); then - exit 1 - fi - ;; - iyr) - if ! ( check_year $value 2010 2020 ); then - exit 1 - fi - ;; - eyr) - if ! ( check_year $value 2020 2030 ); then - exit 1 - fi - ;; - hgt) - if ! ( check_height $value ); then - exit 1 - fi - ;; - hcl) - if ! ( check_hair $value ); then - exit 1 - fi - ;; - ecl) - if ! ( check_eyes $value ); then - exit 1 - fi - ;; - pid) - value=${record[$x]} - if [ ${#value} -ne 9 ]; then - exit 1 - fi - ;; - *) - ;; - esac - done - - exit 0 -} - -exec 3