Browse Source
Changes to be committed: new file: 079PassDerive.py new file: 085CountTriangle.py new file: 101TriangleContain.py new file: 102_triangles.py new file: 112_bouncy.py new file: 187_semiprime/187_semiprime new file: 187_semiprime/primes.txt new file: 187_semiprime/semiprime.go new file: 493Rainbow.py new file: codedTriangle.py new file: coinSum.py new file: eulerCoinSum.py new file: fiboChecker.py new file: oddEven.py new file: p042_words.txt new file: powerfulDigit.py new file: selfPower.py new file: sunday.py new file: symbolCheck.pymaster
19 changed files with 1447 additions and 0 deletions
@ -0,0 +1,42 @@ |
|||||
|
def checkPass(longPass, combi): |
||||
|
passStr=str(longPass) |
||||
|
countPass=0 |
||||
|
for i in range(len(passStr)): |
||||
|
if countPass!=3 and passStr[i]==combi[countPass]: |
||||
|
countPass+=1 |
||||
|
|
||||
|
if countPass==3: |
||||
|
return True |
||||
|
else: |
||||
|
return False |
||||
|
|
||||
|
|
||||
|
def checkAll(longPass, combiList): |
||||
|
failure=False |
||||
|
for i in range(len(combiList)): |
||||
|
tempAns=checkPass(longPass, combiList[i]) |
||||
|
if not(tempAns): |
||||
|
failure=True |
||||
|
break |
||||
|
|
||||
|
return not(failure) |
||||
|
|
||||
|
currentIn=" " |
||||
|
combiList=[] |
||||
|
while currentIn!="": |
||||
|
currentIn=input() |
||||
|
if currentIn!="": |
||||
|
combiList.append(currentIn) |
||||
|
|
||||
|
longPass=100 |
||||
|
while (1): |
||||
|
|
||||
|
if longPass%1000==0: |
||||
|
print(longPass) |
||||
|
|
||||
|
if checkAll(longPass, combiList): |
||||
|
print("Answer: "+str(longPass)) |
||||
|
break |
||||
|
else: |
||||
|
longPass+=1 |
||||
|
|
@ -0,0 +1,31 @@ |
|||||
|
def gridToTriangle(x,y): |
||||
|
sumOfTriangle=0 |
||||
|
for i in range(x): |
||||
|
for o in range(y): |
||||
|
sumOfTriangle+=(x-i)*(y-o) |
||||
|
|
||||
|
return(sumOfTriangle) |
||||
|
|
||||
|
solved=False |
||||
|
sizeOfTriangle=1 |
||||
|
closestGuy=[0,0] |
||||
|
difference=99999999 |
||||
|
answer=0 |
||||
|
|
||||
|
while not(solved): |
||||
|
sizeOfTriangle+=1 |
||||
|
for i in range(sizeOfTriangle): |
||||
|
tempAns=gridToTriangle(i+1,sizeOfTriangle) |
||||
|
tempDiff=abs(2000000-tempAns) |
||||
|
if tempDiff<difference: |
||||
|
closestGuy=[i+1,sizeOfTriangle] |
||||
|
difference=tempDiff |
||||
|
answer=tempAns |
||||
|
if tempDiff>200000000: |
||||
|
solved=True |
||||
|
|
||||
|
if sizeOfTriangle%100==0: |
||||
|
print(sizeOfTriangle) |
||||
|
|
||||
|
print(closestGuy) |
||||
|
print(answer) |
@ -0,0 +1,54 @@ |
|||||
|
#! /usr/bin/python3 |
||||
|
|
||||
|
def findGrad(x1, y1, x2, y2): |
||||
|
top=y2-y1 |
||||
|
bot=x2-x1 |
||||
|
|
||||
|
if bot==0: |
||||
|
return 0, 1 |
||||
|
else: |
||||
|
return top/bot, 0 |
||||
|
|
||||
|
def findRes(x1, y1, x2, y2): |
||||
|
grad=findGrad(x1,y1,x2,y2) |
||||
|
if grad[1]==1: |
||||
|
return x1 |
||||
|
else: |
||||
|
return y1-grad[0]*x1 |
||||
|
|
||||
|
|
||||
|
totalCount=0 |
||||
|
|
||||
|
testFile=open("p102_triangles.txt") |
||||
|
|
||||
|
for iLine in testFile: |
||||
|
|
||||
|
coordS=[] |
||||
|
coordS=iLine.split(",") |
||||
|
coord=[int(coordS[0]),int(coordS[1]),int(coordS[2]),int(coordS[3]),int(coordS[4]),int(coordS[5])] |
||||
|
|
||||
|
countSuc=[0,0,0] |
||||
|
for i in range(3): |
||||
|
for o in range(3): |
||||
|
if o!=i: |
||||
|
last=3-i-o |
||||
|
grad, check=findGrad(coord[i*2], coord[i*2+1], coord[o*2], coord[o*2+1]) |
||||
|
intercept=findRes(coord[i*2], coord[i*2+1], coord[o*2], coord[o*2+1]) |
||||
|
|
||||
|
if check==1: |
||||
|
if 0-intercept>0 and coord[last*2]-intercept>0: |
||||
|
countSuc[i]+=1 |
||||
|
elif 0-intercept<0 and coord[last*2]-intercept<0: |
||||
|
countSuc[i]+=1 |
||||
|
else: |
||||
|
pseu=coord[last*2+1]-grad*coord[last*2] |
||||
|
if 0-intercept>0 and pseu-intercept>0: |
||||
|
countSuc[i]+=1 |
||||
|
elif 0-intercept<0 and pseu-intercept<0: |
||||
|
countSuc[i]+=1 |
||||
|
print(coord) |
||||
|
print(countSuc) |
||||
|
if countSuc[0]==2 and countSuc[1]==2 and countSuc[2]==2: |
||||
|
totalCount+=1 |
||||
|
|
||||
|
print(totalCount) |
File diff suppressed because it is too large
@ -0,0 +1,5 @@ |
|||||
|
import math |
||||
|
|
||||
|
def checkBouncy(a): |
||||
|
length=math.log(a,10) |
||||
|
|
Binary file not shown.
@ -0,0 +1,40 @@ |
|||||
|
104777 |
||||
|
224777 |
||||
|
350430 |
||||
|
479958 |
||||
|
611986 |
||||
|
746796 |
||||
|
882407 |
||||
|
1020421 |
||||
|
1159557 |
||||
|
1299762 |
||||
|
1441080 |
||||
|
1583615 |
||||
|
1726977 |
||||
|
1870727 |
||||
|
2015226 |
||||
|
2160606 |
||||
|
2307264 |
||||
|
2454646 |
||||
|
2601918 |
||||
|
2750198 |
||||
|
2898575 |
||||
|
3047798 |
||||
|
3196971 |
||||
|
3346657 |
||||
|
3497892 |
||||
|
3648972 |
||||
|
3800242 |
||||
|
3951203 |
||||
|
4103663 |
||||
|
4256273 |
||||
|
4410366 |
||||
|
4562748 |
||||
|
4716106 |
||||
|
4869917 |
||||
|
5023360 |
||||
|
5178092 |
||||
|
5332561 |
||||
|
5487779 |
||||
|
5644074 |
||||
|
5800173 |
@ -0,0 +1,56 @@ |
|||||
|
package main |
||||
|
|
||||
|
import "fmt" |
||||
|
|
||||
|
func main() { |
||||
|
THREADCOUNT := 20 |
||||
|
primeList:=make([]int,0,4000) |
||||
|
sentCount:=0 |
||||
|
recvCount:=0 |
||||
|
chani := make(chan int) |
||||
|
var tempi int |
||||
|
|
||||
|
for i:=2; i<50000000; i++ { |
||||
|
if sentCount - recvCount < THREADCOUNT { |
||||
|
sentCount+=1 |
||||
|
go checkPrime(i, chani) |
||||
|
} else { |
||||
|
emptyChannel := false |
||||
|
for emptyChannel!= true { |
||||
|
select { |
||||
|
case tempi = <-chani: |
||||
|
recvCount+=1 |
||||
|
if tempi!=0 { |
||||
|
primeList=append(primeList, tempi) |
||||
|
if len(primeList) % 10000 ==0 { |
||||
|
fmt.Println(i) |
||||
|
} |
||||
|
} |
||||
|
default: |
||||
|
emptyChannel = true |
||||
|
} |
||||
|
} |
||||
|
i-= 1 |
||||
|
} |
||||
|
} |
||||
|
fmt.Println(primeList) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
func checkPrime(i int, chani chan int) bool { |
||||
|
checkCount := 0 |
||||
|
|
||||
|
for c:=2; c<i/2; c++ { |
||||
|
if i%c == 0 { |
||||
|
checkCount+=1 |
||||
|
break |
||||
|
} |
||||
|
} |
||||
|
if checkCount==0 { |
||||
|
chani <- i |
||||
|
return true |
||||
|
} else { |
||||
|
chani <- 0 |
||||
|
return false |
||||
|
} |
||||
|
} |
@ -0,0 +1,30 @@ |
|||||
|
#! /usr/bin/python3 |
||||
|
from decimal import * |
||||
|
import random |
||||
|
|
||||
|
total=[] |
||||
|
|
||||
|
for i in range(1000): |
||||
|
print(i) |
||||
|
for o in range(10): |
||||
|
balls=[] |
||||
|
bag=[] |
||||
|
for color in range(70): |
||||
|
balls.append(int(random.uniform(0,7))) |
||||
|
for choice in range(10): |
||||
|
choose=int(random.uniform(0,70)) |
||||
|
while balls[choose]==-1: |
||||
|
choose=int(random.uniform(0,70)) |
||||
|
|
||||
|
bag.append(balls[choose]) |
||||
|
balls[choose]=-1 |
||||
|
|
||||
|
allCount=len(set(balls)) |
||||
|
total.append(allCount) |
||||
|
|
||||
|
a=Decimal(sum(total)) |
||||
|
b=Decimal(len(total)) |
||||
|
c=Decimal(a/b) |
||||
|
print(getcontext()) |
||||
|
print(c) |
||||
|
print(total) |
@ -0,0 +1,27 @@ |
|||||
|
triSet=set() |
||||
|
|
||||
|
for i in range(1,601): |
||||
|
triSet.add(i*(i+1)*0.5) |
||||
|
|
||||
|
fobj=open("p042_words.txt") |
||||
|
for line in fobj: |
||||
|
names=line |
||||
|
|
||||
|
fobj.close() |
||||
|
|
||||
|
print(names) |
||||
|
|
||||
|
answer=0 |
||||
|
|
||||
|
workingcount=0 |
||||
|
|
||||
|
for i in range(0,len(names)): |
||||
|
if names[i]=="\"" or names[i]==",": |
||||
|
if workingcount!=0: |
||||
|
if workingcount in triSet: |
||||
|
answer=answer+1 |
||||
|
workingcount=0 |
||||
|
else: |
||||
|
workingcount=workingcount+ord(names[i])-64 |
||||
|
|
||||
|
print(answer) |
@ -0,0 +1,33 @@ |
|||||
|
maxjump=[1,9,9,90,90,80,200,200] |
||||
|
value=[200,100,50,20,10,5,2,1] |
||||
|
|
||||
|
working=[0,0,0,0,0,0,0,0] |
||||
|
|
||||
|
ans=0 |
||||
|
|
||||
|
while working[0]<maxjump[0]: |
||||
|
working[7]=working[7]+1 |
||||
|
|
||||
|
#check if exceed maxjump |
||||
|
for i in range(7,0,-1): |
||||
|
if working[i] > maxjump[i]: |
||||
|
working[i-1]=working[i-1]+1 |
||||
|
working[i]=0 |
||||
|
|
||||
|
#start check if adds to two |
||||
|
check=0 |
||||
|
for i in range(0,8): |
||||
|
check=check+working[i]*value[i] |
||||
|
|
||||
|
if check==200: |
||||
|
print(working) |
||||
|
ans=ans+1 |
||||
|
elif check>200: |
||||
|
for i in range(7,0,-1): |
||||
|
if working[i]!=0: |
||||
|
working[i]=0 |
||||
|
working[i-1]=working[i-1]+1 |
||||
|
working[7]=-1 |
||||
|
break |
||||
|
|
||||
|
print("Total Count:",ans+1) |
@ -0,0 +1,33 @@ |
|||||
|
maxjump=[1,9,9,90,90,80,200,200] |
||||
|
value=[200,100,50,20,10,5,2,1] |
||||
|
|
||||
|
working=[0,0,0,0,0,0,0,0] |
||||
|
|
||||
|
ans=0 |
||||
|
|
||||
|
while working[0]<maxjump[0]: |
||||
|
working[7]=working[7]+1 |
||||
|
|
||||
|
#check if exceed maxjump |
||||
|
for i in range(7,0,-1): |
||||
|
if working[i] > maxjump[i]: |
||||
|
working[i-1]=working[i-1]+1 |
||||
|
working[i]=0 |
||||
|
|
||||
|
#start check if adds to two |
||||
|
check=0 |
||||
|
for i in range(0,8): |
||||
|
check=check+working[i]*value[i] |
||||
|
|
||||
|
if check==200: |
||||
|
print(working) |
||||
|
ans=ans+1 |
||||
|
elif check>200: |
||||
|
for i in range(7,0,-1): |
||||
|
if working[i]!=0: |
||||
|
working[i]=0 |
||||
|
working[i-1]=working[i-1]+1 |
||||
|
working[7]=-1 |
||||
|
break |
||||
|
|
||||
|
print("Total Count:",ans+1) |
@ -0,0 +1,24 @@ |
|||||
|
def FibonacciChecker(num2): |
||||
|
num=int(num2) |
||||
|
working=1 |
||||
|
|
||||
|
if num==1: |
||||
|
return "yes" |
||||
|
|
||||
|
full=[1,1] |
||||
|
|
||||
|
while full[working]<num: |
||||
|
full+=[full[working]+full[working-1]] |
||||
|
if full[working+1]>num: |
||||
|
return "no" |
||||
|
working+=1 |
||||
|
|
||||
|
if full[working]==num: |
||||
|
return "yes" |
||||
|
return "no" |
||||
|
|
||||
|
|
||||
|
# keep this function call here |
||||
|
# to see how to enter arguments in Python scroll down |
||||
|
print FibonacciChecker(raw_input()) |
||||
|
|
@ -0,0 +1,11 @@ |
|||||
|
#!/usr/bin/python3 |
||||
|
|
||||
|
oddEven=50 |
||||
|
|
||||
|
if oddEven%2==1: |
||||
|
print(str(oddEven)+" is odd!") |
||||
|
elif oddEven%2==0: |
||||
|
print(str(oddEven)+" is even!") |
||||
|
else: |
||||
|
print("This shouldn't run!") |
||||
|
|
File diff suppressed because one or more lines are too long
@ -0,0 +1,13 @@ |
|||||
|
import math |
||||
|
|
||||
|
answer=0 |
||||
|
seto=set() |
||||
|
for i in range(2,10): |
||||
|
work=1 |
||||
|
while work<=199: |
||||
|
if math.log(math.pow(i,work),10)//1==work-1: |
||||
|
seto.add(math.pow(i,work)) |
||||
|
print(math.pow(i,work)) |
||||
|
work+=1 |
||||
|
|
||||
|
print("Answer:",len(seto)) |
@ -0,0 +1,8 @@ |
|||||
|
import math |
||||
|
|
||||
|
ans=0 |
||||
|
for i in range(1,1001): |
||||
|
ans=ans+pow(i,i) |
||||
|
|
||||
|
magic=str(ans) |
||||
|
print(magic[-10:len(magic)]) |
@ -0,0 +1,19 @@ |
|||||
|
import datetime |
||||
|
import calendar |
||||
|
|
||||
|
ans = 0 |
||||
|
|
||||
|
for year in range(1901, 2001): |
||||
|
for month in range(1,13): |
||||
|
monthmax=calendar.monthrange(year,month) |
||||
|
monthmax=monthmax[1] |
||||
|
working=datetime.date(year,month,1) |
||||
|
if working.month!=month: |
||||
|
break |
||||
|
|
||||
|
if working.weekday() == 6: |
||||
|
print ("Date" , working, ans) |
||||
|
ans=ans+1 |
||||
|
|
||||
|
print ("Answer:"+str(ans)) |
||||
|
|
@ -0,0 +1,20 @@ |
|||||
|
def SimpleSymbols(ytr): |
||||
|
|
||||
|
magic=ytr |
||||
|
|
||||
|
if (ord(magic[len(magic)-1]) in range(97,123)) or (ord(magic[len(magic)-1]) in range(65,91)): |
||||
|
return "false" |
||||
|
|
||||
|
for i in range(0,len(magic)): |
||||
|
if(ord(magic[i]) in range(97,123)) or (ord(magic[i]) in range(65,91)): |
||||
|
if i==0: |
||||
|
return str(i)+"false" |
||||
|
if ((magic[i-1])!='+') or ((magic[i+1])!='+'): |
||||
|
return "false" |
||||
|
|
||||
|
return "true" |
||||
|
# keep this function call here |
||||
|
# to see how to enter arguments in Python scroll down |
||||
|
print(SimpleSymbols(raw_input())) |
||||
|
|
||||
|
|
Loading…
Reference in new issue