Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.91 KB | None | 0 0
  1. 1001111 | O
  2. 0110101 | 5
  3. 1110110 | v
  4. 1111001 | y
  5. 1011111 | _
  6. 0101011 | +
  7. 1111110 | ~
  8. -------
  9. 5555555 <- Sum of bits in each column. Should give a truthy value.
  10.  
  11. 1010000 | P
  12. 1010000 | P
  13. 1000011 | C
  14. 1000111 | G
  15. -------
  16. 4020122 <- Should give a falsey value
  17.  
  18. Addr. | Dump | #6 #5 #4 #3 #2 #1 #0
  19. ------+-------------------------------------------------+---------------------
  20. 00-0F | 53 3D 3E 5B 2E 2E 2E 53 5D 2E 6D 61 70 28 53 3D | 8 11 9 11 9 9 9
  21. 10-1F | 3E 52 2E 6D 61 70 28 28 5F 47 53 53 53 53 53 53 | 20 18 19 17 14 20 19
  22. 20-2F | 56 57 57 57 2C 56 29 3D 3E 52 5B 56 5D 2D 3D 53 | 30 24 32 25 26 30 29
  23. 30-3F | 2E 63 68 61 72 43 6F 64 65 41 74 28 29 3E 3E 56 | 41 37 37 32 34 38 36
  24. 40-4F | 26 31 29 2C 52 3D 5B 5F 3D 33 5E 33 2C 5F 2C 5F | 47 47 48 43 44 47 46
  25. 50-5F | 2C 5F 2C 5F 2C 5F 2C 5F 5D 29 26 26 21 52 2E 73 | 54 57 55 54 56 56 54
  26. 60-6D | 6F 6D 65 28 53 3D 3E 53 5E 52 5B 5F 5D 29 | 64 64 64 64 64 64 64
  27.  
  28. BXs&=?I&]
  29.  
  30. B 1 0 0 0 0 1 0
  31. X 1 0 1 1 0 0 0
  32. s 1 1 1 0 0 1 1
  33. & 0 1 0 0 1 1 0
  34. = 0 1 1 1 1 0 1
  35. ? 0 1 1 1 1 1 1
  36. I 1 0 0 1 0 0 1
  37. & 0 1 0 0 1 1 0
  38. ] 1 0 1 1 1 0 1
  39.  
  40. Sum 5 5 5 5 5 5 5
  41.  
  42. B % Input string (implicit). Convert each char to its ASCII code, and
  43. % then to binary. This gives a binary matrix, with each char of the
  44. % input corresponding to a row
  45. Xs % Sum of each column. Gives a row vector
  46. &= % All pairwise equality comparisons
  47. ? % If all are true
  48. I % Push 3
  49. & % Specify that the next function, namely implicit display, will
  50. % take one input, instead of the whole stack which is the default
  51. ] % End
  52. % Display (implicit)
  53.  
  54. OBUSE&889.
  55.  
  56. Char -> Hex -> Decimal -> Binary
  57. O 0x4F 79 0b1001111
  58. B 0x42 66 0b1000010
  59. U 0x55 85 0b1010101
  60. S 0x53 83 0b1010011
  61. E 0x45 69 0b1000101
  62. & 0x26 38 0b0100110
  63. 8 0x38 56 0b0111000
  64. 8 0x38 56 0b0111000
  65. 9 0x39 57 0b0111001
  66. . 0x2E 46 0b0101110
  67. -------
  68. 5555555
  69.  
  70. OBUSE&889. - Main link: string
  71. O - cast to ordinals
  72. B - convert to binary
  73. U - upend (reverses each to prepare for vectorised sum)
  74. S - sum (vectorises)
  75. E - all equal? (yields 1 if all bit-sums are equal and 0 if not)
  76. 889. - 889.0
  77. & - bitwise and (1 & 889.0 is 1; and 0 & 889.0 is 0)
  78.  
  79. OBUSE$*8?8
  80.  
  81. O 1 0 0 1 1 1 1
  82. B 1 0 0 0 0 1 0
  83. U 1 0 1 0 1 0 1
  84. S 1 0 1 0 0 1 1
  85. E 1 0 0 0 1 0 1
  86. $ 0 1 0 0 1 0 0
  87. * 0 1 0 1 0 1 0
  88. 8 0 1 1 1 0 0 0
  89. ? 0 1 1 1 1 1 1
  90. 8 0 1 1 1 0 0 0
  91. ————————————————
  92. ∑ 5 5 5 5 5 5 5
  93.  
  94. OBUSE$*8?8 Main link. Argument: s (string)
  95.  
  96. O Ordinal; map all characters in s to their code points.
  97. B Binary; convert each code point to base 2.
  98. U Upend; reverse each binary array to right-align the digits.
  99. 8? If 8 is non-zero (it is):
  100. SE$ Sum the corresponding digits and test the the sums for equality.
  101. Else (never happens):
  102. * 8 Raise all binary digits to the eighth power.
  103.  
  104. Total@IntegerDigits[ToCharacterCode@#,2,7]~MatchQ~{"?";a_ ..}&
  105.  
  106. 0000-0010: 54 6f 74 61-6c 40 49 6e-74 65 67 65-72 44 69 67 Total@In tegerDig
  107. 0000-0020: 69 74 73 5b-54 6f 43 68-61 72 61 63-74 65 72 43 its[ToCh aracterC
  108. 0000-0030: 6f 64 65 40-23 2c 32 2c-37 5d 7e 4d-61 74 63 68 ode@#,2, 7]~Match
  109. 0000-0040: 51 7e 7b 22-3f 1f 1f 1f-1f 1f 1f 1f-1f 1f 1f 1f Q~{"?... ........
  110. 0000-0050: 1f 1f 1f 1f-1f 1a 1a 1a-1a 18 18 18-18 18 10 22 ........ ......."
  111. 0000-0058: 3b 61 5f 20-2e 2e 7d 26 ;a_...}&
  112.  
  113. @(_)~diff(sum(de2bi(+_)))%RRPPPVVVW?????????________
  114.  
  115. 15 22 6 15 10 9 13
  116.  
  117. @(_)~diff(sum(de2bi(+_)))
  118. @(_) % An anonymous function that take a variable _ as input
  119. % We use underscore, instead of a character, since it has the
  120. % most suitable binary represetation
  121. de2bi(+_) % Convert the input string to a binary matrix
  122. sum(de2bi(+_)) % Take the sum of each column
  123. diff(sum(de2bi(+_))) % And calculate the difference between each sum
  124. ~diff(sum(de2bi(+_))) % Negate the result, meaning 0 becomes true,
  125. % and everything else becomes false
  126.  
  127. @(_)!((_=sum(de2bi(+_)))-_(1))%RRRFVVVVVVVVV_____????
  128.  
  129. @(_) % An anonymous function that take a variable _ as input
  130. % We use underscore, instead of a character, since it has the
  131. % most suitable binary represetation
  132. ! % Negate the result, meaning 0 becomes true, and everything else becomes false
  133. de2bi(+_) % Convert the input string to a binary matrix
  134. sum(de2bi(+_)) % Take the sum of each column
  135. (_=sum(de2bi(+_))) % Assign the result to a new variable, also called _
  136. % It's not a problem that we use the same variable name, due
  137. % to the order of evaluation
  138. ((_=sum(de2bi(+_)))-_(1)) % Subtract the first element of the new variable _
  139. % If all elements of the new variable _ are identical, then this
  140. % should give us a vector containing only zeros,
  141. % otherwise, at least one element should be non-zero
  142. !((_=sum(de2bi(+_)))-_(1)) % And finally, we negate this.
  143.  
  144. 00000000 5f 2e 6d 61 70 28 43 3d 3e 28 22 30 22 2a 37 2b |_.map(C=>("0"*7+|
  145. 00000010 2b 28 42 69 67 49 6e 74 28 43 29 74 6f 53 74 72 |+(BigInt(C)toStr|
  146. 00000020 69 6e 67 20 32 29 29 74 61 6b 65 52 69 67 68 74 |ing 2))takeRight|
  147. 00000030 20 37 20 6d 61 70 28 5f 2d 34 38 29 29 2e 74 72 | 7 map(_-48)).tr|
  148. 00000040 61 6e 73 70 6f 73 65 2e 6d 61 70 28 5f 2e 73 75 |anspose.map(_.su|
  149. 00000050 6d 29 2e 74 6f 53 65 74 2e 73 69 7a 65 3d 3d 31 |m).toSet.size==1|
  150. 00000060 2f 2f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f |//______________|
  151. 00000070 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f |________________|
  152. 00000080 1f 1f 1f 1f 1e 1e 1e 1e 16 16 16 16 16 12 12 10 |................|
  153. 00000090 10 10 10 10 10 |.....|
  154.  
  155. [:(*/@:={.)[:+/2 #.inv 3 u:]NB.____UUUUUUUUDD
  156.  
  157. def Y(S):
  158. O=map(sorted,zip(*['{:07b}'.format(ord(W))for W in S]))
  159. return O[1:]==O[:-1]#V_____________
  160.  
  161. 00000000: 64 65 66 09 59 28 53 29 3a 0a 09 4f 3d 6d 61 70 def.Y(S):..O=map
  162. 00000010: 28 73 6f 72 74 65 64 2c 7a 69 70 28 2a 5b 27 7b (sorted,zip(*['{
  163. 00000020: 3a 30 37 62 7d 27 2e 66 6f 72 6d 61 74 28 6f 72 :07b}'.format(or
  164. 00000030: 64 28 57 29 29 66 6f 72 09 57 09 69 6e 09 53 5d d(W))for.W.in.S]
  165. 00000040: 29 29 0a 09 72 65 74 75 72 6e 09 4f 5b 31 3a 5d ))..return.O[1:]
  166. 00000050: 3d 3d 4f 5b 3a 2d 31 5d 23 56 5f 5f 5f 5f 5f 5f ==O[:-1]#V______
  167. 00000060: 5f 5f 5f 5f 5f 5f 5f 16 16 16 16 16 16 16 16 16 _______.........
  168. 00000070: 16 16 14 14 10 .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement