Advertisement
zenware

Python Euler Library

Oct 24th, 2011
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import math
  2. '''Work in Progress: A library I created to solve euler problems and other complex math.'''
  3. def isPalindrome(n): # Tells whether or not a number is palindrome.
  4.   return n == n[::-1]
  5.  
  6. def fib(n): # Creates a list containing the Fibonacci series.
  7.     result = []
  8.     a, b = 0, 1
  9.     while a < n:
  10.         result.append(a)
  11.         a, b = b, a+b
  12.     return result
  13.  
  14. def pfact(n): # Prime Factorization of n.
  15.   result = []
  16.   while n >= 2:
  17.     until = int(math.sqrt(n))+1
  18.     for i in range(2,until):
  19.       if not n%i:
  20.         result.append(i)
  21.         break
  22.     else:
  23.       result.append(n)
  24.       return result
  25.     n //= i
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement