Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [ 1sp ] sP
- 0d # count = 0, sentinel
- ?
- [
- 0dd sp ss St # init flags (pairs, sandwich), clear table/tmp with push
- # Process string (note: arrives backwards)
- [
- # pairs
- d3R d3R # a b -> a b b a
- 27*+ d # -> index index b a
- ;t 1=P # set pairs if in table
- 1 lt:t st # delay add to table (with tmp) to avoid overlaps
- r # b a -> a b
- # sandwich
- 3Rd3R =S r # a b c -> b c (sandwich set if a = c)
- z 3<L # leave: last-char sentinel count
- ] dsLx
- s. # clear last-char
- lpls*++ # count += pair * sandwich + 0 (sentinel)
- 0 ? z 2<M # leave: sentinel count
- ] dsMx
- +p
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement