home *** CD-ROM | disk | FTP | other *** search
/ MacPeople 2001 June 15 / MACPEOPLE-2001-06-15.ISO.7z / MACPEOPLE-2001-06-15.ISO / オンラインウエア / 新着!オンラインウエア16 / KHyX.sit / KHyX / Modules / HMNumberTheory / stack.txt < prev   
Text File  |  2001-03-08  |  7KB  |  237 lines

  1. -- stack: in
  2. -- format: 10 (HyperCard 2)
  3. -- flags: 0x1000 (none)
  4. -- protect password hash: 0
  5. -- maximum user level: 5 (scripting)
  6. -- window: Rect(x1=112, y1=113, x2=528, y2=353)
  7. -- screen: Rect(x1=0, y1=0, x2=640, y2=480)
  8. -- card dimensions: w=416 h=240
  9. -- scroll: x=0 y=0
  10. -- background count: 1
  11. -- first background id: 2751
  12. -- card count: 1
  13. -- first card id: 3631
  14. -- list block id: 2129
  15. -- print block id: 0
  16. -- font table block id: 3359
  17. -- style table block id: 3273
  18. -- free block count: 2
  19. -- free size: 6240 bytes
  20. -- total size: 16384 bytes
  21. -- stack block size: 6144 bytes
  22. -- created by hypercard version: 0x02418000
  23. -- compacted by hypercard version: 0x02418000
  24. -- modified by hypercard version: 0x02418000
  25. -- opened by hypercard version: 0x02418000
  26. -- patterns[0]: 0x0000000000000000
  27. -- patterns[1]: 0x8000000008000000
  28. -- patterns[2]: 0x8800220088002200
  29. -- patterns[3]: 0x8888222288882222
  30. -- patterns[4]: 0x88AA22AA88AA22AA
  31. -- patterns[5]: 0xCCAA33AACCAA33AA
  32. -- patterns[6]: 0xEEAABBAAEEAABBAA
  33. -- patterns[7]: 0xEEBBBBEEEEBBBBEE
  34. -- patterns[8]: 0xFFBBFFEEFFBBFFEE
  35. -- patterns[9]: 0xFFBBFFFFFFBBFFFF
  36. -- patterns[10]: 0x8010022001084004
  37. -- patterns[11]: 0xFFFFFFFFFFFFFFFF
  38. -- patterns[12]: 0x8822882288228822
  39. -- patterns[13]: 0x1122448811224488
  40. -- patterns[14]: 0xC4800C6843023026
  41. -- patterns[15]: 0xB130031BD8C00C8D
  42. -- patterns[16]: 0xAA00AA00AA00AA00
  43. -- patterns[17]: 0x8822552288225522
  44. -- patterns[18]: 0x8855225588552255
  45. -- patterns[19]: 0x77DD77DD77DD77DD
  46. -- patterns[20]: 0x8000000000000000
  47. -- patterns[21]: 0xAA55AA55AA55AA55
  48. -- patterns[22]: 0x038448300C020101
  49. -- patterns[23]: 0x8244394482010101
  50. -- patterns[24]: 0x8814224188412214
  51. -- patterns[25]: 0x8080413E080814E3
  52. -- patterns[26]: 0x22048C7422179810
  53. -- patterns[27]: 0xBE808808EB088880
  54. -- patterns[28]: 0x25C8328964244C92
  55. -- patterns[29]: 0xA29C41BE2AC914EB
  56. -- patterns[30]: 0x40A00000040A0000
  57. -- patterns[31]: 0x8040200002040800
  58. -- patterns[32]: 0xAA00800088008000
  59. -- patterns[33]: 0xFF80808080808080
  60. -- patterns[34]: 0x081C22C180010204
  61. -- patterns[35]: 0xFF808080FF080808
  62. -- patterns[36]: 0xF87422478F172271
  63. -- patterns[37]: 0xBF00BFBFB0B0B0B0
  64. -- patterns[38]: 0xFF7FBE5DA2418000
  65. -- patterns[39]: 0xFAF5FAF5A050A050
  66. -- checksum: 0xDDA23EFB
  67. ----- HyperTalk script -----
  68. function binaryAND x,y
  69. put baseconvert(x,10,2) into bx
  70. put baseconvert(y,10,2) into by
  71. repeat while (the number of chars in bx) < (the number of chars in by)
  72.   put "0" before bx
  73. end repeat
  74. repeat while (the number of chars in by) < (the number of chars in bx)
  75.   put "0" before by
  76. end repeat
  77. put "" into bz
  78. repeat with xx = 1 to (the number of chars in by)
  79.   put char xx of bx into c1
  80.   put char xx of by into c2
  81.   put ((c1 = 1) AND (c2 = 1)) into bool
  82.   if bool then put "1" after bz
  83.   if not bool then put "0" after bz
  84. end repeat
  85. return baseconvert(bz,2,10)
  86. end binaryAND
  87.  
  88. function binaryOR x,y
  89. put baseconvert(x,10,2) into bx
  90. put baseconvert(y,10,2) into by
  91. repeat while (the number of chars in bx) < (the number of chars in by)
  92.   put "0" before bx
  93. end repeat
  94. repeat while (the number of chars in by) < (the number of chars in bx)
  95.   put "0" before by
  96. end repeat
  97. put "" into bz
  98. repeat with xx = 1 to (the number of chars in by)
  99.   put char xx of bx into c1
  100.   put char xx of by into c2
  101.   put ((c1 = 1) OR (c2 = 1)) into bool
  102.   if bool then put "1" after bz
  103.   if not bool then put "0" after bz
  104. end repeat
  105. return baseconvert(bz,2,10)
  106. end binaryOR
  107.  
  108. function binaryXOR x,y
  109. put baseconvert(x,10,2) into bx
  110. put baseconvert(y,10,2) into by
  111. repeat while (the number of chars in bx) < (the number of chars in by)
  112.   put "0" before bx
  113. end repeat
  114. repeat while (the number of chars in by) < (the number of chars in bx)
  115.   put "0" before by
  116. end repeat
  117. put "" into bz
  118. repeat with xx = 1 to (the number of chars in by)
  119.   put char xx of bx into c1
  120.   put char xx of by into c2
  121.   put ((c1 = 1) OR (c2 = 1)) into bool
  122.   if ((c1 = 1) AND (c2 = 1)) then put false into bool
  123.   if bool then put "1" after bz
  124.   if not bool then put "0" after bz
  125. end repeat
  126. return baseconvert(bz,2,10)
  127. end binaryXOR
  128.  
  129. function binaryNOT x
  130. put baseconvert(x,10,2) into bx
  131. put "" into bz
  132. repeat with xx = 1 to (the number of chars in bx)
  133.   put char xx of bx into c1
  134.   if c1 = 0 then put "1" after bz
  135.   if c1 = 1 then put "0" after bz
  136. end repeat
  137. return baseconvert(bz,2,10)
  138. end binaryNOT
  139.  
  140. function isPrime x
  141. if x < 2 then return "neither"
  142. if intgr(x) <> x then return "neither"
  143. if (x > 6) and (last char of x is in "024685") then return false -- cheating shortcut
  144. if (x < 7) then return item x of "neither,true,true,false,true,false,true" -- and another
  145. put true into bol
  146. repeat with xx = 2 to intgr(sqrt(x))
  147.   if (x/xx) = intgr(x/xx) then put false into bol
  148. end repeat
  149. return bol
  150. end isPrime
  151.  
  152. function isComposite x
  153. if x < 2 then return "neither"
  154. if intgr(x) <> x then return "neither"
  155. return (not (isprime(x)))
  156. end isComposite
  157.  
  158. function isPerfect x
  159. put empty into factorList
  160. if x < 1 then return "neither"
  161. if intgr(x) <> x then return "neither"
  162. if comma & x & comma is in ",6,28,496,8128,33550336,8589869056,137438691328,2305843008139952128," then return true -- cheating shortcut
  163. if x < 100000000 then return false -- and another
  164. if (factorSum(x)-x) = x then return true
  165. return false
  166. end isPerfect
  167.  
  168. function isAbundant x
  169. put empty into factorList
  170. if x < 1 then return "neither"
  171. if intgr(x) <> x then return "neither"
  172. if comma & x & comma is in ",6,28,496,8128,33550336,8589869056,137438691328,2305843008139952128," then return false
  173. return (factorSum(x)-x) > x
  174. end isAbundant
  175.  
  176. function isDeficient x
  177. put empty into factorList
  178. if x < 1 then return "neither"
  179. if intgr(x) <> x then return "neither"
  180. if comma & x & comma is in ",6,28,496,8128,33550336,8589869056,137438691328,2305843008139952128," then return false
  181. return (factorSum(x)-x) < x
  182. end isDeficient
  183.  
  184. function isHappy x
  185. if x < 0 then return "neither"
  186. if intgr(x) <> x then return "neither"
  187. put 0 into a
  188. repeat with i = 1 to (the number of chars in x)
  189.   add (char i of x)^3 to a
  190. end repeat
  191. return (a = x)
  192. end isHappy
  193.  
  194. function isPalindromic x
  195. put x into n1
  196. put empty into n2
  197. repeat with x = 1 to (the number of chars in n1)
  198.   put char x of n1 before n2
  199. end repeat
  200. return (n1 = n2)
  201. end isPalindromic
  202.  
  203. function isTriangular x
  204. return (sqrt((8*x)+1) = intgr(sqrt((8*x)+1)))
  205. end isTriangular
  206.  
  207. function isSquare x
  208. return (sqrt(x) = intgr(sqrt(x)))
  209. end isSquare
  210.  
  211. function isEven x
  212. return (x/2 = intgr(x/2))
  213. end isEven
  214.  
  215. function isOdd x
  216. return not isEven(x)
  217. end isOdd
  218.  
  219. function isPositive x
  220. return (x > 0)
  221. end isPositive
  222.  
  223. function isNegative x
  224. return (x < 0)
  225. end isNegative
  226.  
  227. function thePerfectness x
  228. if isAbundant(x) then return "1"
  229. if isDeficient(x) then return "-1"
  230. if isPerfect(x) then return "0"
  231. end thePerfectness
  232.  
  233. function thePolarity x
  234. return sgn(x)
  235. end thePolarity
  236.  
  237.