A comment I made in chat and the ensuing conversation inspired me to make this challenge.
Am I the only one referred to by initials around here? We are all about golfing things down. We can have MB and D-nob and ... O.
If I'm known as "CH" then I think everyone else ought to have an initial-based nickname as well.
Here's a list of the top 100 Programming Puzzles & Code Golf users by reputation to play with:
Martin Büttner
Doorknob
Peter Taylor
Howard
marinus
Dennis
DigitalTrauma
David Carraher
primo
squeamish ossifrage
Keith Randall
Ilmari Karonen
Quincunx
Optimizer
grc
Calvin's Hobbies
ugoren
Mig
gnibbler
Sp3000
aditsu
histocrat
Ventero
xnor
mniip
Geobits
J B
Joe Z.
Gareth
Jan Dvorak
isaacg
edc65
Victor
steveverrill
feersum
ace
Danko Durbić
xfix
PhiNotPi
user23013
manatwork
es1024
Joey
daniero
boothby
nneonneo
Joey Adams
Timwi
FireFly
dansalmo
grovesNL
breadbox
Timtech
Flonk
algorithmshark
Johannes Kuhn
Yimin Rong
copy
belisarius
professorfish
Ypnypn
trichoplax
Darren Stone
Riot
ProgramFOX
TheDoctor
swish
minitech
Jason C
Tobia
Falko
PleaseStand
VisioN
leftaroundabout
alephalpha
FUZxxl
Peter Olson
Eelvex
marcog
MichaelT
w0lf
Ell
Kyle Kanos
qwr
flawr
James_pic
MtnViewMark
cjfaure
hammar
bitpwner
Heiko Oberdiek
proud haskeller
dan04
plannapus
Mr Lister
randomra
AShelly
ɐɔıʇǝɥʇuʎs
Alexandru
user unknown
Challenge
Write a program or function that takes in a list of strings and outputs another list of strings of their minimal, unique, initial-based nicknames, giving preference to those closer to the start of the list.
Apply this method to each string S in the list in the order given to create the nicknames:
- Split S up into words separated by spaces, removing all spaces in the process.
- List the nonempty prefixes of the string of the first letters of the words in S, from shortest to longest.
e.g.Just Some Name
→J
,JS
,JSN
- Choose the first item in this list that is not identical to an already chosen nickname as the nickname for S. Stop if a nickname was chosen, continue to step 4 otherwise.
e.g. ifJust Some Name
was the first string thenJ
is guaranteed to be the nickname. - List the prefixes again, but this time include the second letter of the first word in it's natural place.
e.g.Just Some Name
→Ju
,JuS
,JuSN
- Do the same as in step 3 for this list, stopping if a unique nickname is found.
- Repeat this process with the remaining letters of the first word, eventually inserting letters into the second word, then the third, and so on, until a unique nickname is found.
e.g. The first unique string listed here will be the nickname:
Jus
,JusS
,JusSN
Just
,JustS
,JustSN
Just
,JustSo
,JustSoN
(note thato
was not added afterJust
)
Just
,JustSom
,JustSomN
Just
,JustSome
,JustSomeN
Just
,JustSome
,JustSomeNa
Just
,JustSome
,JustSomeNam
Just
,JustSome
,JustSomeName
In the end all the input strings should end up with a unique nickname (potentially identical to the string). You may assume that none of the input strings will map to the same nickname using this method.
Example
Updated to fix my mistake!
For the input
Martin Buttner
Doorknob
Peter Taylor
Howard
marinus
Dennis
DigitalTrauma
David Carraher
Martin Bitter
Martin Butter
Martin Battle
Martini Beer
Mart Beer
Mars Bar
Mars Barn
the nicknames would be
M
D
P
H
m
De
Di
DC
MB
Ma
MaB
Mar
MarB
Mars
MarsB
Details
- Input can be from a file (one name per line), or one name at a time via stdin/command line, or as a function argument of a list of strings, or as a function arg of a single string with newlines between names.
- Output should be printed to stdout (one nickname per line) or returned by the function as a list of strings, or as one string with newlines between nicknames.
- Ideally programs will work for names that contain any characters except line terminators. However, you may assume that all the names only contain printable ASCII. (The PPCG names don't.)
- Only the regular space character counts as a word separator. Leading and trailing spaces can be ignored.
Scoring
The shortest submission in bytes wins. Tiebreaker goes to the answer posted earliest.