[48in24 Exercise] [02-27] Acronym

This issue is a discussion for contributors to collaborate in getting ready to be featured in 48in24. Please refer to this forum topic for more info.


We will be featuring Acronym from Feb 27 onwards.

Staff jobs

These are things for Erik/Jeremy to do:

  • ☐ Check/update exercise in Problem Specifications
  • :ballot_box_with_check: Create + schedule video

Community jobs

For each track:

  • Implement Acronym
  • Add approaches (and an approaches introduction!) for each idiomatic or interesting/educational approach.
  • Add video walkthroughs (record yourself solving and digging deeper into the exercise).
  • Highlight up to 16 different featured exercises (coming soon)

Existing Approaches

You can use these as the basis for approaches on your own tracks. Feel free to copy/paste/reuse/rewrite/etc as you see fit! Maybe ask ChatGPT to translate to your programming language.

  • findallin (scala)
  • look-for-start-chars (c)
  • split (scala)

Track Statuses

You can see an overview of which tracks have implemented the exercise at the #48in24 implementation status page.

I’ll port for CoffeeScript, LFE, and Red.

There’s already a closed PR for Acronym at Add Acronym practice exercise by kephas · Pull Request #187 · exercism/lfe · GitHub.

Approaches for PowerShell PR.

2 Likes

Python approaches in process.

1 Like

Does anyone have any interesting solutions they want to share? I currently have:

  • Functional pipeline with built-in function to match words
  • Regex match with word boundary anchor
  • Regex match and iteration
  • Regex match on uppercased input
  • Regex split
  • Split using set
  • Iterate and keep track of previous char
  • Regex matching unicode letters (with optional marks)
  • Stack-based approach

Not sure if this overlaps with your categories, but this one is “Iterate using states”: glennj's solution for Acronym in Go on Exercism

1 Like

This is maybe a variant on “iterate and keep track of previous char”? It does a string replace, a split on space chars, and then selects the first char of a word by string index:

Jeff Parker’s Solution to Acronym

There is also a solution in Python that we are including in our approaches doc. It uses only re.sub(). It’s slower than any other, but different from the solutions that match and iterate. It does use a word boundary, so is probably a variant of “Regex match with word boundary anchor” It also uses a positive lookbehind for the _ characters. It does overfit, so might not be the best to feature:

import re

def abbreviate(to_abbreviate):
    pattern = re.compile(r"\B[a-z',]+|-| |[A-Z]{2}\b|[^A-Z'](?<=_)")
    
    return  re.sub(pattern, "", to_abbreviate).upper()
1 Like

That sounds goodf!

@BethanyG I’ve slightly tweaked your solution, just in case you’re interested:

import re

def abbreviate(words):
    return re.sub(r'(?<!_)\B[a-zA-Z\']+|[ ,\-_]', '', words.upper())

NICE! Wow. Thank you for shortening and simplifying that! I will use that one instead in the approach. :smile: I am always surprised by what small tweaks can do in regex (and often bewildered by how there are 10million ways to do something).

1 Like

Alright. I know this is obsessive, but I couldn’t help myself. This one uses character classes and avoids needing escapes by using double quotes:

re.sub(r"(?<!_)\B[\w']+|[\W_]", "", words.upper())

40 additional steps in the engine however (958 vs 915), as compared to:

  re.sub(r"(?<!_)\B[a-zA-Z']+|[  ,-_]", "", words.upper())

I really am going to stop now. Promise.

1 Like

But of course they match different things.

1 Like

Erlang and D are missing so I’ll work on those early next week.

Can’t edit the previous post so here’s Add acronym by BNAndras · Pull Request #233 · exercism/d · GitHub

1 Like