Advertisement
Guest User

Untitled

a guest
Jun 15th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. S > -SS
  2. S > 0
  3. S > 1
  4.  
  5. S > SS-
  6. S > 0
  7. S > 1
  8.  
  9. Prefix notation: --01-0-01
  10. Parentheses: -(-01)(-0(-01))
  11. Convert: (01-)(0(01-)-)-
  12. Postfix notation: 01-001---
  13.  
  14. Input Output
  15. 1 1
  16. 0 0
  17. -01 01-
  18. -10 10-
  19. --01-0-01 01-001---
  20.  
  21. ,[[->++++<<+>]>[[-]<<[.[-]<]]>,]
  22.  
  23. ,[ Take input and start main loop
  24. [->++++<<+>] Push input, and compute 4*input
  25. >[ If 4*input is nonzero (and thus input is not @):
  26. [-]<< Zero out this cell and move to top of stack
  27. [.[-]<] Pop from stack and output until is reached
  28. ]
  29. >, Move pointer into the correct position. If input was @, the earlier > pushed onto the stack.
  30. ]
  31.  
  32. M!`-*.
  33. +m`^-(.*)¶(d.*)
  34. $1$2-
  35.  
  36. def p(s):x=next(s);yield from[x]*(x>"-")or[*p(s),*p(s),"-"]
  37.  
  38. >>> list(p(iter("--01-0-01")))
  39. ['0', '1', '-', '0', '0', '1', '-', '-', '-']
  40.  
  41. L+&-hbTsyM.-Btbytbhb
  42.  
  43. L+&-hbTsyM.-Btbytbhb
  44. L define a function y(b), that returns:
  45. -hbT remove the chars "10" from the first char b
  46. (T=10, and - will convert a number to a string)
  47. & if this gives the empty string (a falsy value)
  48. + hb then append b[0] to it and return it
  49. (so this will parse a digit 0 or 1 from the string)
  50. & otherwise (the first char is a -)
  51. ytb parse the first prefix expression from b[1:]
  52. (recursive call)
  53. .-Btb remove this parsed expression bifurcated from b[1:]
  54. this gives a tuple [b[1:], b[1:] without first expr]
  55. yM parse and convert an expression from each one
  56. s join the results
  57. + hb and append the b[0] (the minus) to it and return
  58.  
  59. ;
  60. -;
  61. +`¶(.+);(.+)
  62. $1$2-
  63. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement