ludus

Name Shortening

ld-0010 · 6 › ██████░░░░ · text, arrays · requires: arrays, lambda · oner lambdaless generalized golfed

Your client has a list of first and last names. They want to shorten them as much as possible, but keep enough characters that similar names stay distinguishable.

The method: first names are never changed. A person's last name is compared only against the last names of people who share their first name — keep the shortest prefix of the last name that differs from every one of those other last names' equal-length prefixes. If one character is enough (or the first name is unique in the list), keep just the last initial followed by a period.

For example — Emily Johnson, Emily Jones, Emily Doe, and John Jones become Emily Joh, Emily Jon, Emily D., and John J.

No two people share both a first and a last name. Produce the shortened full name for each person, one row per input row. The grader swaps in name lists of different lengths, so cover the whole OUTPUT range: empty input rows must produce empty output rows.

Work on it

  1. Make a copy of the template — it becomes your private sheet.
  2. Solve it however you like — helper columns and extra tabs are fair game. The one rule: the grader swaps INPUT for other datasets, so never put your own content inside INPUT.
  3. Check yourself against the expected sample output shown in your copy (and below).
  4. Submit below — Share → "anyone with the link, Viewer", paste the link. Your sheet is graded against 3 hidden datasets, so hardcoded answers won't survive.

Sample

Input (Input!B2:C34)

FirstLast
EmilyJohnson
EmilyJones
EmilyDoe
JohnJones
MariaSilva
KenjiSato
PriyaPatel
JohnJackson

Expected output (Answer!B3:B34)

Shortened
Emily Joh
Emily Jon
Emily D.
John Jo
Maria S.
Kenji S.
Priya P.
John Ja

Adapted from "Name Shortening" in the astral.cafe Community Practice Problems sheet.