The TransCompilator

Solved LeetCode program · 831 of 1,000

#1096 · Brace Expansion II

Hard String chunk-17.md

Original English source

Keep a shared current as empty text. Keep a shared pending as an empty list of text. Keep a shared finished as an empty list of text. Keep a shared pool as an empty list of text. Keep a shared prefix as empty text. Keep a shared suffix as empty text. Keep a shared inside as empty text. Keep a shared option as empty text. Keep a shared open of 0. Keep a shared close of 0. Keep a shared total of 0. Keep a shared order of 0. Keep a shared same of 0. Keep a shared candidate as empty text.

To uncover. Set open to -1. The place is 0. The last is the last position of current.
Repeat while place is at most last and open is less than 0.
The symbol is the slice of current from place to place plus 1. If symbol matches "{", set open to place. Add 1 to place.

To enclose. Set close to -1. The depth is 0. The walk is 0. The last is the last position of current.
Repeat while walk is at most last and close is less than 0.
The symbol is the slice of current from walk to walk plus 1. If symbol matches "{", add 1 to depth. If symbol matches "}", subtract 1 from depth. The closing is 0. If symbol matches "}", set closing to 1. If closing is 1 and depth is 0, set close to walk. Add 1 to walk.

To extend. The parts is a list of prefix, option, and suffix. The combined is join parts with "". Place combined into pending. Add 1 to total.

To expand inside. The start is 0. The level is 0. The spot is 0. The last is the last position of inside.
Repeat while spot is at most last.
The symbol is the slice of inside from spot to spot plus 1. If symbol matches "{", add 1 to level. If symbol matches "}", subtract 1 from level. The comma is 0. If symbol matches ",", set comma to 1. If comma is 1 and level is 0, The mark is spot, The piece is the slice of inside from start to mark, Set option to piece, Extend, Set start to spot plus 1. If spot is last, The finish is spot plus 1, The piece is the slice of inside from start to finish, Set option to piece, Extend. Add 1 to spot.

To search. Set same to 0. The spot is 0. The last is the last position of pool.
Repeat while spot is at most last and same is 0.
The other is item spot of pool. If other matches candidate, set same to 1. Add 1 to spot.

To compare from left (a whole number) with right (a whole number). Set order to 0. The first is item left of pool. The second is item right of pool. The firstsize is the length of first. The secondsize is the length of second. The span is firstsize. If secondsize is less than span, set span to secondsize.
For every spot from 0 to span minus 1.
The firstsymbol is character spot of first. The secondsymbol is character spot of second. If order is 0 and firstsymbol is less than secondsymbol, set order to -1. If order is 0 and firstsymbol is more than secondsymbol, set order to 1. If order is 0 and firstsize is less than secondsize, set order to -1. If order is 0 and firstsize is more than secondsize, set order to 1.

The source is "{a,b}{c,{d,e}}". Set current to a copy of source. The seed is a copy of source. Place seed into pending. Set total to 1. The front is 0.
Repeat while front is less than total.
The chosen is item front of pending. The next is a copy of chosen. Set current to a copy of next. Add 1 to front. Uncover. If open is less than 0, Place current into finished. If open is at least 0, Enclose. If open is at least 0, Set prefix to the slice of current from 0 to open. If open is at least 0, The begin is open plus 1, Set inside to the slice of current from begin to close. If open is at least 0, The tail is close plus 1, The end is the last position of current, The final is end plus 1, Set suffix to the slice of current from tail to final. If open is at least 0, Expand inside.

For every spot from 0 to the last position of finished.
The piece is item spot of finished. Set candidate to a copy of piece. Search. If same is 0, Place candidate into pool.

The lastpool is the last position of pool.
For every spot from 0 to lastpool minus 1.
For every probe from spot plus 1 to lastpool.
Compare from spot with probe. If order is more than 0, swap item spot of pool and item probe of pool.

For each piece in pool, show piece.

Open in Playground Browse all 1,000 problems

Expected stdout

ac
ad
ae
bc
bd
be