Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1001111 | O
- 0110101 | 5
- 1110110 | v
- 1111001 | y
- 1011111 | _
- 0101011 | +
- 1111110 | ~
- -------
- 5555555 <- Sum of bits in each column. Should give a truthy value.
- 1010000 | P
- 1010000 | P
- 1000011 | C
- 1000111 | G
- -------
- 4020122 <- Should give a falsey value
- Addr. | Dump | #6 #5 #4 #3 #2 #1 #0
- ------+-------------------------------------------------+---------------------
- 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
- 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
- 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
- 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
- 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
- 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
- 60-6D | 6F 6D 65 28 53 3D 3E 53 5E 52 5B 5F 5D 29 | 64 64 64 64 64 64 64
- BXs&=?I&]
- B 1 0 0 0 0 1 0
- X 1 0 1 1 0 0 0
- s 1 1 1 0 0 1 1
- & 0 1 0 0 1 1 0
- = 0 1 1 1 1 0 1
- ? 0 1 1 1 1 1 1
- I 1 0 0 1 0 0 1
- & 0 1 0 0 1 1 0
- ] 1 0 1 1 1 0 1
- Sum 5 5 5 5 5 5 5
- B % Input string (implicit). Convert each char to its ASCII code, and
- % then to binary. This gives a binary matrix, with each char of the
- % input corresponding to a row
- Xs % Sum of each column. Gives a row vector
- &= % All pairwise equality comparisons
- ? % If all are true
- I % Push 3
- & % Specify that the next function, namely implicit display, will
- % take one input, instead of the whole stack which is the default
- ] % End
- % Display (implicit)
- OBUSE&889.
- Char -> Hex -> Decimal -> Binary
- O 0x4F 79 0b1001111
- B 0x42 66 0b1000010
- U 0x55 85 0b1010101
- S 0x53 83 0b1010011
- E 0x45 69 0b1000101
- & 0x26 38 0b0100110
- 8 0x38 56 0b0111000
- 8 0x38 56 0b0111000
- 9 0x39 57 0b0111001
- . 0x2E 46 0b0101110
- -------
- 5555555
- OBUSE&889. - Main link: string
- O - cast to ordinals
- B - convert to binary
- U - upend (reverses each to prepare for vectorised sum)
- S - sum (vectorises)
- E - all equal? (yields 1 if all bit-sums are equal and 0 if not)
- 889. - 889.0
- & - bitwise and (1 & 889.0 is 1; and 0 & 889.0 is 0)
- OBUSE$*8?8
- O 1 0 0 1 1 1 1
- B 1 0 0 0 0 1 0
- U 1 0 1 0 1 0 1
- S 1 0 1 0 0 1 1
- E 1 0 0 0 1 0 1
- $ 0 1 0 0 1 0 0
- * 0 1 0 1 0 1 0
- 8 0 1 1 1 0 0 0
- ? 0 1 1 1 1 1 1
- 8 0 1 1 1 0 0 0
- ————————————————
- ∑ 5 5 5 5 5 5 5
- OBUSE$*8?8 Main link. Argument: s (string)
- O Ordinal; map all characters in s to their code points.
- B Binary; convert each code point to base 2.
- U Upend; reverse each binary array to right-align the digits.
- 8? If 8 is non-zero (it is):
- SE$ Sum the corresponding digits and test the the sums for equality.
- Else (never happens):
- * 8 Raise all binary digits to the eighth power.
- Total@IntegerDigits[ToCharacterCode@#,2,7]~MatchQ~{"?";a_ ..}&
- 0000-0010: 54 6f 74 61-6c 40 49 6e-74 65 67 65-72 44 69 67 Total@In tegerDig
- 0000-0020: 69 74 73 5b-54 6f 43 68-61 72 61 63-74 65 72 43 its[ToCh aracterC
- 0000-0030: 6f 64 65 40-23 2c 32 2c-37 5d 7e 4d-61 74 63 68 ode@#,2, 7]~Match
- 0000-0040: 51 7e 7b 22-3f 1f 1f 1f-1f 1f 1f 1f-1f 1f 1f 1f Q~{"?... ........
- 0000-0050: 1f 1f 1f 1f-1f 1a 1a 1a-1a 18 18 18-18 18 10 22 ........ ......."
- 0000-0058: 3b 61 5f 20-2e 2e 7d 26 ;a_...}&
- @(_)~diff(sum(de2bi(+_)))%RRPPPVVVW?????????________
- 15 22 6 15 10 9 13
- @(_)~diff(sum(de2bi(+_)))
- @(_) % An anonymous function that take a variable _ as input
- % We use underscore, instead of a character, since it has the
- % most suitable binary represetation
- de2bi(+_) % Convert the input string to a binary matrix
- sum(de2bi(+_)) % Take the sum of each column
- diff(sum(de2bi(+_))) % And calculate the difference between each sum
- ~diff(sum(de2bi(+_))) % Negate the result, meaning 0 becomes true,
- % and everything else becomes false
- @(_)!((_=sum(de2bi(+_)))-_(1))%RRRFVVVVVVVVV_____????
- @(_) % An anonymous function that take a variable _ as input
- % We use underscore, instead of a character, since it has the
- % most suitable binary represetation
- ! % Negate the result, meaning 0 becomes true, and everything else becomes false
- de2bi(+_) % Convert the input string to a binary matrix
- sum(de2bi(+_)) % Take the sum of each column
- (_=sum(de2bi(+_))) % Assign the result to a new variable, also called _
- % It's not a problem that we use the same variable name, due
- % to the order of evaluation
- ((_=sum(de2bi(+_)))-_(1)) % Subtract the first element of the new variable _
- % If all elements of the new variable _ are identical, then this
- % should give us a vector containing only zeros,
- % otherwise, at least one element should be non-zero
- !((_=sum(de2bi(+_)))-_(1)) % And finally, we negate this.
- 00000000 5f 2e 6d 61 70 28 43 3d 3e 28 22 30 22 2a 37 2b |_.map(C=>("0"*7+|
- 00000010 2b 28 42 69 67 49 6e 74 28 43 29 74 6f 53 74 72 |+(BigInt(C)toStr|
- 00000020 69 6e 67 20 32 29 29 74 61 6b 65 52 69 67 68 74 |ing 2))takeRight|
- 00000030 20 37 20 6d 61 70 28 5f 2d 34 38 29 29 2e 74 72 | 7 map(_-48)).tr|
- 00000040 61 6e 73 70 6f 73 65 2e 6d 61 70 28 5f 2e 73 75 |anspose.map(_.su|
- 00000050 6d 29 2e 74 6f 53 65 74 2e 73 69 7a 65 3d 3d 31 |m).toSet.size==1|
- 00000060 2f 2f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f |//______________|
- 00000070 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f 5f |________________|
- 00000080 1f 1f 1f 1f 1e 1e 1e 1e 16 16 16 16 16 12 12 10 |................|
- 00000090 10 10 10 10 10 |.....|
- [:(*/@:={.)[:+/2 #.inv 3 u:]NB.____UUUUUUUUDD
- def Y(S):
- O=map(sorted,zip(*['{:07b}'.format(ord(W))for W in S]))
- return O[1:]==O[:-1]#V_____________
- 00000000: 64 65 66 09 59 28 53 29 3a 0a 09 4f 3d 6d 61 70 def.Y(S):..O=map
- 00000010: 28 73 6f 72 74 65 64 2c 7a 69 70 28 2a 5b 27 7b (sorted,zip(*['{
- 00000020: 3a 30 37 62 7d 27 2e 66 6f 72 6d 61 74 28 6f 72 :07b}'.format(or
- 00000030: 64 28 57 29 29 66 6f 72 09 57 09 69 6e 09 53 5d d(W))for.W.in.S]
- 00000040: 29 29 0a 09 72 65 74 75 72 6e 09 4f 5b 31 3a 5d ))..return.O[1:]
- 00000050: 3d 3d 4f 5b 3a 2d 31 5d 23 56 5f 5f 5f 5f 5f 5f ==O[:-1]#V______
- 00000060: 5f 5f 5f 5f 5f 5f 5f 16 16 16 16 16 16 16 16 16 _______.........
- 00000070: 16 16 14 14 10 .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement