-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath_complementary_equations.sh
More file actions
55 lines (45 loc) · 1.16 KB
/
math_complementary_equations.sh
File metadata and controls
55 lines (45 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
print_to_printer=false
while getopts "p" opt; do
case $opt in
p)
print_to_printer=true
;;
\?)
echo "Invalid option: -$OPTARG" >&2
;;
esac
done
output="\n\n"
output+="Find the complementary equations, and the missing number.\n\n"
num_questions=6
for i in $(seq 1 $num_questions); do
# Choose a total (target) from 50 to 150
total=$((50 + RANDOM % 101))
# Choose one known operand between 10 and (total - 10)
known=$((10 + RANDOM % (total - 19)))
# Randomly decide the form of equation (1, 2, or 3)
form=$((1 + RANDOM % 3))
case $form in
1)
# __ + known = total
output+="$(printf "%1s) %10s + %2d = %3d" "$i" "____" "$known" "$total")"
;;
2)
# known + __ = total
output+="$(printf "%1s) %10d + %2s = %3d" "$i" "$known" "____" "$total")"
;;
3)
# total - __ = known
output+="$(printf "%1s) %10d - %2s = %3d" "$i" "$total" "____" "$known")"
;;
esac
output+="\n\n\n\n\n"
done
# Output or print
if $print_to_printer ; then
(figlet "Complement Equations"; echo -e "$output") | paps | lpr
else
figlet "Complement Equations"
echo -e "$output"
fi