Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import math
- #
- #####################################################
- #
- # This doesn't have the imaging shit. If you
- # want it ask me it's in a different file so I'd
- # need to do some reformatting.
- # JB
- ####################################################
- #
- e = 0
- n = 1
- d = 2
- x = 3
- a = 4
- b = 5
- c = 6
- primes = [2]
- def isPrime(number):
- last = len(primes) - 1
- if(number < primes[last]):
- return number in primes
- else:
- for i in range(primes[last], number):
- hits = 0
- for j in range(2,i/2):
- if(i%j==0):
- hits = hits + 1
- break
- if(hits == 0):
- primes.append(i)
- return number in primes
- def ENA(E,N,A):
- X = int(math.sqrt(2 * N * A - E))
- D = X + A
- C = D * D + E
- B = C / A
- return (E,N,D,X,A,B,C)
- def ENX(E,N,X):
- A = (X*X + E)/(2*N)
- D = X + A
- B = A + 2 * X + N
- C = A * B
- return (E,N,D,X,A,B,C)
- def AB(A,B):
- C = A * B
- D = int(math.sqrt(C))
- E = C - D * D
- X = D - A
- N = ((X * X)+E)/(2 * A)
- return (E,N,D,X,A,B,C)
- def C(C):
- return AB(1,C)
- # Gets (0,1) record at index
- def zeroOne(index): #index starts at index = 1
- A = index * index * 2
- D = 2 * index * (index + 1)
- X = index * 2
- E = 0
- N = 1
- B = A + 2 * X + 2 * N
- C = A * B
- return (E,N,D,X,A,B,C)
- # Gets (1,1) record at index
- def oneOne(index): # so (1,1,2,1,1,5) is index = 0
- A = (index)**2 + (index + 1)**2
- z1 = zeroOne(index)
- D = z1[b]
- X = 2 * index + 1
- E = 1
- N = 1
- B = A + 2 * X + 2 * N
- C = A * B
- return (E,N,D,X,A,B,C)
- # Gets (0,2) record at index in a better way (IMO)
- def zeroTwo(index):
- X = index * 2
- A = index * index
- B = (index + 2)**2
- C = A * B
- D = X + A
- E = C - D*D
- N = ((X * X) + E)/(2 * A)
- return (E,N,D,X,A,B,C)
- #deprecated
- def zeroTwoOG(index):
- one = zeroOne(index)
- return O2fromO1(one)
- #deprecated
- def O2fromO1(rec): #capital o's not 0's
- index = rec[x]/2
- L = index*index
- D = rec[d] - L
- A = rec[a] - L
- B = rec[b] - L + 2
- X = rec[x]
- C = A * B
- return (0,2,D,X,A,B,C)
- #Checks whether or not a record is valid. If not valid, prints the error.
- def isValid(rec):
- A = rec[a]
- B = rec[b]
- C = A*B
- N = rec[n]
- D = rec[d]
- X = rec[x]
- E = rec[e]
- if(A*B-E != D*D): print (rec,"a*b-e != d^2")
- elif(X + A != D): print (rec,"x+a != d")
- elif(A==0):return
- elif(N != ((X * X) +E)/(2*A)): print (rec,"n != (x^2+e)/2a")
- else:print(rec, True)
- #Gets record at (e,1) at index index
- def nOne(E,index):
- if(E == 0):
- return zeroTwo(index)
- if(E == 1):
- return zeroOne(index)
- if(E%2==0):
- #EVEN
- addPart = E/2
- baseRecord = zeroOne(index)
- else:
- #ODD
- addPart = (E-1) / 2
- baseRecord = oneOne(index)
- N = 1
- A = baseRecord[a] + addPart
- B = baseRecord[b] + addPart
- D = baseRecord[d] + addPart
- X = baseRecord[x]
- C = A * B
- return (E,N,D,X,A,B,C)
- #Gets record at (0,n) at index
- def zeroN(N,index):
- if(N == 1):
- return zeroOne(index)
- if(N == 2):
- return zeroTwo(index)
- if(N % 2 == 0):
- #Even
- factor = N/2
- baseRec = zeroTwo(index)
- else:
- #Odd
- factor = N
- baseRec = zeroOne(index)
- E = baseRec[e] * factor
- D = baseRec[d] * factor
- X = baseRec[x] * factor
- A = baseRec[a] * factor
- B = baseRec[b] * factor
- C = A * B
- return (E,N,D,X,A,B,C)
- #This will give coords for parabolic origins and also P is the shifter for N for the parabola
- #This one is a little harder to explain I might need to draw a pic
- def originForP(A,P):
- if(A%2 == 0):
- return ENA(0,(A/2)*P*P,A)
- else:
- if(P%2 == 0):
- return ENA(0, (A*(P*P))/2,A)
- else:
- return ENA(A, (A*(P*P)+1)/2, A)
- #This is my parabolic origin stuff. This is to go up or down from origin of parabola
- def shiftFromOrigin(origin, P, t):
- E = origin[e] - (t * t)
- N = origin[n] + t * P
- A = origin[a]
- return ENA(E,N,A)
- #forgot what this does. Pretty sure its a valid record
- def rightShiftN(rec):
- E = rec[e] + rec[n] * 2
- N = rec[n]
- D = rec[d] + 1
- X = rec[x]
- A = rec[a] + 1
- B = rec[b] + 1
- C = A * B
- return (E,N,D,X,A,B,C)
- #same as above
- def leftShiftN(rec):
- E = rec[e] - rec[n] * 2
- N = rec[n]
- D = rec[d] - 1
- X = rec[x]
- A = rec[a] - 1
- B = rec[b] - 1
- C = A * B
- return (E,N,D,X,A,B,C)
- #Gets record for (-1,n) at index
- def negOneN(N, index):
- rec = nOne(-1,index)
- while(rec[n] != N):
- nextN = rec[n] + 1
- if( rec[a] % nextN == 0):
- M = rec[a] / nextN
- newA = rec[a] - M
- newD = rec[d] - M
- newB = rec[b] - M + 2
- newC = newA * newB
- rec = (rec[e], nextN, newD, rec[x], newA, newB, newC)
- else:
- print("No Record")
- return rec
- #Gets record for (-t^2,n) at index !!This is a good one!!
- def negSquare(square, N,index):
- rec = nOne(-square, index)
- #print(rec)
- while(rec[n] != N):
- nextN = rec[n] + 1
- if( rec[a] % nextN == 0):
- M = rec[a] / nextN
- newA = rec[a] - M
- newB = rec[b] - M + 2
- newD = rec[d] - M
- newC = newA * newB
- rec = (rec[e], nextN, newD, rec[x], newA, newB, newC)
- #print(rec)
- else:
- #print("No Record")
- return -1
- return rec
- # Test I wrote to check if the negative squares works
- def negSquareCheck():
- for i in range(1,10): #<fuck with this 10 if u want more
- square = i*i
- print(str(square) + ":")
- for row in range(1,10): #<also this 10
- for entry in range(1,10): #<also this 10
- rec = negSquare(square, row, entry)
- if(rec != -1):
- isValid(rec)
- #Wanted to see if C was a square anywhere. Yielded some cool results
- def negSquareCheckC():
- for i in range(1,50):
- square = i*i
- print(str(square) + ":")
- for row in range(1,50):
- for entry in range(1,100):
- rec = negSquare(square, row, entry)
- if(rec != -1):
- if(rec[a]>0 and rec[b] > 0 and math.sqrt(rec[c]) % 1 == 0):
- isValid(rec)
- #Generates for A, deprecated
- def generateForAFactor(A):
- end = theEnd(1000,0,0,0,0)
- emin = -40
- emax = 40
- height = 100
- s = " "
- for i in range(emin,emax):
- if(i == 0):
- s = s + "*"
- elif(i%10==0):
- s = s + str(abs((i-i%10))/10)
- else:
- s = s + " "
- s = s + "\n "
- for i in range(emin,emax):
- s = s + str(abs(i)%10)
- s = s + "\n"
- for N in range(-2,height):
- s=s+str(N%10)
- for i in range(emin,emax):
- hit = 0
- if(i in end.keys() and N in end[i].keys()):
- for record in end[i][N]:
- if(record[a] % A == 0):
- s = s + "+"
- hit = 1
- break
- if(hit == 0):
- s = s + "."
- s = s + "\n"
- print(s)
- #Generates ASCII graph for whenever (e,n,d,x,a,b,c) is a certain value
- #val = value to match e,n,d,x,a,b, or c to
- #index = (e,n,d,x,a,b,c) (if u use my code these are predefined constnats)
- def generateFor(val, index):
- end = theEnd(1000,0,0,0,0)
- emin = -40
- emax = 40
- height = 200
- s = " "
- for i in range(emin,emax):
- if(i == 0):
- s = s + "*"
- elif(i%10==0):
- s = s + str(abs((i-i%10))/10)
- else:
- s = s + " "
- s = s + "\n "
- for i in range(emin,emax):
- s = s + str(abs(i)%10)
- s = s + "\n"
- for N in range(-2,height):
- s=s+str(N%10)
- for i in range(emin,emax):
- hit = 0
- if(i in end.keys() and N in end[i].keys()):
- for record in end[i][N]:
- if(record[index] == val):
- s = s + "+"
- hit = 1
- break
- if(hit == 0):
- s = s + "."
- s = s + "\n"
- print(s)
- #TheEnd
- def theEnd(i_max, x_min, y_min, x_max, y_max):
- theEnd = dict()
- for i in range(i_max):
- for j in range(i):
- a = i-j
- b = i+j
- c = a*b
- odd = c%2==1
- d = int(math.sqrt(c))
- d = d - d%1 #floor
- e = c - (d*d)
- f = e - ((2*d) + 1)
- n = i - d
- x = d - a
- if(e not in theEnd): theEnd[e] = dict()
- if(n not in theEnd[e]): theEnd[e][n] = []
- if(f not in theEnd): theEnd[f] = dict()
- if(n-1 not in theEnd[f]): theEnd[f][n-1] = []
- X1 = [e,n,d,x,a,b]
- theEnd[e][n].append(X1)
- X2 = [f,n-1,d+1,x+1,a,b]
- theEnd[f][n-1].append(X2)
- #print(e,n,d,x,a,b)
- return theEnd
Advertisement
Add Comment
Please, Sign In to add comment