Sina Media Lab commited on
Commit
3c35d02
·
1 Parent(s): 40d3dfc
modules/counting/addition_bases.py DELETED
@@ -1,49 +0,0 @@
1
- # modules/numbering_system/addition_bases.py
2
-
3
- title = "Addition in Various Bases"
4
- description = "This module covers addition operations in bases like binary, octal, and hexadecimal."
5
-
6
- def generate_question():
7
- import random
8
-
9
- # Choose a base and corresponding valid digits
10
- base = random.choice([2, 8, 16])
11
- digits = '01' if base == 2 else '01234567' if base == 8 else '0123456789ABCDEF'
12
-
13
- # Generate two valid numbers for the selected base
14
- num1 = ''.join(random.choice(digits) for _ in range(3))
15
- num2 = ''.join(random.choice(digits) for _ in range(3))
16
-
17
- def add_numbers(num1, num2, base):
18
- # Perform the addition in the correct base
19
- return hex(int(num1, base) + int(num2, base))[2:].upper() if base == 16 else \
20
- oct(int(num1, base) + int(num2, base))[2:] if base == 8 else \
21
- bin(int(num1, base) + int(num2, base))[2:] if base == 2 else \
22
- str(int(num1) + int(num2))
23
-
24
- correct_answer = add_numbers(num1, num2, base)
25
- options = [correct_answer]
26
-
27
- # Generate incorrect answers
28
- while len(options) < 4:
29
- invalid_answer = ''.join(random.choice(digits) for _ in range(4))
30
- if invalid_answer != correct_answer:
31
- options.append(invalid_answer)
32
-
33
- random.shuffle(options)
34
-
35
- question = f"Add the numbers {num1} and {num2} in base {base}."
36
- explanation = f"The sum of {num1} and {num2} in base {base} is {correct_answer}."
37
- step_by_step_solution = [
38
- f"Step 1: Convert the numbers {num1} and {num2} to base 10.",
39
- "Step 2: Add the numbers in base 10.",
40
- f"Step 3: Convert the sum back to base {base}."
41
- ]
42
-
43
- return {
44
- "question": question,
45
- "options": options,
46
- "correct_answer": correct_answer,
47
- "explanation": explanation,
48
- "step_by_step_solution": step_by_step_solution
49
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
modules/counting/additive_multiplicative.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import random
2
+ import nltk
3
+ from nltk.corpus import words
4
+ from nltk.corpus import wordnet
5
+
6
+ # Ensure the NLTK word corpus is downloaded
7
+ nltk.download('words')
8
+ nltk.download('wordnet')
9
+
10
+ title = "Counting and Combinatorial Questions"
11
+ description = "This module covers basic counting principles, including additive and multiplicative principles in combinatorial problems."
12
+
13
+ def get_random_word(length=None):
14
+ """Return a random word from the NLTK words corpus with an optional length."""
15
+ word_list = words.words()
16
+ if length:
17
+ word_list = [word for word in word_list if len(word) == length]
18
+ return random.choice(word_list).capitalize()
19
+
20
+ def get_synonym(word):
21
+ """Return a random synonym for a word using WordNet."""
22
+ synonyms = wordnet.synsets(word)
23
+ if synonyms:
24
+ return random.choice(synonyms).lemmas()[0].name().capitalize()
25
+ return word.capitalize()
26
+
27
+ def generate_question():
28
+ question_type = random.choice(["vowels", "ties", "outfits", "combinations"])
29
+
30
+ if question_type == "vowels":
31
+ # Randomly generate two-letter words using vowels
32
+ vowel_count = random.randint(3, 5)
33
+ vowels = [get_random_word(1) for _ in range(vowel_count)]
34
+ num_two_letter_words = len(vowels) * 26
35
+ word_type = get_random_word(4)
36
+ question = f"How many two-letter {word_type}s can be formed if the first letter must be one of these {vowel_count} vowels: {', '.join(vowels)}?"
37
+ correct_answer = num_two_letter_words
38
+ explanation = f"There are {vowel_count} choices for the first letter (vowels) and 26 choices for the second letter (any letter). Thus, the total number of two-letter words is {vowel_count} * 26 = {num_two_letter_words}."
39
+ step_by_step_solution = [
40
+ f"Step 1: Identify the number of choices for the first letter ({vowel_count} vowels).",
41
+ "Step 2: Identify the number of choices for the second letter (any letter).",
42
+ f"Step 3: Multiply the two values: {vowel_count} * 26 = {num_two_letter_words}.",
43
+ f"Step 4: The total number of two-letter words is {num_two_letter_words}."
44
+ ]
45
+
46
+ elif question_type == "ties":
47
+ # Randomly generate tie names
48
+ regular_ties = random.randint(5, 10)
49
+ bow_ties = random.randint(3, 7)
50
+ tie_name = get_random_word(3)
51
+ question = f"You own {regular_ties} {tie_name}s and {bow_ties} bow {tie_name}s. How many choices do you have for your neckwear?"
52
+ correct_answer = regular_ties + bow_ties
53
+ explanation = f"You have {regular_ties} choices for {tie_name}s and {bow_ties} choices for bow {tie_name}s. Since you can wear either type, you have {regular_ties} + {bow_ties} = {correct_answer} choices for neckwear."
54
+ step_by_step_solution = [
55
+ f"Step 1: Identify the number of {tie_name}s ({regular_ties}).",
56
+ f"Step 2: Identify the number of bow {tie_name}s ({bow_ties}).",
57
+ f"Step 3: Add the two values: {regular_ties} + {bow_ties} = {correct_answer}.",
58
+ f"Step 4: The total number of neckwear choices is {correct_answer}."
59
+ ]
60
+
61
+ elif question_type == "outfits":
62
+ # Randomly generate clothing items
63
+ shirt_count = random.randint(4, 8)
64
+ skirt_count = random.randint(3, 6)
65
+ pants_count = random.randint(1, 4)
66
+ dress_count = random.randint(2, 5)
67
+ clothing_item = get_random_word(5)
68
+ question = (f"You have {shirt_count} {clothing_item}s, {skirt_count} skirts, {pants_count} pants, and {dress_count} dresses. "
69
+ "You want to select either a shirt to wear with a skirt or pants, or just a dress. How many outfits do you have to choose from?")
70
+ outfit_with_shirt = shirt_count * (skirt_count + pants_count)
71
+ correct_answer = outfit_with_shirt + dress_count
72
+ explanation = (f"You can choose a {clothing_item} ({shirt_count} options) with either a skirt ({skirt_count} options) or pants ({pants_count} options), "
73
+ f"giving {shirt_count} * ({skirt_count} + {pants_count}) = {outfit_with_shirt} outfits. "
74
+ f"Or you can choose a dress ({dress_count} options), so the total number of outfits is {outfit_with_shirt} + {dress_count} = {correct_answer}.")
75
+ step_by_step_solution = [
76
+ "Step 1: Calculate the number of outfits with a shirt and either a skirt or pants.",
77
+ f"Step 2: Multiply the number of {clothing_item}s ({shirt_count}) by the sum of skirts ({skirt_count}) and pants ({pants_count}): {shirt_count} * ({skirt_count} + {pants_count}) = {outfit_with_shirt}.",
78
+ f"Step 3: Add the number of dresses ({dress_count}): {outfit_with_shirt} + {dress_count} = {correct_answer}.",
79
+ f"Step 4: The total number of outfits is {correct_answer}."
80
+ ]
81
+
82
+ elif question_type == "combinations":
83
+ # Randomly generate meal options
84
+ appetizers = random.randint(2, 5)
85
+ main_courses = random.randint(4, 7)
86
+ desserts = random.randint(3, 5)
87
+ drinks = random.randint(2, 4)
88
+ meal_item = get_random_word(4)
89
+ question = (f"A restaurant offers {appetizers} {meal_item}s, {main_courses} main courses, {desserts} desserts, and {drinks} types of drinks. "
90
+ "How many different meal combinations can you order if you choose one of each?")
91
+ correct_answer = appetizers * main_courses * desserts * drinks
92
+ explanation = (f"You have {appetizers} choices for an {meal_item}, {main_courses} choices for a main course, {desserts} choices for a dessert, "
93
+ f"and {drinks} choices for a drink. Multiplying these together gives the total number of meal combinations: "
94
+ f"{appetizers} * {main_courses} * {desserts} * {drinks} = {correct_answer}.")
95
+ step_by_step_solution = [
96
+ f"Step 1: Identify the number of choices for each part of the meal: {meal_item}s, main courses, desserts, and drinks.",
97
+ f"Step 2: Multiply the number of choices: {appetizers} * {main_courses} * {desserts} * {drinks} = {correct_answer}.",
98
+ f"Step 3: The total number of meal combinations is {correct_answer}."
99
+ ]
100
+
101
+ options = [correct_answer]
102
+
103
+ # Generate incorrect answers ensuring they are unique and close to the correct answer
104
+ while len(options) < 4:
105
+ incorrect_answer = random.randint(correct_answer - random.randint(1, 10), correct_answer + random.randint(1, 10))
106
+ if incorrect_answer != correct_answer and incorrect_answer not in options:
107
+ options.append(incorrect_answer)
108
+
109
+ random.shuffle(options)
110
+
111
+ return {
112
+ "question": question,
113
+ "options": options,
114
+ "correct_answer": correct_answer,
115
+ "explanation": explanation,
116
+ "step_by_step_solution": step_by_step_solution
117
+ }
modules/number_system/{subtraction_bases.py → tmp/subtraction_bases.py} RENAMED
File without changes
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  streamlit
2
  huggingface_hub
3
  fpdf
4
- sympy
 
 
1
  streamlit
2
  huggingface_hub
3
  fpdf
4
+ sympy
5
+ nltk