to-report split [ string ] ;; utility reporter to split a string into a list report n-values length string [ [ n ] -> item n string ] end to-report squeeze [ character string ] ;; reporter that actually does the squeeze function ;; remote immeadiately repeating instances of character from string ifelse ( string = "" ) [ report "" ] ;; empty input, report empty output [ report reduce [ [ a b ] -> ( word a ifelse-value b = character and b = last a [ "" ] [ b ] ) ] split string ] end to-report bracket [ string ] ;; utility reporter to enclose a string in brackets report ( word "<<<" string ">>>" ) end to-report format [ string ] ;; utility reporter to format the output as required report ( word bracket string " " length string ) end to demo-squeeze [ character string ] ;; procedure to display the required output output-print bracket character output-print format string output-print format squeeze character string end to demo ;; procedure to perform the test cases demo-squeeze " " "" demo-squeeze "-" "\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln " demo-squeeze "7" "..1111111111111111111111111111111111111111111111111111111111111117777888" demo-squeeze "." "I never give 'em hell, I just tell the truth, and they think it's hell. " demo-squeeze " " " --- Harry S Truman " demo-squeeze "-" " --- Harry S Truman " demo-squeeze "r" " --- Harry S Truman " end