Skip to content

Instantly share code, notes, and snippets.

View andrewphillipdoss's full-sized avatar

Andrew Doss andrewphillipdoss

  • Chicago, IL
View GitHub Profile
@andrewphillipdoss
andrewphillipdoss / gist:c05d80c218a4786525acdc290f194cbd
Created March 11, 2018 20:01
Write a script that Prints Fibonacci Series numbers till 10,000
fibonacci = [1,1]
i = 1
while (fibonacci[i] + fibonacci[i-1]) < 10000:
fibonacci.append(fibonacci[i] + fibonacci[i-1])
i += 1
print(fibonacci)
@andrewphillipdoss
andrewphillipdoss / fibonacci.py
Last active March 11, 2018 20:10
Write a script that Prints Fibonacci Series numbers till 10,000
fibonacci = [1,1] #start fibonacci with the first two elements
i = 1 #start iterator at second number in the series
while (fibonacci[i] + fibonacci[i-1]) < 10000: #while the number to be appeneded is less than 10 grand
fibonacci.append(fibonacci[i] + fibonacci[i-1]) #append the number
i += 1 #increment the iterator
print(fibonacci) #print the list
@andrewphillipdoss
andrewphillipdoss / largest_prime_under.py
Created March 11, 2018 21:47
Write an efficient script that prints largest Prime number that is smaller than 1,000,000
def largest_prime_under(n):
while n >= 2: #exit loop when all iterations have been exhausted
# If a number is not prime, it can be factored into two factors (let's call them x and y).
# If both x and y are greater than the square root of n, then x*y > n,
# so at least one of those factors must be less than or equal to the square root of n,
# and to check if n is prime, we only need to test for factors less than or equal to the square root:
if all(n % x for x in range(2, int(n ** 0.5 + 1))):
print (n) #print and break if the test passes
break