Exemple #1
0
def term(k):
	"""
		compute   (4k)!(1103+26390k)
				______________________

					(k!)^4 * 396 ^ 4k
	"""
	numerator = factorial(4*k) * (1103 + 26390 * k) * 1.0
	denominator = pow(factorial(k),4) * pow (396 , 4*k)

	y = numerator/denominator
	return y
Exemple #2
0
def estimate_pi():
	'''Estimates the value of pi using the 
	Srinivasa Ramanujan infinite series'''
	total = 0
	k = 0
	factor = 2 * math.sqrt(2)/9801
	while True:
		num = factorial(4*k) * (1103 + 26390*k)
		den = factorial(k)**4 * 396**(4*k)
		term = factor * num/den
		total += term
		if term <= 1e-15:
			break
		k += 1
	return 1/total
Exemple #3
0
def piCalc(intGrupo):
    getcontext().prec = int(12 *intGrupo)
    listAcumPi = Decimal(0.0)#2
    intI = 0
    for k in range(0, intGrupo, 1):#n
        intI += 1
        intP1 = Decimal(((-1) ** k))#5
        intP2, intFact = factorial(6 * k)#6 * n
        intI = intI + intFact
        intP3 = Decimal((13591409 + (545140134 * k)))#6
        intP4,  intFact= factorial(3 * k)#6
        factP5, intFact = factorial(k)#6
        intP5 = factP5 ** 3
        floatP6 = Decimal((640320) ** Decimal(((3 * k) + (3 / 2))))#9
        intNumerador = Decimal(intP1 * intP2 * intP3)#8
        floatDenominador = Decimal(intP4 * intP5 * floatP6)#8
        floatSum = Decimal(intNumerador / floatDenominador)#6
        float12Sum = 12 * floatSum#4
        listAcumPi += float12Sum#4
    pi = Decimal(1/listAcumPi)#5
    return pi, intI#1
Exemple #4
0
 def test_1(self):
     assert factorial(0) == 1
Exemple #5
0
def test_fact():
    assert factorial(5) == 120
Exemple #6
0
import sys
import factorial
sys.maxint
print sys.maxint
#print fac(100000)
print factorial(100)
    for x in range(1, 28123 + 1):
        if canitbe(x, nums=poop) is False:
            total += x
        print(x, total)
    return total

Hmm. Too slow but it works.


i got to 4179871 and it seemed stuck so I tried it...

#24

In [254]: from math import factorial

In [255]: factorial(10)
Out[255]: 3628800

method 1:
Iterate through from 0123456789 - 9876543210.
Count when any number doen not appear twice.

first make a function that lists them all.
Then alter it to skip...

def iter():
    count = 1
    rotate = 0
    x = 123456789
    old = x
    while x <= 9876543210:
# import factorial as utility
# import factorial
# from factorial import factorial
# from factorial import sum

from factorial import *

# print(sum([1,2,3,4]))

# from factorial import sum as my_sum

# print(sum([1,2,3,4]))

n = int(input("Enter your number:"))

# # print("Factorial of your number is:", utility.factorial(n))
# # print("Sum of your number is:", utility.sum(n))

print("Factorial of your number is:", factorial(n))
print("Sum of your number is:", sum(n))
Exemple #9
0
 def test_input_zero(self):
     self.assertEqual(factorial(0), 1)
"""n! means n × (n − 1) × ... × 3 × 2 × 1

For example, 10! = 10 × 9 × ... × 3 × 2 × 1 = 3628800,
and the sum of the digits in the number 10! is 3 + 6 + 2 + 8 + 8 + 0 + 0 = 27.

Find the sum of the digits in the number 100!"""
t=0;
from factorial import *
z=factorial(100)
a=str(z)
for i in a:
    t=int(i)+t
print(t)
Exemple #11
0
def test_factorial():
    i=10
    e=factorial_2(10)
    eq_(e,factorial(i))
Exemple #12
0
def test_factorial():
    i = 10
    e = 3628800
    eq_(e, factorial(i))
Exemple #13
0
 def test_input_ten(self):
     self.assertEqual(factorial(10), 3628800)
Exemple #14
0
 def test_input_hundred(self):
     self.assertEqual(
         factorial(100),
         93326215443944152681699238856266700490715968264381621468592963895217599993229915608941463976156518286253697920827223758251185210916864000000000000000000000000
     )
Exemple #15
0
 def test_input_seven(self):
     self.assertEqual(factorial(7), 5040)
Exemple #16
0
 def test_input_negative_fail(self):
     with self.assertRaises(ValueError):
         output = factorial(-10)
Exemple #17
0
 def test_input_one(self):
     self.assertEqual(factorial(1), 1)
Exemple #18
0
 def test_2(self):
     assert factorial(1) == 1
 def test_raise_error(self):
     with self.assertRaises(ValueError):
         factorial(-3)
Exemple #20
0
for(i=0;i<50;i+10){

}

for i in range(5):
    x = 1+10
    print(x)


####

n!
-------------------------
k!(n-k)!

math.factorial(n) / (math.factorial(k) * math.factorial(n-k))

form math import factorial
factorial(n) / (factorial(k)*factorial(n-k))


from math import factorial as bharat 
bharat(n)/(bharat(k)*bharat(n-k))

#######
var dog = {
    color:black,
    breed:lab
}
dog.color
#######
Exemple #21
0
def test_factorial():
    assert (factorial(5)) == 120
    assert (factorial(1)) == 1
Exemple #22
0
 def test_factorial(self):
     self.assertEqual(factorial(6), 720)
	def testNegative(self):
		result = factorial(-1)
		assert result == "The argument cannot be less than zero."
 def test_factorial(self):
     self.assertEqual(6, factorial(3))
	def testPositive(self):
		assert factorial(5) == 120, "Failed on 5."
Exemple #26
0
from factorial import *

fact = factorial

list(map(fact, range(6)))

[fact(n) for n in range(6)]

list(map(factorial, filter(lambda n: n % 2, range(6))))

[factorial(n) for n in range(6) if n % 2]
	def testZero(self):
		assert factorial(0) == 1, "Failed on 0."
except IndexError:
    print("please enter a valid index number")

#Q3
#An exception
#NameError: Hi there

#Q4
# -5.0
# a/b result in 0

#Q5
#1.
try:
    import factorial
    print(factorial(5))
except ModuleNotFoundError:
    print("please enter a valid module")

#2.
try:
    x=int(input("enter integer"))
    print("integer is",x)
except ValueError:
    print("enter a valid integer !!")

#3.
l=[1,2,3]
try:
    print(l[3])
except IndexError:
"""145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145.

Find the sum of all numbers which are equal to the sum of the factorial of their digits.

Note: as 1! = 1 and 2! = 2 are not sums they are not included."""

n=0;
x=0;
s=0;
def reset():
    global x
    x=0
from factorial import *
for n in range(3,50000):
    a=str(n)
    for i in a:
        x=factorial(int(i))+x
    print(x)
    if x==n:
        s=s+n
    reset()
print('sum',s)