#!/usr/bin/env bash

# Initialize variables for the first and second bands
first_band=""
second_band=""

# Iterate over the color arguments
for ((i=1; i<=2; i++)); do
    color="${!i}"  # Get the value of the i-th argument
    value=""       # Initialize the value for the color

    # Match the color to its numeric value using a case statement
    case $color in
        black) value="0" ;;
        brown) value="1" ;;
        red) value="2" ;;
        orange) value="3" ;;
        yellow) value="4" ;;
        green) value="5" ;;
        blue) value="6" ;;
        violet) value="7" ;;
        grey) value="8" ;;
        white) value="9" ;;
    esac

    # Check if the color value is empty (unrecognized color)
    if [ -z "$value" ]; then
        echo "invalid color"
        exit 1
    fi

    # Assign the value to the corresponding band
    if [ -z "$first_band" ]; then
        first_band="$value"
    elif [ -z "$second_band" ]; then
        second_band="$value"
        break  # Break the loop after finding the first two bands
    fi
done

# Print the resulting number
if [ "$first_band" = "0" ]; then
    echo "$second_band"
else
    echo "$first_band$second_band"
fi
