Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added function for find base given two numbers and one base #434

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mathgenerator/_gen_list.py
Original file line number Diff line number Diff line change
@@ -132,4 +132,5 @@
("tribonacci_series", "computer_science"),
("nth_tribonacci_number", "computer_science"),
("velocity_of_object", "misc"),
("base_b_given_two_nums", "misc"),
]
23 changes: 22 additions & 1 deletion mathgenerator/misc.py
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ def arithmetic_progression_term(max_d=100, max_a=100, max_n=100):

def _fromBaseTenTo(n, to_base):
"""Converts a decimal number n to another base, to_base.
Utility of base_conversion()
Utility of base_conversion() and base_b_given_two_nums()
"""
alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
assert type(
@@ -94,6 +94,27 @@ def base_conversion(max_num=60000, max_base=16):
ans = _fromBaseTenTo(n, bases[1])
return problem, f'${ans}$'

def base_b_given_two_nums(max_num=1000, max_base=16):
"""Base b Given Two Numbers

| Ex. Problem | Ex. Solution |
| --- | --- |
| Find the value of b if $10$ base $2$ is equal to $2$ base b | $10$ |
"""
#derive a random number
val = random.randint(2, max_num)
#derive 2 unequal random bases
base1 = random.randint(2, max_base)
base2 = random.randint(2, max_base) #base b
while base1 == base2: base2 = random.randint(2, max_base) #recalculate bases if they are equal

#find the numbers in the given bases
num1 = _fromBaseTenTo(val, base1)
num2 = _fromBaseTenTo(val, base2)

problem = f"Find the value of b if ${num1}$ base ${base1}$ is equal to ${num2}$ base b"
solution = f'${base2}$'
return problem, solution

def _newton_symbol(n, k):
"""Utility of binomial_distribution()"""