Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 14 commits
  • 19 files changed
  • 0 commit comments
  • 1 contributor
View
0 python/problem1.py → python/p1.py
File renamed without changes.
View
24 python/p19.py
@@ -0,0 +1,24 @@
+#!/usr/bin/python
+
+def isLeapYear(year):
+ return year%4==0 and (year%100!=0 or year%400==0)
+
+def daysInMonth(month,year):
+ if month in [3,5,8,10]:
+ return 30
+ elif month == 1:
+ return isLeapYear(year) and 29 or 28
+ else:
+ return 31
+
+numSundays=0
+day = 1 #the first day in 1901
+
+for year in range(1901,2001):
+ for month in range(0,12):
+ day%=7
+ if day == 6:
+ numSundays+=1
+ day+=daysInMonth(month,year)
+
+print numSundays
View
0 python/problem2.py → python/p2.py
File renamed without changes.
View
18 python/p26.py
@@ -0,0 +1,18 @@
+#!/usr/bin/python
+
+def isCoprimeTo10(num):
+ return num%2!=0 and num%5!=0
+
+maxD=0
+maxI=0
+for i in range(2,1000):
+ k = 1
+ if isCoprimeTo10(i):
+ while ((10**k) % i) != 1:
+ k+=1
+ if maxD < k:
+ maxD = max(maxD,k)
+ maxI = i
+ print i,k
+
+print maxI,maxD
View
0 python/problem27.py → python/p27.py
File renamed without changes.
View
0 python/problem28.py → python/p28.py
File renamed without changes.
View
0 python/problem29.py → python/p29.py
File renamed without changes.
View
0 python/problem3.py → python/p3.py
File renamed without changes.
View
0 python/problem30.py → python/p30.py
File renamed without changes.
View
0 python/problem31.py → python/p31.py
File renamed without changes.
View
45 python/p33.py
@@ -0,0 +1,45 @@
+#!/usr/bin/python
+
+#The fraction 49/98 is a curious fraction, as an inexperienced mathematician in attempting to simplify it may incorrectly believe that 49/98 = 4/8, which is correct, is obtained by cancelling the 9s.
+#
+#We shall consider fractions like, 30/50 = 3/5, to be trivial examples.
+#
+#There are exactly four non-trivial examples of this type of fraction, less than one in value, and containing two digits in the numerator and denominator.
+#
+#If the product of these four fractions is given in its lowest common terms, find the value of the denominator.
+
+
+def specialCancel(num,den):
+ num_s = str(num)
+ den_s = str(den)
+ for index,c in enumerate(num_s):
+ if c == den_s[0] and den_s[1] != '0':
+ if float(num_s[(index+1)%2])/float(den_s[1]) == float(num)/den:
+ return True
+ if c == den_s[1] and den_s[0] != '0':
+ if float(num_s[(index+1)%2])/float(den_s[0]) == float(num)/den:
+ return True
+ return False
+
+
+exp = (specialCancel(i,k) for i in range(10,100) for k in range(10,100) if i/k < 1.0)
+
+finalI = 1
+finalK = 1
+
+for i in range(10,100):
+ for k in range(10,100):
+ if i/k < 1.0 and i%10 != 0 and k % 10 != 0 and specialCancel(i,k):
+ finalI *= i
+ finalK *= k
+
+
+def gcd(a,b):
+ if b == 0:
+ return a
+ else:
+ return gcd(b, a % b)
+
+greatest = gcd(finalI,finalK)
+print greatest,finalI,finalK
+print finalI/greatest,finalK/greatest
View
0 python/problem4.py → python/p4.py
File renamed without changes.
View
0 python/problem5.py → python/p5.py
File renamed without changes.
View
0 python/problem6.py → python/p6.py
File renamed without changes.
View
19 python/p7.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+def isPrime(num):
+ i=2
+ while i*i <= num:
+ if num%i==0:
+ return False
+ i+=1
+ return True
+
+
+i=0
+cnt=2
+while i < 10001:
+ if isPrime(cnt):
+ i+=1
+ print i,cnt
+ cnt+=1
+
View
15 python/p8.py
@@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+# I think this is the one where you have to find the highest product of any 5 digits in a row in the list
+
+f = file('p8.txt')
+txt = f.read()
+f.close()
+
+txt = txt.strip()
+
+
+length=len(txt)
+
+print max([reduce(lambda x,y: int(x)*int(y), txt[i-5:i]) for i in range(5,length)])
+
View
1 python/p8.txt
@@ -0,0 +1 @@
+7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450
View
22 ruby/p11.rb
@@ -18,20 +18,30 @@
class NodeTraveler
attr_accessor :debug
+ attr_reader :xbound, :ybound
def initialize(map)
@map = map
@xbound = map[0].length
@ybound = map.length
@debug = false
+ @cardinalDirections = [[-1,-1],[-1,0],[-1,1],[0,1],[0,-1],[1,-1],[1,0],[1,-1]]
+ end
+
+ def GetMaxProductForNode(nodex,nodey,steps)
+ maxProduct = 0
+ @cardinalDirections.each {|dir|
+ dirProduct = self.TravelDirectionForProduct(dir[0],dir[1],nodex,nodey,steps)
+ maxProduct = [maxProduct,dirProduct].max
+ }
+ return maxProduct
end
def TravelDirectionForProduct(xstep,ystep,ystart,xstart,steps)
xPos = xstart
yPos = ystart
product = 1
while self.CheckBounds(xPos,yPos) and steps > 0 do
- puts @map[yPos][xPos].class
product *= @map[yPos][xPos]
xPos += xstep
yPos += ystep
@@ -53,4 +63,12 @@ def CheckBounds(x,y)
traveler = NodeTraveler.new(split)
-puts traveler.TravelDirectionForProduct(1,1,0,1,2)
+maxProductTotal = 0
+
+for i in 0..traveler.ybound
+ for k in 0..traveler.xbound
+ maxProductTotal = [maxProductTotal,traveler.GetMaxProductForNode(k,i,4)].max
+ end
+end
+
+puts maxProductTotal
View
30 ruby/p12.rb
@@ -2,5 +2,35 @@
#What is the value of the first triangle number to have over five hundred divisors
+def numDivisors(x)
+ sqrtx = Math.sqrt(x)
+ i = 1
+ numDiv = 0
+ divisorList = []
+ while i <= sqrtx
+ if x%i==0
+ numDiv+=(i==sqrtx)?1:2
+ divisorList.push(x/i,i)
+ end
+ i+=1
+ end
+ puts divisorList.uniq.sort.join(',')
+ return numDiv
+end
+for i in 2..20
+ puts i.to_s + ": " + numDivisors(i).to_s
+ puts
+end
+exit
+
+triNum = 1
+triAdder = 2
+
+while numDivisors(triNum) < 500
+ triNum+=triAdder
+ triAdder+=1
+end
+
+puts triNum

No commit comments for this range

Something went wrong with that request. Please try again.