feat: make math problem more complex

This commit is contained in:
Krzysztof kuhy Rudnicki 2025-04-05 23:04:01 +02:00
parent c8902471df
commit f3c8aac365

View File

@ -65,7 +65,7 @@ function display_operation() {
# Function to check if user is trying to install specific packages that require confirmation # Function to check if user is trying to install specific packages that require confirmation
function check_for_steam() { function check_for_steam() {
# List of packages that require confirmation # List of packages that require confirmation
local restricted_packages=("steam" "freetube-bin" "seamonkey-bin" "seamonkey") local restricted_packages=("steam" "freetube-bin" "seamonkey-bin" "seamonkey" "google-chrome" "mirosoft-edge-stable-bin" "opera" "slimjet" "vivaldi" "yandex-browser" "min-browser-bin" "vieb-bin")
# Check if the command is an installation command # Check if the command is an installation command
if [[ "$1" == "-S" || "$1" == "-Sy" || "$1" == "-Syu" || "$1" == "-Syyu" || "$1" == "-U" ]]; then if [[ "$1" == "-S" || "$1" == "-Sy" || "$1" == "-Syu" || "$1" == "-Syyu" || "$1" == "-U" ]]; then
@ -92,69 +92,56 @@ 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 # Generate a random math problem with a random number of operations
operation_type=$((RANDOM % 5 + 1)) # Define possible operations
operations=('+' '-' '*' '/')
case $operation_type in # Decide on the number of operations (2-4)
1) # Addition num_operations=$((RANDOM % 4 + 3))
num1=$((RANDOM % 90 + 10))
num2=$((RANDOM % 90 + 10)) # Start with a random number
problem="$num1 + $num2" current_value=$((RANDOM % 50 + 10))
solution=$((num1 + num2)) problem="$current_value"
;;
2) # Subtraction # Build the problem step by step
num1=$((RANDOM % 90 + 10)) for ((i=1; i<=num_operations; i++)); do
num2=$((RANDOM % 90 + 10)) # Choose a random operation
# Make sure num1 > num2 for positive result op=${operations[$((RANDOM % ${#operations[@]}))]}
if [[ $num1 -lt $num2 ]]; then
temp=$num1 # Generate the next operand based on the operation
num1=$num2 case $op in
num2=$temp '+')
fi next_num=$((RANDOM % 50 + 5))
problem="$num1 - $num2" ;;
solution=$((num1 - num2)) '-')
;; next_num=$((RANDOM % 50 + 5))
3) # Multiplication ;;
num1=$((RANDOM % 15 + 2)) '*')
num2=$((RANDOM % 15 + 2)) next_num=$((RANDOM % 10 + 2)) # Smaller numbers for multiplication
problem="$num1 * $num2" ;;
solution=$((num1 * num2)) '/')
;; # For division, ensure it's clean (no remainder)
4) # Division (with whole number result) next_num=$((RANDOM % 5 + 2))
num2=$((RANDOM % 10 + 2)) current_value=$((next_num * (RANDOM % 10 + 1)))
num1=$((num2 * (RANDOM % 10 + 1))) problem="$current_value"
problem="$num1 / $num2" i=1 # Reset counter to ensure we still get the right number of operations
solution=$((num1 / num2)) continue
;; ;;
5) # Mixed with parentheses esac
num1=$((RANDOM % 20 + 5))
num2=$((RANDOM % 10 + 2)) problem="$problem $op $next_num"
num3=$((RANDOM % 20 + 5))
# Update current value for next iteration
# Random sub-operation case $op in
sub_op=$((RANDOM % 3 + 1)) '+') current_value=$((current_value + next_num)) ;;
'-') current_value=$((current_value - next_num)) ;;
case $sub_op in '*') current_value=$((current_value * next_num)) ;;
1) '/') current_value=$((current_value / next_num)) ;;
problem="($num1 + $num2) * $num3" esac
solution=$(((num1 + num2) * num3)) done
;;
2) # Calculate solution using bash's evaluation
if [[ $num1 -lt $num2 ]]; then solution=$(eval "echo \$(($problem))")
temp=$num1
num1=$num2
num2=$temp
fi
problem="($num1 - $num2) * $num3"
solution=$(((num1 - num2) * num3))
;;
3)
problem="$num1 * ($num2 + $num3)"
solution=$((num1 * (num2 + num3)))
;;
esac
;;
esac
echo -e "${YELLOW}To confirm installation, please solve this math problem:${NC}" echo -e "${YELLOW}To confirm installation, please solve this math problem:${NC}"
echo -e "${CYAN}$problem = ?${NC}" echo -e "${CYAN}$problem = ?${NC}"