: bisect-slice ( a -- b c ) dup length 2 /i cut-slice ; DEFER: chop : check-right ( seq int -- int ) swap [ drop -1 ] [ swap [ dup first ] dip [ <=> ] keep swap { { +gt+ [ drop drop -1 ] } { +lt+ [ [ rest-slice ] dip chop ] } [ drop drop from>> ] } case ] if-empty ; : chop ( seq int -- int ) [ bisect-slice ] dip [ check-right ] keep swap dup -1 = not [ 2nip ] [ drop swap [ drop -1 ] [ swap chop ] if-empty ] if ;