mirror of
https://github.com/kuhyx/scripts.git
synced 2026-07-06 19:23:08 +02:00
feat: make math problem harder
This commit is contained in:
parent
f3c8aac365
commit
95471e8fca
@ -92,21 +92,45 @@ function check_for_steam() {
|
|||||||
function prompt_for_math_solution() {
|
function prompt_for_math_solution() {
|
||||||
echo -e "${YELLOW}WARNING: You are trying to install a restricted package.${NC}"
|
echo -e "${YELLOW}WARNING: You are trying to install a restricted package.${NC}"
|
||||||
|
|
||||||
# Generate a random math problem with a random number of operations
|
|
||||||
# Define possible operations
|
# Define possible operations
|
||||||
operations=('+' '-' '*' '/')
|
operations=('+' '-' '*' '/')
|
||||||
|
mult_div_operations=('*' '/')
|
||||||
|
add_sub_operations=('+' '-')
|
||||||
|
|
||||||
# Decide on the number of operations (2-4)
|
# Set minimum requirements
|
||||||
num_operations=$((RANDOM % 4 + 3))
|
min_total_operations=6
|
||||||
|
min_mult_div=3
|
||||||
|
|
||||||
# Start with a random number
|
# Start with a random number
|
||||||
|
number_of_operations=$((RANDOM % 4 + min_total_operations))
|
||||||
current_value=$((RANDOM % 50 + 10))
|
current_value=$((RANDOM % 50 + 10))
|
||||||
problem="$current_value"
|
problem="$current_value"
|
||||||
|
|
||||||
# Build the problem step by step
|
# Track how many multiplication/division operations we've used
|
||||||
for ((i=1; i<=num_operations; i++)); do
|
mult_div_count=0
|
||||||
# Choose a random operation
|
|
||||||
op=${operations[$((RANDOM % ${#operations[@]}))]}
|
# Build the problem with minimum required operations
|
||||||
|
for ((i=1; i<=number_of_operations; i++)); do
|
||||||
|
# If we haven't met the multiplication/division minimum and we're running out of operations
|
||||||
|
if [[ $mult_div_count -lt $min_mult_div && $(($number_of_operations - $i + 1)) -le $(($min_mult_div - $mult_div_count)) ]]; then
|
||||||
|
# Force a multiplication or division
|
||||||
|
op=${mult_div_operations[$((RANDOM % 2))]}
|
||||||
|
mult_div_count=$((mult_div_count + 1))
|
||||||
|
# If we've met minimum mult/div requirement, use any operation
|
||||||
|
elif [[ $mult_div_count -ge $min_mult_div ]]; then
|
||||||
|
op=${operations[$((RANDOM % 4))]}
|
||||||
|
# Count if we randomly selected another mult/div operation
|
||||||
|
[[ $op == "*" || $op == "/" ]] && ((mult_div_count++))
|
||||||
|
# Otherwise randomly choose a mult/div or add/sub with preference for mult/div
|
||||||
|
else
|
||||||
|
# 70% chance for mult/div until minimum is met
|
||||||
|
if [[ $((RANDOM % 10)) -lt 7 ]]; then
|
||||||
|
op=${mult_div_operations[$((RANDOM % 2))]}
|
||||||
|
mult_div_count=$((mult_div_count + 1))
|
||||||
|
else
|
||||||
|
op=${add_sub_operations[$((RANDOM % 2))]}
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Generate the next operand based on the operation
|
# Generate the next operand based on the operation
|
||||||
case $op in
|
case $op in
|
||||||
@ -117,14 +141,16 @@ function prompt_for_math_solution() {
|
|||||||
next_num=$((RANDOM % 50 + 5))
|
next_num=$((RANDOM % 50 + 5))
|
||||||
;;
|
;;
|
||||||
'*')
|
'*')
|
||||||
next_num=$((RANDOM % 10 + 2)) # Smaller numbers for multiplication
|
next_num=$((RANDOM % 9 + 2)) # Smaller numbers for multiplication
|
||||||
;;
|
;;
|
||||||
'/')
|
'/')
|
||||||
# For division, ensure it's clean (no remainder)
|
# For division, ensure it's clean (no remainder)
|
||||||
next_num=$((RANDOM % 5 + 2))
|
next_num=$((RANDOM % 5 + 2))
|
||||||
current_value=$((next_num * (RANDOM % 10 + 1)))
|
temp_value=$((next_num * (RANDOM % 10 + 1)))
|
||||||
|
current_value=$temp_value
|
||||||
problem="$current_value"
|
problem="$current_value"
|
||||||
i=1 # Reset counter to ensure we still get the right number of operations
|
i=1 # Reset counter to ensure we still get the right number of operations
|
||||||
|
mult_div_count=0 # Reset the counter since we're starting over
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user