Determine if a string is collapsible: Difference between revisions
Content deleted Content added
Determine if a string is collapsible en FreeBASIC |
|||
Line 1,567: | Line 1,567: | ||
</pre> |
</pre> |
||
=={{header|Nim}}== |
|||
<lang Nim>import unicode, strformat |
|||
proc collapse(s: string) = |
|||
let original = s.toRunes |
|||
echo fmt"Original: length = {original.len}, string = «««{s}»»»" |
|||
var previous = Rune(0) |
|||
var collapsed: seq[Rune] |
|||
for rune in original: |
|||
if rune != previous: |
|||
collapsed.add(rune) |
|||
previous = rune |
|||
echo fmt"Collapsed: length = {collapsed.len}, string = «««{collapsed}»»»" |
|||
echo "" |
|||
const Strings = ["", |
|||
"\"If I were two-faced, would I be wearing this one?\" --- Abraham Lincoln ", |
|||
"..1111111111111111111111111111111111111111111111111111111111111117777888", |
|||
"I never give 'em hell, I just tell the truth, and they think it's hell. ", |
|||
" --- Harry S Truman ", |
|||
"The better the 4-wheel drive, the further you'll be from help when ya get stuck!", |
|||
"headmistressship", |
|||
"aardvark", |
|||
"😍😀🙌💃😍😍😍🙌",] |
|||
for s in Strings: |
|||
s.collapse()</lang> |
|||
{{out}} |
|||
<pre>Original: length = 0, string = «««»»» |
|||
Collapsed: length = 0, string = «««»»» |
|||
Original: length = 72, string = «««"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln »»» |
|||
Collapsed: length = 70, string = «««"If I were two-faced, would I be wearing this one?" - Abraham Lincoln »»» |
|||
Original: length = 72, string = «««..1111111111111111111111111111111111111111111111111111111111111117777888»»» |
|||
Collapsed: length = 4, string = «««.178»»» |
|||
Original: length = 72, string = «««I never give 'em hell, I just tell the truth, and they think it's hell. »»» |
|||
Collapsed: length = 69, string = «««I never give 'em hel, I just tel the truth, and they think it's hel. »»» |
|||
Original: length = 72, string = ««« --- Harry S Truman »»» |
|||
Collapsed: length = 17, string = ««« - Hary S Truman »»» |
|||
Original: length = 80, string = «««The better the 4-wheel drive, the further you'll be from help when ya get stuck!»»» |
|||
Collapsed: length = 77, string = «««The beter the 4-whel drive, the further you'l be from help when ya get stuck!»»» |
|||
Original: length = 16, string = «««headmistressship»»» |
|||
Collapsed: length = 14, string = «««headmistreship»»» |
|||
Original: length = 8, string = «««aardvark»»» |
|||
Collapsed: length = 7, string = «««ardvark»»» |
|||
Original: length = 8, string = «««😍😀🙌💃😍😍😍🙌»»» |
|||
Collapsed: length = 6, string = «««😍😀🙌💃😍🙌»»»</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |