• [^] # Re: en shell bref

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

    Juste pour la seconde 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
    # +0=loose
    _nr=$( grep -cE '^ *A +X *$' "$_if" ) _ts=$(( _ts + 3*_nr )) # AC RS
    _nr=$( grep -cE '^ *B +X *$' "$_if" ) _ts=$(( _ts + 1*_nr )) # BA PR
    _nr=$( grep -cE '^ *C +X *$' "$_if" ) _ts=$(( _ts + 2*_nr )) # CB SP
    # +3=draw
    _nr=$( grep -cE '^ *A +Y *$' "$_if" ) _ts=$(( _ts + 4*_nr )) # AA
    _nr=$( grep -cE '^ *B +Y *$' "$_if" ) _ts=$(( _ts + 5*_nr )) # BB
    _nr=$( grep -cE '^ *C +Y *$' "$_if" ) _ts=$(( _ts + 6*_nr )) # CC
    # +6=win
    _nr=$( grep -cE '^ *A +Z *$' "$_if" ) _ts=$(( _ts + 8*_nr )) # AB RP
    _nr=$( grep -cE '^ *B +Z *$' "$_if" ) _ts=$(( _ts + 9*_nr )) # BC PS
    _nr=$( grep -cE '^ *C +Z *$' "$_if" ) _ts=$(( _ts + 7*_nr )) # CA SR
    # end
    echo "$_ts"

    Même principe, juste qu'on calcule autrement.

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