Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs

Dashboard
Notifications
Mark all as read
Challenges

Abbreviate everything

+3
−0

Challenge

Make a program that takes input of a string and abbreviate it.

  • All letters of an abbreviation are capitalized, so keep that in mind.
  • Whitespace, numbers and non-English characters are ignored.
  • If the inputted string is a paragraph (2+ sentences), the abbreviation will be split by spaces ( ) where ., ? or ! are, while commas (,) are ignored in this splitting scenario.
  • Words that are connected by hyphens (-) will result to only one letter.
  • The only non-alphabetical characters to remain in the result are colons (:) and semicolons (;).
  • This is code-golf, so shortest program in each language wins.

Test Cases

// Input
# Output

Hello, World!
HW

Can you make me a sandwich?
CYMMAS

hyper-neutrino
H

Too long; didn't read
TL;DR

I studied, don't worry. I will pass.
ISDW IWP

What???!?!
W

Get me 99 bottles of beer, bro!
GMBOBB
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

3 answers

+3
−0

Python 3, 142 bytes

def f(s):
	m=1;r=""
	for c in s.upper():
		if'@'<c<'['or'-'==c:r+=c*m;m=0
		if c in":; ":r+=c*(c!=' ');m=1
		if c in".?!":r+=' ';m=1
	return r

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

Haskell, 139 138 bytes

import Data.Char
f(a:b)|d a=toUpper a:f(dropWhile(\a->e a"-'"||d a)b)|e a":;"=a:c|e a".?!"=' ':c|0<1=c where c=f b;d=isLetter;e=elem
f a=a

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

+2
−0

JavaScript (Node.js), 91 68 65 bytes

s=>s.toUpperCase().match(/(?<=^| )[A-Z]|:|;|(?<=[.?!]) /g).join``

Assumes that the original text is properly formatted (has a space after punctuation). It converts the string to uppercase, then matches the following:

  • A letter at the beginning of the string or preceded by a space
  • : or ;
  • A space preceded by ., ?, or !

Try it online!

Why does this post require moderator attention?
You might want to add some details to your flag.

0 comment threads

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!