[48in24 Exercise] [01-23] Reverse String

As always, feedback is much appreciated! We’re especially looking for:

  1. Interesting approaches to show
  2. Things to discuss
  • In immutable languages, strings can be copied to a list to get a mutable copy.
  • Mutable data can be reversed in place via n/2 in place swaps.
  • The simple solution is to walk the string in reverse and write to a string builder/string/list.
  • The (generally slow) solution is to walk a string and do inserts.
  • The above two can also be done with string concatenation and building n strings.
1 Like

This week is gonna be so much fun! I’ve already found tons of great solutions using a wide variety of approaches (more suggestions are always welcome).

1 Like

It is pure envy talking, but featuring Ruby’s (and Gos) handling of unicode characters that have combining marks and accents vs other languages would be fun. :smile:

.

Do you have a particular solution that showcases this well? Ruby doesn’t have reverse string I think

For Go –

andrerfcsantos | bobahop | KellenWatt – All use rune slices and strings.Builder in various ways, but still fail to group ‘valid’ combining marks. But the solutions are clean and worth going through.

Kellydanma doesn’t use strings.Builder, but also only reverses code points, as the examples above.

FacundoDecena – Adds in a check to make sure that the Unicode marks are valid, and the reversal keeps the marks grouped correctly :smile: :tada:


Tested these out on the Go playground, against code I took from Rosetta code., so all props to the person who wrote up the Go examples there! :smile:

Used the Thai string “ผู้เขียนโปรแกรม”.

1 Like

Approaches for Reverse String on PowerShell.
Writing approaches is a lot more work than I expected :sweat_smile:

2 Likes

I’ve included this (runes vs graphemes) in my list of solutions. Thanks!

1 Like
1 Like
1 Like