<commit_before>#!/usr/bin/env bash

# user configurable
words_file=/usr/share/dict/words
quit_key=0

# set by the program
num_attempts=
answer=
question=
letters=()

array_contains() {
    # checks if the second argument (string) is in the first argument (array)
    local e

    for e in "${@:1:1}"; do
        [[ "$e" == "$2" ]] && return $(true)
    done

    return $(false)
}

game_over() {
    echo -e "Sorry, the answer is: $answer"
    echo -e "Thanks for playing. Goodbye.\n"
}

game_win() {
    # win condition: no more blanks to guess

    # search for underscores in $question
    if [[ "$question" =~ _ ]]; then
        return $(false)
    fi

    echo -e "That's correct! The answer is: $answer"

    local lettercount="${#letters[@]}"
    local units="letter"
    if [[ $lettercount > 1 ]]; then
        units+="s"
    fi

    echo -e "You won using $lettercount $units."
    echo -e "Great job, and thanks for playing!\n"
}

generate_question() {
    # retrieve a random word from word file
    answer=$(python -c "import random, sys; print random.choice(open(sys.argv[1]).readlines())" $words_file)

    # generate blanks for the question
    local i
    for (( i=0; i<${#answer}; i++ )); do
        if [[ "${answer:$i:1}" =~ [[:space:]] ]]; then
            question+="  "
        else
            question+="_ "
        fi
    done

    # the number of attempts is based on the length of the answer
    # somewhat arbitrary formula
    num_attempts=$(( ${#answer} / 2 + 3 ))
}

print_letters() {
    if [[ "${#letters[*]}" > 0 ]]; then
        echo "${letters[*]}"
    fi
}

print_question() {
    echo -e "\n\n\t$question\n\n"
}

print_prompt() {
    echo -en "Enter a letter ($quit_key to quit). "

    local attempts="attempt"
    if [[ "$num_attempts" > 1 ]]; then
        attempts+="s"
    fi

    echo -e "$num_attempts $attempts left."<commit_msg>Increased the number of attempts.<commit_after>#!/usr/bin/env bash

# user configurable
words_file=/usr/share/dict/words
quit_key=0

# set by the program
num_attempts=
answer=
question=
letters=()

array_contains() {
    # checks if the second argument (string) is in the first argument (array)
    local e

    for e in "${@:1:1}"; do
        [[ "$e" == "$2" ]] && return $(true)
    done

    return $(false)
}

game_over() {
    echo -e "Sorry, the answer is: $answer"
    echo -e "Thanks for playing. Goodbye.\n"
}

game_win() {
    # win condition: no more blanks to guess

    # search for underscores in $question
    if [[ "$question" =~ _ ]]; then
        return $(false)
    fi

    echo -e "That's correct! The answer is: $answer"

    local lettercount="${#letters[@]}"
    local units="letter"
    if [[ $lettercount > 1 ]]; then
        units+="s"
    fi

    echo -e "You won using $lettercount $units."
    echo -e "Great job, and thanks for playing!\n"
}

generate_question() {
    # retrieve a random word from word file
    answer=$(python -c "import random, sys; print random.choice(open(sys.argv[1]).readlines())" $words_file)

    # generate blanks for the question
    local i
    for (( i=0; i<${#answer}; i++ )); do
        if [[ "${answer:$i:1}" =~ [[:space:]] ]]; then
            question+="  "
        else
            question+="_ "
        fi
    done

    # the number of attempts is based on the length of the answer
    # somewhat arbitrary formula
    num_attempts=$(( ${#answer} / 2 + 5 ))
}

print_letters() {
    if [[ "${#letters[*]}" > 0 ]]; then
        echo "${letters[*]}"
    fi
}

print_question() {
    echo -e "\n\n\t$question\n\n"
}

print_prompt() {
    echo -en "Enter a letter ($quit_key to quit). "

    local attempts="attempt"
    if [[ "$num_attempts" > 1 ]]; then
        attempts+="s"
    fi

    echo -e "$num_attempts $attempts left."
{'fraction_non_alphanumeric': 0.1579925650557621, 'fraction_numerical': 0.006372809346787042, 'mean_word_length': 2.560491493383743, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3888231', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1237, 'n_words': 397}