Пример #1
0
def getNumR(n):
    """
    Returns the number of values of R that satisfies N choose R > 1 million.
    I just need to find the first value of r that works and return n - r - r + 1, because math.
    """
    for r in range(1, ceil(n / 2)):
        if f.factorial(n) / f.factorial(r) / f.factorial(n - r) > 1000000:
            return n - 2 * r + 1
Пример #2
0
def richardson_extrapolation(f, n, N):
    if not callable(f):
        g = f; f = lambda k: g.__getitem__(int(k))
    orig = mp.prec
    try:
        mp.prec = 2*orig
        s = mpf(0)
        for j in range(0, N+1):
            c = (n+j)**N * (-1)**(j+N) / (factorial(j) * factorial(N-j))
            s += c * f(mpf(n+j))
    finally:
        mp.prec = orig
    return +s
Пример #3
0
def diffc(f, x, n=1, radius=mpf(0.5)):
    """
    Compute an approximation of the nth derivative of f at the point x
    using the Cauchy integral formula. This only works for analytic
    functions. A circular path with the given radius is used.

    diffc increases the working precision slightly to avoid simple
    rounding errors. Note that, especially for large n, differentiation
    is extremely ill-conditioned, so this precaution does not
    guarantee a correct result. (Provided there are no singularities
    in the way, increasing the radius may help.)

    The returned value will be a complex number; a large imaginary part
    for a derivative that should be real may indicate a large numerical
    error.
    """
    prec = mp.prec
    try:
        mp.prec += 10
        def g(t):
            rei = radius*exp(j*t)
            z = x + rei
            return f(z) / rei**n
        d = quadts(g, [0, 2*pi])
        return d * factorial(n) / (2*pi)
    finally:
        mp.prec = prec
Пример #4
0
def check(n):
	fact_sum = 0
	for dig in str(n):
		fact_sum += factorial(int(dig))
	if fact_sum == n:
		return True
	return False
def compute():
    total = functions.factorial(100)
    total = str(total)
    
    total = sum(int(i) for i in total)
            
    return str(total)
Пример #6
0
def test_factorial():
    assert factorial(0) == 1
    assert factorial(5) == 120
    with pytest.raises(TypeError):
        factorial('string')
    with pytest.raises(TypeError):
        factorial(1.1)
    with pytest.raises(ValueError):
        factorial(-2)
Пример #7
0
def euler20(x):
    """sums the digits given by the factorial of x"""
    fact = factorial(x)

    summ = 0
    for a in str(fact):
        summ += int(a)
    return summ
Пример #8
0
def testFactorial(x):
    sys.path.append('../project/sugarlabs-calculate-sugar-0.94')
    from functions import factorial

    try:
        output = factorial(x)
    except:
        output = "Fail"
    return output
def testFactorial(x):

	#get Directory for functions
	currentworkingdirectory = os.getcwd()
	currentworkingdirectory = currentworkingdirectory.replace('/testCasesExecutables', '')
	currentworkingdirectory = (currentworkingdirectory + '/project/src')
	sys.path.insert(0, currentworkingdirectory)

	from functions import factorial

	try:
		output = factorial(int(x))
	except:
		output = "ERROR"
	
	return output
Пример #10
0
def compute():
    total = 0

    fac = [0] * 10

    for i in range(10):
        fac[i] = functions.factorial(i)

    for i in range(3, LIMIT):
        temp = 0

        temp = sum(fac[int(i)] for i in str(i))

        if temp == i:
            total += i

    return str(total)
Пример #11
0
def testFactorial(x):

    #get Directory for functions and extract factorial
    currentworkingdirectory = os.getcwd()
    currentworkingdirectory = currentworkingdirectory.replace(
        '/testCasesExecutables', '')
    currentworkingdirectory = (currentworkingdirectory + '/project/src')
    sys.path.insert(0, currentworkingdirectory)

    from functions import factorial

    #run factorial function
    try:
        output = factorial(int(x))
    except:
        output = "ERROR"

    return output
Пример #12
0
# s. trowbridge 2020
import functions as fn
import plotly.express as px
import plotly.graph_objects as go

n = 10
nums = [i for i in range(1, n + 1)]
sums = []
products = []

for i in range(1, n + 1):
    sums.append(fn.summation(i))

for i in range(1, n + 1):
    products.append(fn.factorial(i))

print(sums)
print(products)
print("")

# instantiate a plotly express line chart from list comprehensions
fig = go.Figure(data=[
    go.Scatter(x=nums,
               y=sums,
               mode='markers+lines',
               marker_color=sums,
               marker_size=5,
               name='final_exam_grade'),
    go.Scatter(x=nums,
               y=products,
               mode='markers+lines',
Пример #13
0
 def eps_pade(p):
     return mpf(2)**(3-2*p) * factorial(p)**2/(factorial(2*p)**2 * (2*p + 1))
Пример #14
0
def index():
    f5 = factorial(5)
    f6 = factorial(6)
    #lista = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    return render_template('index.html', f5=f5, f6=f6, factorial=factorial)
Пример #15
0
from functions import factorial, PI
import functions

r = functions.factorial(10)
print(r)
r = factorial(19)
print(r)

print(PI)
print(functions.PI)
Пример #16
0
if __name__ == '__main__':
    main()

nterms = 50
print("Fibonacci sequence:")
for i in range(nterms):
    print(i," : ",fibonacci(i))


print (factorial(8))'''

a = [1, 5, 7, 8, 11, 13, 16]
b = [8, 4, 1, 3, 2, 6]
c = [6, 5, 3, 1, 8, 7, 2, 4]

print(factorial(4))

#print (binary_search(a,11,0,len(a)-1))

#bubble_sort(b)

#insertion_sort(c)

#print(fib_to(20))
#print(fib_to(20)[20])

#print(toLowerCase("ABCD"))

#print(ord('a'))
Пример #17
0
def main():
    print(find_sum(factorial(100)))
Пример #18
0
from functions import factorial 

print(factorial(5))
Пример #19
0
import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
import functions
functions.scope(1)
functions.cube(2)
import functions
functions.factorial(5)
import functions as fn
fn.cube(2)
from fu
from functions import cube
cube(2)
from functions import *
factorialr(6)
importlib sys
import sys
sys.path
sum([1,2,3])
sum([1,2,3,4])
sum(1,2,3,4)
from functions import *
sum([1,2,3,4])
my_sum(1,2,3,4)
import sys; print('%s %s' % (sys.executable or sys.platform, sys.version))
3*5
print(3*5)
s = 'hello'
s
print(s)
print(s.__repr__())
if 1:
    print('yes')
Пример #20
0
 def eps_pade(p):
     return mpf(2)**(3-2*p) * factorial(p)**2/(factorial(2*p)**2 * (2*p + 1))
Пример #21
0
    def newClient(self, connection, client_address, port):
        print(timePrintout() + "  New Client: thread created")

        try:
            print(timePrintout() + "  Connection from", client_address, ":",
                  port)

            # Receive the data in small chunks and retransmit it
            while True:
                data = connection.recv(4096)

                if len(data) != 0:
                    message = Segment.unpack(data)
                    #message.print()
                    print(message.time() + '  Received: ' + message.printout())

                    token = message.id
                    numberA = int(message.numberA)
                    numberB = int(message.numberB)

                    if message.operation == OPERATION.id:
                        token = random.randint(100, 1000)
                        connection.sendall(
                            Segment(OPERATION.id, True, token, time.time(), "",
                                    "", "").pack())
                    elif message.operation == OPERATION.addition:
                        result = functions.addition(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.addition, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.addition, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.subtraction:
                        result = functions.subtraction(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.subtraction, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.subtraction, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.multiplication:
                        result = functions.multiplication(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.multiplication, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.multiplication, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.division:
                        result = functions.division(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.division, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.division, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.exponentiation:
                        result = functions.exponentiation(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.exponentiation, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.exponentiation, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.negation:
                        result = functions.negation(numberA)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.negation, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.negation, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.root:
                        result = functions.root(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.root, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.root, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.combination:
                        result = functions.combination(numberA, numberB)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.combination, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.combination, True, token,
                                        time.time(), 0, 0, result).pack())
                    elif message.operation == OPERATION.factorial:
                        result = functions.factorial(numberA)
                        if result > 2147483647 or result < -2147483648:
                            connection.sendall(
                                Segment(OPERATION.factorial, False, token,
                                        time.time(), 0, 0, 0).pack())
                        else:
                            connection.sendall(
                                Segment(OPERATION.factorial, True, token,
                                        time.time(), 0, 0, result).pack())
                    else:
                        print(timePrintout() +
                              "  Error occured: Wizard must be stopped!")

                    # break

        finally:
            # Clean up the connection
            connection.close()
Пример #22
0
from importlib import reload

__author__ = "Bartlomiej Ciurus"

import functions

print("First: " + str(functions.factorial(8)))
print("Second: " + str(functions.fibonacci(8)))

reload(functions)

print("Third: " + str(functions.factorial(8)))
print("Fourth: " + str(functions.fibonacci(8)))

del functions

import functions as func

print("Fifth: " + str(func.factorial(6)))
print("Sixth: " + str(func.fibonacci(5)))

reload(func)

print("Seventh: " + str(func.factorial(6)))
print("Eight: " + str(func.fibonacci(5)))

del func

from functions import *

print("Ninth: " + str(fibonacci(8)))
Пример #23
0
def num_of_combs(a, b):
    return factorial(a) / (factorial(b) * factorial(a - b))
Пример #24
0
def test_factorial():
    assert factorial(4) == 24