Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- S > -SS
- S > 0
- S > 1
- S > SS-
- S > 0
- S > 1
- Prefix notation: --01-0-01
- Parentheses: -(-01)(-0(-01))
- Convert: (01-)(0(01-)-)-
- Postfix notation: 01-001---
- Input Output
- 1 1
- 0 0
- -01 01-
- -10 10-
- --01-0-01 01-001---
- ,[[->++++<<+>]>[[-]<<[.[-]<]]>,]
- ,[ Take input and start main loop
- [->++++<<+>] Push input, and compute 4*input
- >[ If 4*input is nonzero (and thus input is not @):
- [-]<< Zero out this cell and move to top of stack
- [.[-]<] Pop from stack and output until is reached
- ]
- >, Move pointer into the correct position. If input was @, the earlier > pushed onto the stack.
- ]
- M!`-*.
- +m`^-(.*)¶(d.*)
- $1$2-
- def p(s):x=next(s);yield from[x]*(x>"-")or[*p(s),*p(s),"-"]
- >>> list(p(iter("--01-0-01")))
- ['0', '1', '-', '0', '0', '1', '-', '-', '-']
- L+&-hbTsyM.-Btbytbhb
- L+&-hbTsyM.-Btbytbhb
- L define a function y(b), that returns:
- -hbT remove the chars "10" from the first char b
- (T=10, and - will convert a number to a string)
- & if this gives the empty string (a falsy value)
- + hb then append b[0] to it and return it
- (so this will parse a digit 0 or 1 from the string)
- & otherwise (the first char is a -)
- ytb parse the first prefix expression from b[1:]
- (recursive call)
- .-Btb remove this parsed expression bifurcated from b[1:]
- this gives a tuple [b[1:], b[1:] without first expr]
- yM parse and convert an expression from each one
- s join the results
- + hb and append the b[0] (the minus) to it and return
- ;
- -;
- ¶
- +`¶(.+);(.+)
- $1$2-
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement