Guest User

CollegeAnonsGreatAwesomeWork

a guest
Dec 29th, 2017
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.34 KB | None | 0 0
  1. import math
  2.  
  3. #
  4. #####################################################
  5. #
  6. # This doesn't have the imaging shit. If you
  7. # want it ask me it's in a different file so I'd
  8. # need to do some reformatting.
  9. # JB
  10. ####################################################
  11. #
  12.  
  13. e = 0
  14. n = 1
  15. d = 2
  16. x = 3
  17. a = 4
  18. b = 5
  19. c = 6
  20.  
  21. primes = [2]
  22.  
  23. def isPrime(number):
  24. last = len(primes) - 1
  25. if(number < primes[last]):
  26. return number in primes
  27. else:
  28. for i in range(primes[last], number):
  29. hits = 0
  30. for j in range(2,i/2):
  31. if(i%j==0):
  32. hits = hits + 1
  33. break
  34. if(hits == 0):
  35. primes.append(i)
  36. return number in primes
  37.  
  38.  
  39. def ENA(E,N,A):
  40. X = int(math.sqrt(2 * N * A - E))
  41. D = X + A
  42. C = D * D + E
  43. B = C / A
  44. return (E,N,D,X,A,B,C)
  45.  
  46. def ENX(E,N,X):
  47. A = (X*X + E)/(2*N)
  48. D = X + A
  49. B = A + 2 * X + N
  50. C = A * B
  51. return (E,N,D,X,A,B,C)
  52.  
  53. def AB(A,B):
  54. C = A * B
  55. D = int(math.sqrt(C))
  56. E = C - D * D
  57. X = D - A
  58. N = ((X * X)+E)/(2 * A)
  59. return (E,N,D,X,A,B,C)
  60.  
  61. def C(C):
  62. return AB(1,C)
  63.  
  64. # Gets (0,1) record at index
  65. def zeroOne(index): #index starts at index = 1
  66. A = index * index * 2
  67. D = 2 * index * (index + 1)
  68. X = index * 2
  69. E = 0
  70. N = 1
  71. B = A + 2 * X + 2 * N
  72. C = A * B
  73. return (E,N,D,X,A,B,C)
  74.  
  75. # Gets (1,1) record at index
  76. def oneOne(index): # so (1,1,2,1,1,5) is index = 0
  77. A = (index)**2 + (index + 1)**2
  78. z1 = zeroOne(index)
  79. D = z1[b]
  80. X = 2 * index + 1
  81. E = 1
  82. N = 1
  83. B = A + 2 * X + 2 * N
  84. C = A * B
  85. return (E,N,D,X,A,B,C)
  86.  
  87.  
  88.  
  89. # Gets (0,2) record at index in a better way (IMO)
  90. def zeroTwo(index):
  91. X = index * 2
  92. A = index * index
  93. B = (index + 2)**2
  94. C = A * B
  95. D = X + A
  96. E = C - D*D
  97. N = ((X * X) + E)/(2 * A)
  98. return (E,N,D,X,A,B,C)
  99.  
  100.  
  101. #deprecated
  102. def zeroTwoOG(index):
  103. one = zeroOne(index)
  104. return O2fromO1(one)
  105.  
  106. #deprecated
  107. def O2fromO1(rec): #capital o's not 0's
  108. index = rec[x]/2
  109. L = index*index
  110. D = rec[d] - L
  111. A = rec[a] - L
  112. B = rec[b] - L + 2
  113. X = rec[x]
  114. C = A * B
  115. return (0,2,D,X,A,B,C)
  116.  
  117. #Checks whether or not a record is valid. If not valid, prints the error.
  118. def isValid(rec):
  119. A = rec[a]
  120. B = rec[b]
  121. C = A*B
  122. N = rec[n]
  123. D = rec[d]
  124. X = rec[x]
  125. E = rec[e]
  126. if(A*B-E != D*D): print (rec,"a*b-e != d^2")
  127. elif(X + A != D): print (rec,"x+a != d")
  128. elif(A==0):return
  129. elif(N != ((X * X) +E)/(2*A)): print (rec,"n != (x^2+e)/2a")
  130. else:print(rec, True)
  131.  
  132. #Gets record at (e,1) at index index
  133. def nOne(E,index):
  134. if(E == 0):
  135. return zeroTwo(index)
  136. if(E == 1):
  137. return zeroOne(index)
  138.  
  139. if(E%2==0):
  140. #EVEN
  141. addPart = E/2
  142. baseRecord = zeroOne(index)
  143. else:
  144. #ODD
  145. addPart = (E-1) / 2
  146. baseRecord = oneOne(index)
  147. N = 1
  148. A = baseRecord[a] + addPart
  149. B = baseRecord[b] + addPart
  150. D = baseRecord[d] + addPart
  151. X = baseRecord[x]
  152. C = A * B
  153. return (E,N,D,X,A,B,C)
  154.  
  155. #Gets record at (0,n) at index
  156. def zeroN(N,index):
  157. if(N == 1):
  158. return zeroOne(index)
  159. if(N == 2):
  160. return zeroTwo(index)
  161.  
  162. if(N % 2 == 0):
  163. #Even
  164. factor = N/2
  165. baseRec = zeroTwo(index)
  166. else:
  167. #Odd
  168. factor = N
  169. baseRec = zeroOne(index)
  170. E = baseRec[e] * factor
  171. D = baseRec[d] * factor
  172. X = baseRec[x] * factor
  173. A = baseRec[a] * factor
  174. B = baseRec[b] * factor
  175. C = A * B
  176. return (E,N,D,X,A,B,C)
  177.  
  178.  
  179.  
  180. #This will give coords for parabolic origins and also P is the shifter for N for the parabola
  181. #This one is a little harder to explain I might need to draw a pic
  182. def originForP(A,P):
  183. if(A%2 == 0):
  184. return ENA(0,(A/2)*P*P,A)
  185. else:
  186. if(P%2 == 0):
  187. return ENA(0, (A*(P*P))/2,A)
  188. else:
  189. return ENA(A, (A*(P*P)+1)/2, A)
  190.  
  191. #This is my parabolic origin stuff. This is to go up or down from origin of parabola
  192. def shiftFromOrigin(origin, P, t):
  193. E = origin[e] - (t * t)
  194. N = origin[n] + t * P
  195. A = origin[a]
  196. return ENA(E,N,A)
  197.  
  198. #forgot what this does. Pretty sure its a valid record
  199. def rightShiftN(rec):
  200. E = rec[e] + rec[n] * 2
  201. N = rec[n]
  202. D = rec[d] + 1
  203. X = rec[x]
  204. A = rec[a] + 1
  205. B = rec[b] + 1
  206. C = A * B
  207. return (E,N,D,X,A,B,C)
  208. #same as above
  209. def leftShiftN(rec):
  210. E = rec[e] - rec[n] * 2
  211. N = rec[n]
  212. D = rec[d] - 1
  213. X = rec[x]
  214. A = rec[a] - 1
  215. B = rec[b] - 1
  216. C = A * B
  217. return (E,N,D,X,A,B,C)
  218.  
  219. #Gets record for (-1,n) at index
  220. def negOneN(N, index):
  221. rec = nOne(-1,index)
  222. while(rec[n] != N):
  223. nextN = rec[n] + 1
  224. if( rec[a] % nextN == 0):
  225. M = rec[a] / nextN
  226. newA = rec[a] - M
  227. newD = rec[d] - M
  228. newB = rec[b] - M + 2
  229. newC = newA * newB
  230. rec = (rec[e], nextN, newD, rec[x], newA, newB, newC)
  231. else:
  232. print("No Record")
  233. return rec
  234.  
  235. #Gets record for (-t^2,n) at index !!This is a good one!!
  236. def negSquare(square, N,index):
  237. rec = nOne(-square, index)
  238. #print(rec)
  239. while(rec[n] != N):
  240. nextN = rec[n] + 1
  241. if( rec[a] % nextN == 0):
  242. M = rec[a] / nextN
  243. newA = rec[a] - M
  244. newB = rec[b] - M + 2
  245. newD = rec[d] - M
  246. newC = newA * newB
  247. rec = (rec[e], nextN, newD, rec[x], newA, newB, newC)
  248. #print(rec)
  249. else:
  250. #print("No Record")
  251. return -1
  252. return rec
  253.  
  254.  
  255. # Test I wrote to check if the negative squares works
  256. def negSquareCheck():
  257. for i in range(1,10): #<fuck with this 10 if u want more
  258. square = i*i
  259. print(str(square) + ":")
  260. for row in range(1,10): #<also this 10
  261. for entry in range(1,10): #<also this 10
  262. rec = negSquare(square, row, entry)
  263. if(rec != -1):
  264. isValid(rec)
  265.  
  266.  
  267.  
  268. #Wanted to see if C was a square anywhere. Yielded some cool results
  269. def negSquareCheckC():
  270. for i in range(1,50):
  271. square = i*i
  272. print(str(square) + ":")
  273. for row in range(1,50):
  274. for entry in range(1,100):
  275. rec = negSquare(square, row, entry)
  276. if(rec != -1):
  277. if(rec[a]>0 and rec[b] > 0 and math.sqrt(rec[c]) % 1 == 0):
  278. isValid(rec)
  279.  
  280. #Generates for A, deprecated
  281. def generateForAFactor(A):
  282. end = theEnd(1000,0,0,0,0)
  283. emin = -40
  284. emax = 40
  285. height = 100
  286. s = " "
  287. for i in range(emin,emax):
  288. if(i == 0):
  289. s = s + "*"
  290. elif(i%10==0):
  291. s = s + str(abs((i-i%10))/10)
  292. else:
  293. s = s + " "
  294. s = s + "\n "
  295. for i in range(emin,emax):
  296. s = s + str(abs(i)%10)
  297. s = s + "\n"
  298. for N in range(-2,height):
  299. s=s+str(N%10)
  300. for i in range(emin,emax):
  301. hit = 0
  302. if(i in end.keys() and N in end[i].keys()):
  303. for record in end[i][N]:
  304. if(record[a] % A == 0):
  305. s = s + "+"
  306. hit = 1
  307. break
  308.  
  309. if(hit == 0):
  310. s = s + "."
  311. s = s + "\n"
  312. print(s)
  313.  
  314. #Generates ASCII graph for whenever (e,n,d,x,a,b,c) is a certain value
  315. #val = value to match e,n,d,x,a,b, or c to
  316. #index = (e,n,d,x,a,b,c) (if u use my code these are predefined constnats)
  317. def generateFor(val, index):
  318. end = theEnd(1000,0,0,0,0)
  319. emin = -40
  320. emax = 40
  321. height = 200
  322. s = " "
  323. for i in range(emin,emax):
  324. if(i == 0):
  325. s = s + "*"
  326. elif(i%10==0):
  327. s = s + str(abs((i-i%10))/10)
  328. else:
  329. s = s + " "
  330. s = s + "\n "
  331. for i in range(emin,emax):
  332. s = s + str(abs(i)%10)
  333. s = s + "\n"
  334. for N in range(-2,height):
  335. s=s+str(N%10)
  336. for i in range(emin,emax):
  337. hit = 0
  338. if(i in end.keys() and N in end[i].keys()):
  339. for record in end[i][N]:
  340. if(record[index] == val):
  341. s = s + "+"
  342. hit = 1
  343. break
  344.  
  345. if(hit == 0):
  346. s = s + "."
  347. s = s + "\n"
  348. print(s)
  349.  
  350.  
  351. #TheEnd
  352. def theEnd(i_max, x_min, y_min, x_max, y_max):
  353. theEnd = dict()
  354. for i in range(i_max):
  355. for j in range(i):
  356. a = i-j
  357. b = i+j
  358. c = a*b
  359. odd = c%2==1
  360. d = int(math.sqrt(c))
  361. d = d - d%1 #floor
  362. e = c - (d*d)
  363. f = e - ((2*d) + 1)
  364. n = i - d
  365. x = d - a
  366.  
  367. if(e not in theEnd): theEnd[e] = dict()
  368. if(n not in theEnd[e]): theEnd[e][n] = []
  369. if(f not in theEnd): theEnd[f] = dict()
  370. if(n-1 not in theEnd[f]): theEnd[f][n-1] = []
  371. X1 = [e,n,d,x,a,b]
  372. theEnd[e][n].append(X1)
  373. X2 = [f,n-1,d+1,x+1,a,b]
  374. theEnd[f][n-1].append(X2)
  375. #print(e,n,d,x,a,b)
  376. return theEnd
Advertisement
Add Comment
Please, Sign In to add comment