Skip to content

Instantly share code, notes, and snippets.

View BedirYilmaz's full-sized avatar
🌍

Bedir Yılmaz BedirYilmaz

🌍
View GitHub Profile
@BedirYilmaz
BedirYilmaz / Soru1.py
Last active October 11, 2016 08:02
Sum of all numbers that are smaller than 999 and can be divided by 5 or 3
sum = 0
for x in range(999, 1, -1):
if x % 5 == 0 or x % 3 == 0:
print(x)
sum += x
print(sum)
@BedirYilmaz
BedirYilmaz / Soru2.py
Last active October 19, 2016 07:38
Sum of the even fibonacci numbers that are smaller than 4000000
def fib (n) :
if (n == 1 or n==2):
return 1
return (fib(n-1) + fib(n-2))
limit = 4000000
x = 1
sum = 0
a = 0
while a < limit:
@BedirYilmaz
BedirYilmaz / Soru3.py
Created October 11, 2016 10:45
Listing the prime factors of given number
def primer(n):
notprime = False
for x in range(2 , n):
for y in range (2, x):
if x%y == 0:
notprime = True
break
if notprime == False and n % x == 0:
print(str(x) + " is prime and is a factor")
notprime = False
@BedirYilmaz
BedirYilmaz / Soru4.py
Created October 12, 2016 07:44
Finding the largest palindrome made from the product of two 3-digit numbers.
def palindrome(str):
return str == str[::-1]
for i in range(100, 999):
for j in range(100,999):
if(palindrome(str(i*j))):
print(i*j)
@BedirYilmaz
BedirYilmaz / Soru5.py
Last active October 18, 2016 09:51
Find the smallest positive number that is evenly divisible by all of the numbers from 1 to 20
def divisible (n):
if(n % 7 != 0):
return False
if(n % 9 != 0):
return False
if(n % 11 != 0):
return False
if(n % 13 != 0):
return False
if(n % 16 != 0):
@BedirYilmaz
BedirYilmaz / Soru6.py
Created October 18, 2016 10:33
Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
def sumofsquares (n):
sum = 0
for x in range(1,n+1):
sum += x*x
return sum
def squareofsum(n):
sum = 0
for x in range(1,n+1):
sum += x
@BedirYilmaz
BedirYilmaz / Soru7.py
Created October 18, 2016 10:58
Find out what the 10 001st prime number is.
def primer(n):
notprime = False
primecount = 0
x = 2
while True:
for y in range (2, x):
if x%y == 0:
notprime = True
break
if notprime == False:
@BedirYilmaz
BedirYilmaz / Soru8.py
Created October 18, 2016 11:34
Find the thirteen adjacent digits in the 1000-digit number that have the greatest product. What is the value of this product?
def mthndigits(number,m,n):
a = str(number)
return int(a[m:m+n])
def digitmultiply(number):
stringfied = str(number)
product = 1
for x in stringfied:
product *= int(x)
return product
print(5*7*9*11*13*16*17*19)
@BedirYilmaz
BedirYilmaz / Soru7v2.py
Last active October 22, 2016 01:39
Find 10001 nth prime number
# Special thanks to Ceyhan Yılmaz and cosinus
def nthPrime(n):
number = 3
primemultiples = []
primes = []
primes.append(2)
prime = True
while (len(primes)<=n):
prime = True
if number in primemultiples: