[48in24 Exercise] [04-02] Luhn

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 Luhn from Apr 02 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 Luhn
  • 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.

  • foldright (scala)
  • recursion (python, scala)
  • replace-reverse-enumerate (python)
  • reversed-for (python)
  • scrub-and-validate-first (go)
  • validate-as-you-go (go)
  • validate-scrub-foldright (scala)
  • validate-scrub-recursion (scala)

Track Statuses

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

For this exercise’s video, I currently have these solutions and taling points. If you know more or better versions of these, let me know.

  1. Swift: single pass using even/odd boolean
    Use guards and keep track of even/odd via bool

  2. Ruby: method chain with indexed map
    Use a chain of methods, including tap to short-circuit and map to transform

  3. Gleam: functional method chain with Result type
    Use the Result type to capture errors

  4. R: vectorized operation to only update even indices
    Use a vectorized operation to only double even indices

  5. Pharo: sanitize replace even characters
    Replace even characters in string, -9 is applied by taking sum

  6. Tcl: index into list for doubling
    Index into a list for the doubled digit value

I’ll port the exercise for Ballerina.

1 Like
  1. Accepting any valid Number characters
    and beeing flexible on the Space Separator - working thus also in parts of our world where 0…9 are not used.
1 Like