• # en shell bref

    Posté par (site web personnel, Mastodon) . En réponse au message Avent du Code, jour 2. Évalué à 1.

    Juste pour la première partie

    #!/bin/sh
    # 1ドル: input file
    if test -z "1ドル"
    then
     echo "Please call me with an input file..." >&2
     exit 1
    fi
    _if="1ドル"
    if ! command -v grep >/dev/null
    then
     echo "Cannot locate 'grep' command in $PATH" >&2
     exit 2
    fi
    _ts=0 # total score
    _nr=0 # number of round
    # loose
    _nr=$( grep -cE '^ *B +X *$' "$_if" ) _ts=$(( _ts + 1*_nr ))
    _nr=$( grep -cE '^ *C +Y *$' "$_if" ) _ts=$(( _ts + 2*_nr ))
    _nr=$( grep -cE '^ *A +Z *$' "$_if" ) _ts=$(( _ts + 3*_nr ))
    # draw
    _nr=$( grep -cE '^ *A +X *$' "$_if" ) _ts=$(( _ts + 4*_nr ))
    _nr=$( grep -cE '^ *B +Y *$' "$_if" ) _ts=$(( _ts + 5*_nr ))
    _nr=$( grep -cE '^ *C +Z *$' "$_if" ) _ts=$(( _ts + 6*_nr ))
    # win
    _nr=$( grep -cE '^ *C +X *$' "$_if" ) _ts=$(( _ts + 7*_nr ))
    _nr=$( grep -cE '^ *A +Y *$' "$_if" ) _ts=$(( _ts + 8*_nr ))
    _nr=$( grep -cE '^ *B +Z *$' "$_if" ) _ts=$(( _ts + 9*_nr ))
    # end
    echo "$_ts"

    C'est une bête énumération exhaustive des cas, un peu comme la solution en AWK, mais en étant un peu plus lâche sur le formatage du fichier.

    "It is seldom that liberty of any kind is lost all at once." ― David Hume