g | x | w | all
Bytes Lang Time Link
018Japt P250720T133830ZShaggy
031Uiua250302T234037ZErikDaPa
099Swift 6250301T182706ZmacOSist
048AWK250228T215748Zxrs
026Pip240318T000610ZDLosc
016Thunno 2230729T174232ZThe Thon
01905AB1E170719T143041ZErik the
016Vyxal sr210524T173938Za stone
047Factor210524T180945Zchunes
044Zsh210120T174309Zpxeger
068Scala210122T174105Zuser
149C gcc210122T151558Zelechris
012Stax210121T215622Zrecursiv
034K ngn/k210121T214901Zcoltim
018Husk210120T115849ZRazetime
075R170719T143751ZGiuseppe
01805AB1E210120T204912ZMakonede
144C# .NET190820T154342Zcanttalk
043Pip190801T144338ZKenzie
058PHP160315T140034Zaross
053JavaScript160402T200354Zericw314
046vim160313T164610ZDoorknob
148Pylongolf2160402T181312Zuser4701
060bash / GNU coreutils160401T215119Zmeereeum
027IPOS non competing160401T150619ZDenker
096Python160313T172427Zmriklojn
134C#160316T141706ZGER
027MATL160313T123021ZLuis Men
093Lua160316T041612ZTrebuche
175Factor160316T000916Zcat
020Jelly160313T125200ZSp3000
085JavaScript160313T143715Zclamchow
076Bash + GNU coreutils160315T111538Zrexkogit
075Haskell160313T125359Zflawr
122Lua160315T093315ZKatenkyo
056JavaScript ES6160313T172926ZDowngoat
092PHP160314T014254ZJustin
081Python160314T152858Zshooqie
029Retina160313T121821ZAndreas
063JavaScript160313T164810Zjdidion
081PowerShell160314T013849ZMatt
043Ruby160313T162248ZAlex A.
032Perl160313T163704ZDoorknob
117Mathematica160313T155134Zmartin
055Julia160313T155459ZAlex A.
022CJam160313T143948ZNinjaBea
02805AB1E160313T121205ZAdnan
020Pyth160313T120846ZDenker

Japt -P, 18 bytes

v ¸k`Âç¡"`q¤ ËÎu

Try it

Uiua, 31 bytes

∵◇⊢▽¬⊸∊∩(⊜□⊸≠@ )"AND OR BY OF"⌵

Explanation:

∵◇⊢▽¬⊸∊∩(⊜□⊸≠@ )"AND OR BY OF"⌵
       ∩(⊜□⊸≠@ )"AND OR BY OF"⌵ => split both the input uppercased and list of ignored words
   ▽¬⊸∊                         => filter words not in the list of ignored words
∵◇⊢                             => take first letter of each word

Try this online!

Swift 6, 123 99 bytes

{String(($0+"").uppercased().split{$0<"!"}.filter{!$0.contains(/^(AND|O[RF]|BY)$/)}.map(\.first!))}

Ungolfed version:

func acronym(of string: String) -> String {
  // uppercase the string and split it by spaces
  // " " compares less than "!" -- we can use this to save a byte
  let words = string.uppercased().split { $0 < "!" }

  // remove extra words
  let filteredWords = words.filter { !$0.contains(/^(AND|O[RF]|BY)$/) }

  // get initial letters and join them
  return String(filteredWords.map(\.first!))
}

AWK, 48 bytes

{$0=toupper($0);printf$0~/^(AND|BY|OR|OF)/?_:$1}

Attempt This Online!

Pip, 26 bytes

@_M_N"OROFBYAND"CH4FNUCa^s

Takes the string as a command-line argument. Attempt This Online!

A version that takes each word as a separate command-line argument would be 24 bytes (replace a^s at the end with g). This might meet the spec, since the invocation would look something like:

pip.py acronym.pip United states of America

Try It Online!

Explanation

@_M_N"OROFBYAND"CH4FNUCa^s
                       a   ; Command-line argument
                     UC    ; Uppercase
                        ^s ; Split on spaces
                   FN      ; Filter, keeping elements for which this function is falsey:
     "OROFBYAND"           ;   Take that string
                CH4        ;   Chop it into 4 pieces: ["OR";"OF";"BY";"AND"]
   _N                      ;   Is the argument in that list?
  M                        ; Map this function to each remaining string:
@_                         ;   Get the first character
                           ; Join and autoprint (implicit)

Thunno 2, 16 bytes

RO“œẆḶuıdƓ“ROṗ€h

Try it online!

Explanation

RO“œẆḶuıdƓ“ROṗ€h  # Implicit input
RO                # Uppercase and split on spaces
  “œẆḶuıdƓ“       # Compressed string "and or by of"
           RO     # Uppercase and split on spaces
             ṗ    # Remove these words
              €h  # First character of each
                  # Implicit output

05AB1E, 19 bytes

lð¡“€ƒ€—€‹€‚“#K€нJu

Try it online!

A 21 byte version:

lð¡“€ƒ€—€‹€‚“#Kvy0èuJ

Try it online!

Vyxal sr, 20 16 bytes

-4 thanks to @Underslash.

⇧⌈«X⟩qḊ8ɖ⇩«⇧⌈Fvh

Try it Online!

⇧⌈«X⟩qḊ8ɖ⇩«⇧⌈Fvh    # Full program
⇧                   # Convert (implicit) input converted to uppercase...
 ⌈                  # Split on spaces
  «X⟩qḊ8ɖ⇩«⇧⌈       # Create the list ['OR', 'BY', 'OF', 'AND']
             F      # and remove those from the input.
              vh    # Replace each word with its first letter
                    # `s` flag: Concatenate the letters and print

Factor, 47 bytes

[ >upper R/ AND|OF|OR|BY|\B.| |/ ""re-replace ]

Try it online!

Zsh, 46 45 44 bytes

for i;printf ${${${i:u}:#(AND|OR|BY|OF)}[1]}

Try it online!

-1 thanks to @roblogic

Explanation:

for i;printf ${${${i:u}:#(AND|OR|BY|OF)}[1]}
for i;                                         # for each word in the input
                 ${i  }                        # take that word
                    :u                         # capitalised
                         (AND|OR|BY|OF)        # if it matches one of these words
               ${      :#              }       # replace it with an empty string
             ${                         [1]}   # take the first character
      printf                                   # and print with no newline

Scala, 68 bytes

_.toUpperCase.replaceAll("\\b(AND|OR|BY|OF) ?|(?<=\\b\\w)\\w+ ?","")

Try it online!

Not the most creative answer ever.

Without regex, 75 bytes

_.toUpperCase split " "filterNot Set("AND","OR","OF","BY")map(_(0))mkString

Scastie

C (gcc), 149 bytes

#define x*strcmp(c,
F(char*s){char*d,*c=s;while(*s)*s++|=32;for(s=c;c;c=!d?*s=0:d+1)d=index(c,32),d?*d=0:0,1 x"and")x"or")x"by")x"of")?*s++=*c^32:0;}

Try it online!

Very naive approach. Will try to optimize it further. My first priority was to create a working example in C as there was no C submission yet.

Edit: optimized it by replacing initial conversion to upper case with conversion to lower case (easier as space is no longer an exception). I replaced strcmp with a define and replaced a while loop with a for. I did some further small optimizations and am now out of ideas.

Thanks to ceiling cat for bringing it down even more!

Stax, 16 12 bytes

î♣}ïû┴N=a,╥Ç

Run and debug it

K (ngn/k), 34 bytes

{`c$-32+*'(" "\_x)^$`and`or`by`of}

Try it online!

Husk, 19 18 bytes

m←¤-w¨BYΘRΘF⁴ND¨ma

Try it online!

-1 byte from Dominic Van Essen.

R, 77 75 bytes

cat(substr(w<-toupper(scan(,'')),1,1)[!grepl('^(AND|OR|OF|BY)$',w)],sep='')

Try it online!

-1 byte thanks to Dominic van Essen changing the indexing.

Reads from stdin. Takes the words, converts them to uppercase, removes those that are excluded from acronyms, extracts the first character from each, and prints them to the stdout.

05AB1E, 18 bytes

lð¡“€ƒ€—€‹€‚“#K€нu

Try it online!

lð¡“€ƒ€—€‹€‚“#K€нu  # full program
                 u  # convert...
                н   # first character of...
               €    # each element of...
                    # implicit input...
l                   # in lowercase...
  ¡                 # split by...
 ð                  # spaces...
              K     # without any of the elements of...
   “€ƒ€—€‹€‚“       # "and or by of"...
             #      # split by spaces...
                 u  # to uppercase
                    # implicit output

C# .NET, 144 bytes

class P{static void Main(string[]a){foreach(var c in a[0].ToUpper().Split(' '))if(c!="OR"&c!="AND"&c!="BY"&c!="OF")System.Console.Write(c[0]);}}

Try Online

Pip, 43 bytes

a:UCq^sFi,#a{`(OR|OF|AND|BY)`~=a@i?xOa@i@0}

definitely golfable, but I'm still learning regex

explanation:

a:UCq^s                                     input toUpper, split on " "
       Fi,#a{                             } iterate over a
             `(OR|OF|AND|BY)`~=a@i?xOa@i@0  if not exact match, output first char of this word

Try it online!

PHP, 68 61 58 bytes

Uses ISO-8859-1 encoding.

for(;$w=$argv[++$x];)stripos(_AND_OR_BY_OF,$w)||print$w&ß;

Run like this (-d added for aesthetics only):

php -d error_reporting=30709 -r 'for(;$w=$argv[++$x];)stripos(_AND_OR_BY_OF,$w)||print$w&ß; echo"\n";' united states oF america

Ungolfed:

// Iterate over the CLI arguments (words).
for(;$w = $argv[++$x];)
    // Check if the word is one of the excluded words by substring index.
    // The check is case insensitive.
    stripos("_AND_OR_BY_OF", $w) ||
        // Print the word, converting to uppercase and getting only the
        // first char by using bitwise AND.
        print $w & "ß";

JavaScript, 80 72 55 53 bytes

Code

function a(t){t=t.toUpperCase();t=t.replace(/AND|OR|BY|OF|\B.| |/g,"");return t}

function a(t){return t.toUpperCase().replace(/AND|OR|BY|OF|\B.| |/g,"")}

I just read about arrow functions and realized I could shorten this up even more.

a=t=>t.toUpperCase().replace(/AND|OR|BY|OF|\B.| |/g,"")

According to this, you don't count the assignment in the length, so -2 bytes.

t=>t.toUpperCase().replace(/AND|OR|BY|OF|\B.| |/g,"")

This is my first golf, so it's not very good.

vim, 46

gUU:s/ /\r/g<cr>:g/\vAND|OR|OF|BY/d<cr>:%s/.\zs.*\n<cr>
gUU                      make line uppercase
:s/ /\r/g<cr>            replace all spaces with newlines
:g/\vAND|OR|OF|BY/d<cr>  remove unwanted words
:%s/.\zs.*\n<cr>         remove all non-initial characters and newlines

I particularly like that last bit. The first . in the regex matches the first character of the line. Then we use \zs to start the "actually-being-replaced" part, effectively not replacing the initial character. .* matches the rest of the line, and \n matches the trailing newline. Since we don't specify a replace string, vim simply removes everything in the match, leaving only initials.

Pylongolf2, 14 bytes (UTF-8)

c| l1╨3♀~

Pylongolf2 has many non-ASCII characters that count as 2 bytes.

c| l1╨3♀~
c         read input
 |        split by space (note the space after |)
   l1     substring(0, 1)
     ╨3   convert to uppercase
       ♀~ pop the array into the stack and print it.

bash / GNU coreutils, 60 bytes

sed -e's/\b'{and,o[rf],by}'\W*//Ig' -re's/(\w)\S* ?/\u\1/g'

IPOS - non competing, 27 bytes

uS`"AND|OR|BY|OF"ER`%S!h%S-

This works in the current version (v0.2) of the interpreter.

Example run

python IPOS.py -i "United States of America" uS`\"AND|OR|BY|OF\"ER`%S!h%S-
USA

The backslashes there are only for escaping of the quotes and are not needed for the program.

Explanation

u                  # Make the input uppercase
S                  # Push a space to the stack
`"AND|OR|BY|OF"ER` # Push a command to the stack, that replaces matches of the regex
                   # with an empty string
%                  # Split the uppercased input string on spaces, apply the command and
                   # join back on spaces. This removes the required words from the input.
S                  # Push a space to the stack
!h                 # Push a command that only selects the first character of a string
%                  # Split on spaces, apply the command and join back on spaces
S-                 # Remove the remaining spaces (forgot to make this usuable
                   # with regexes, would have saved me some bytes here :( )

Python, 103 96 bytes

This is my first attempt at code golf, and this could probably be golfed a lot more. Thanks to DenkerAffe for saving seven characters.

lambda x:"".join([x[0]for y in x.split(" ") if y.lower() not in ['and','or','of','by']]).upper()

It takes the input, turns it into a list of words and takes their first letter if it's not one of the forbidden words, then turns everything to uppercase.

C#, 134 bytes

Golfed

class P{static void Main(string[] a){foreach (var s in a){if(!"AND OR BY OF".Contains(s.ToUpper())){Console.Write(s.ToUpper()[0]);}}}}

Readable

class P
{
    static void Main(string[] a)
    {
        foreach (var s in a)
        {
            if (!"AND OR BY OF".Contains(s.ToUpper()))
            {
                Console.Write(s.ToUpper()[0]);
            }
        }
    }
}

Execute from command line

75448.exe Light Amplification by Stimulation of Emitted Radiation

LASER

75448.exe united states of america

USA

MATL, 34 27 bytes

1 byte fewer thanks to @AandN

KkYb'OF AND OR BY'YbX-c1Z)!

Try it online!

Xk                  % convert to uppercase
Yb                  % split by spaces. Gives a cell array of input words
'AND OR BY OF'      % ignored words separated by spaces
Yb                  % split by spaces. Gives a cell array of ignored words
X-                  % setdiff: remove ignored words (result is stable)
c                   % convert to 2D char array, padding words with spaces
1Z)                 % take first column
!                   % transpose into a row

Lua, 113 112 93 bytes

arg[1]:upper():gsub("%w+",function(w)io.write(("AND OR BY OF"):find(w)and""or w:sub(0,1))end)

Factor, 175 bytes

I learned a lot by writing this.

USING: strings ascii sets splitting kernel sequences math.ranges ;
>lower " " split [ { "and" "or" "by" "of" } in? not ] filter [ first dup [a,b] >string ] map "" join >upper 

As a word:

USING: strings ascii sets splitting kernel sequences math.ranges ;

: >initialism ( str -- str )
  >lower " " split                            ! string.lower.split(" ")
  [ { "and" "or" "by" "of" } in? not ] filter ! word in { } ?
  [ first dup [a,b] >string ]          map    ! word[0]
  "" join >upper ;                            ! "".join.upper

Unit tests:

USING: tools.test mk-initialism ;
IN: mk-initialism.tests

{ "LASER" } [ "Light Amplification by Stimulation of Emitted Radiation" >initialism ] unit-test
{ "USA"   } [ "United States OF Americaof" >initialism ]                              unit-test
{ "USA"   } [ "united states and america" >initialism ]                               unit-test
{ "JTW"   } [ "Jordan Of the World" >initialism ]                                     unit-test

Pass!

Jelly, 21 20 bytes

,“°ɲịĊs°gɗ»ṣ€⁶Œuḟ/Ḣ€

Try it online!

(-1 thanks to @Dennis.)

,“°ɲịĊs°gɗ»              Pair input with the string "OR OF by AND"
           ṣ€⁶           Split both by spaces
              Œu         Uppercase
                ḟ/       Reduce filter (removing ignored words from input)
                  Ḣ€     Keep first letters of remaining words

Jelly's dictionary is a bit weird in that it has AND in uppercase yet by in lowercase...

JavaScript, 104 85 bytes

Saved 19 bytes thanks to @Aplet123.

Splits the string by spaces then checks if it is the words of, or, and, or by. If it is, it ignores it, otherwise it takes the first letter of it. It then joins the array and makes the string uppercase.

a=_=>_.split` `.map(v=>/\b(o(f|r)|and|by)\b/i.test(v)?"":v[0]).join("").toUpperCase()

Ungolfed:

function a(_) {
       _ = _.split` `; //Split on spaces
       _ = _.map(function(v){return new RegExp("\b(o(f|r)|and|by)\b","i").test(v)}); //Check if the banned words are in the result
       _ = _.join(""); //Join it into a string
       _ = _.toUpperCase(); //Convert it to uppercase
};

Bash + GNU coreutils, 103 76 bytes

for i in ${@^^};do grep -qE '\b(AND|OR|BY|OF)\b'<<<$i||echo -n ${i:0:1};done

Run with

./codegolf.sh Light Amplification BY Stimulation of Emitted Radiationofo

either with single argument quoted or with multiple arguments.

(I distorted the last word to contain of).


60 bytes

Thanks to @manatwork.

for i in ${@^^};{ [[ $i = @(AND|OR|BY|OF) ]]||printf %c $i;}

Haskell, 100 99 98 82 75 bytes

I am quite sure it can be shortened a lot more as I still suck at using $,. etc. so I keep using () insted=)

Thanks @nimi for your help magic!

import Data.Char
w=words
x=[h!!0|h<-w$toUpper<$>x,notElem h$w"OF BY OR AND"]

Example:

*Main> a "united states by america"
"USA"

Lua, 122 Bytes

I would have love to use a pattern to get rid of the banned words, but sadly, lua isn't made to match groups of characters... So I had to use a for loop instead, which is much more expensive.

s=arg[1]for k,v in next,{"of","and","by","or"}do
s=s:gsub(v,"")end
print(s:gsub("(%a)%a+",string.upper):gsub("%s","").."")

Ungolfed

s=arg[1]                               -- initialise s with the argument
for k,v in next,{"of","and","by","or"} -- iterate over the array of banned words
do
    s=s:gsub(v,"")                     -- replace the occurences of v by 
end                                    --   an empty string
print(s:gsub("(%a)%a+",                -- replace words (separated by spaces)
              string.upper)            -- by their first letter capitalised
         :gsub("%s","")                -- replace spaces with empty strings
                       .."")           -- concatenate to prevent the number of 
                                       -- substitutions to be shown

JavaScript (ES6), 56 bytes

Saved a byte thanks to @edc65.

s=>s.toUpperCase().replace(/\B.| |(AND|O[RF]|BY)\b/g,"")

Explanation

The code is self explanatory, I'll just explain the regex:

\B.          // Matches any character (`.`), that's not the start of a word
|            // Matches spaces
|(...)\b     // Matches all the words that should be ignored

It removed all of these matched characers and uppercases the word

PHP, 92 bytes

First attempt at code golf.

foreach(explode(" ",str_replace(["AND","OR","BY","OF"],"",strtoupper($s)))as$x){echo$x[0];}

The variable $s is the phrase to be converted: $s = "United States of America".

Requires PHP 5.4 or above for short array syntax to work.

Python, 81 bytes

lambda s:''.join(c[0]for c in s.upper().split()if c not in'AND OF OR BY'.split())

Retina, 29 31 36 bytes

T`l`L
 |(AND|OR|BY|OF)\b|\B.

Intended newline at the end.

Thanks to Martin Büttner for saving 5 bytes

Try it online

T`l`L                  # Replace lowercase with uppercase
 |(AND|OR|BY|OF)\b|\B. # Regex match, it doesn't matter if we match 'AND' in SHAND
                       #   since the 'SH' will still become 'S' or am I missing something?
                       # Replace with nothing

JavaScript, 61 64 66 63 bytes

a=>a.toUpperCase().replace(/(AND|O[FR]|BY|(\w)\w+)( |$)/g,"$2")

It uses a Regular Expression to find get words that aren't from the list: and, or, of, by, and captures the first letter. It then capitalizes the resulting string of letters.

EDIT: 64 Bytes - Fixed for words start with of,or,by,and

EDIT: 66 Bytes - Fixed to check all words including last word.

EDIT: 63 Bytes - Saved 3 Bytes thanks to @edc65 and @Cyoce!

PowerShell, 81 Bytes

(-join($args[0].Split(" ")|?{$_-notmatch"^(and|or|by|of)$"}|%{$_[0]})).ToUpper()

Explanation

Split on the spaces creating an array. Drop the offending members. Pull the first character and join together. Use ToUpper() on the resulting string.

Ruby, 45 43 bytes

->s{s.upcase.scan(/\b(?!AND|OR|OF|BY)\S/)*''}

This is a lambda function that accepts a string and returns a string. To call it, assign it to a variable and do f.call(input).

It uses the same approach as my Julia answer, namely convert to uppercase, get matches of the regular expression \b(?!AND|OR|OF|BY)\S, and join into a string.

Try it here

Saved 2 bytes thanks to manatwork!

Perl, 32 bytes

say uc=~/\b(?!AND|OR|OF|BY)\S/g

+1 byte for the -n flag.

Algorithm stolen from @AlexA's Julia answer.

Mathematica, 132 117 bytes

ToUpperCase[First/@Characters@DeleteCases[StringDelete[StringSplit@#,"of"|"and"|"or"|"by",IgnoreCase->True],""]<>""]&

15 bytes saved thanks to @CatsAreFluffy.

Julia, 72 63 61 55 bytes

s->join(matchall(r"\b(?!AND|OR|OF|BY)\S",uppercase(s)))

This is an anonymous function that accepts a string and returns a string. To call it, assign it to a variable.

We convert the string to uppercase, select each match of the regular expression \b(?!AND|OR|OF|BY)\S as an array, and join it into a string.

Saved 8 bytes thanks to Dennis!

CJam, 28 24 22 bytes

qeuS/"AOBONRYFD"4/z-:c

Try it online. Thanks to Sp3000 for pointing out a bug and suggesting a fix, and to Dennis for saving 4 6(!) bytes.

Explanation

qeuS/  e# Convert the input to uppercase and split on spaces
"AOBONRYFD"4/z  e# Push the array of short words. See more below
-      e# Remove each short word from the input words
:c     e# Cast the remaining words to characters, which is a
       e# shorter way of taking the first letter

Dennis suggested this trick for shortening the word list: Splitting AOBONRYFD into chunks of four, we get

AOBO
NRYF
D

Transposing columns into rows with the z operator, we get the proper words!

05AB1E, 33 32 28 bytes

Code:

‘€ƒ€—€‚€‹‘ð¡)Uuð¡)vXyQO>iy¬?

Uses CP-1252 encoding.

Pyth, 25 21 20 bytes

shM-crz1dc4."@YK½¼

Try it here!

Thanks to @Jakube for saving one byte!

Explanation

shM-crz1dc4."@YK½¼  # z = input

     rz1               # convert input to uppercase
    c   d              # split input on spaces
         c4."@YK½¼     # create a list of the words from a packed string which shall be ignored
   -                   # filter those words out
 hM                    # only take the first letter of all words
s                      # join them into one string

The packed string becomes ANDBYOROF