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

It would be nice if they are implemented in every track. But I don’t think that is a requirement. It would be nice to have approaches and videos, but I suspect that isn’t going to happen for a decent number.

I would have to defer to @iHiD and @ErikSchierboom for all of the details, but my understanding is that the goal is to get as many of the featured exercises implemented across all tracks as possible, and have as many approaches articles as possible completed for them.

There will be videos for each featured exercise where iHiD and Erik discuss strategies and programming language choices, but the hope is that there will also be video walkthroughs contributed by the community.

But its not “do or die” – more an inspiration or strong encouragement to get some content filled in, and some new contributors on board.

Thanks for the reply!
That make a lot more sense I suppose, cuz I look at the date and it seem like a short time to do all of that for all of the tracks.
Also, would it be possible to get the full list of the 48 exercises soon, or it is not possible because they need to be consider based on many factors so it will be a gradual thing like last year?

See Which exercises for #48in24? - #12 by ErikSchierboom

Note: Let’s try and keep these threads specific to the actual exercise in question and have general discussions on dedicated threads. Thanks! :slight_smile:

PRs made. I’ll take a look at porting the exercises for Ballerina, OCaml, and ReasonML and then write approaches and mentoring notes for Racket and Vim script.

1 Like

Just FYI in case somebody was planning to help by adding reverse-string to Elixir: don’t. @jiegillet and I chose not to implement it on purpose. See https://github.com/exercism/elixir/blob/8d74999e643302cd02057e32b51168f6d60e592c/config.json#L3008-L3015

If nobody else is already working on it, I’d like to do the approaches for the Clojure track.

1 Like

I can look into adding the reverse-string exercise to the Haskell track as I see that is missing currently.

1 Like

Awesome. Thanks!

1 Like

Discuss: null-terminated strings

C and assembly languages work with null-terminated strings. We can discuss:

  • This can be good for performance, as no additional length field needs to be stored in memory, but similarly it can be bad too as figuring out the length is O(N)
  • This is bad for memory safety, as it is easy to make a mistake and go beyond the length of a string

Discuss: in-place mutation vs copy

In some languages, strings a mutable, in other they’re not. The latter would require a copy to be made, whereas the former doesn’t.

We can discuss:

  • Why make strings immutable at all? (safety, ability for inlining)
  • Is there a performance difference (well yes, as copy involves allocating new memory)
  • Specialized string builders

This can also be bad for performance is what we’re performing involves figuring out the string length :grin:

1 Like

Discuss: bytes vs characters

Some languages treat strings as a sequence of characters (or make it appear as if they do), others do not, and they usually treat a string as a sequence (or array) of bytes.

We can discuss:

  • The trade-off. Why not always treat them as chars?
  • ASCII vs Unicode, why the former is more limited (only 128 chars for regular ASCII, 255 for extended ASCII)
  • UTF-8 encodes unicode, but uses variable bytes encoding (ASCII chars are one byte, but other character points could use up to four bytes)
  • Difference between rune (single unicode code point) vs graphemes (aka grapheme cluster, which is what you see or print on screen, can be multiple code points)
1 Like

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