[Question]
  [
# Objective
Your goal is to make a program that converts an input to its acronym. Your input is guaranteed to have only letters and spaces. The input will have exactly one space between words. You must output the acronym of the input.
# Rules
* Your code cannot be case-sensitive(e.g. `foo` and `Foo` are the same)
* Your code must ignore the following words and not put them in the acronym:
`and or by of`
* You **cannot** assume that the words are all lowercase.
* The output must be entirely capitalised, with no separation between characters.
* A trailing newline is accepted but not necessary.
* If your language has an acronym function builtin, you may **not** use it.
## Examples
(inputs/outputs grouped) 
```
United States of America
USA
Light Amplification by Stimulation of Emitted Radiation
LASER
united states of america
USA
Jordan Of the World
JTW
```
# Scoring
This is a [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") challenge so the shortest code wins.
# Leaderboard
```
var QUESTION_ID=75448,OVERRIDE_USER=8478;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentUrl(e,s){return"https://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
```
```
body{text-align:left!important}#answer-list,#language-list{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
```
```
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>
```
  
[Answer]
# Pyth, ~~25~~ ~~21~~ 20 bytes
```
shM-crz1dc4."@YK½¼
```
[Try it here!](http://pyth.herokuapp.com/?code=shM-crz1dc4.%22%40YK%19%17%C2%BD%C2%BC&input=United+States+of+America&test_suite=1&test_suite_input=United+States+of+America%0ALight+Amplification+by+Stimulation+of+Emitted+Radiation%0Aunited+states+of+america&debug=0)
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`
[Answer]
## [Jelly](https://github.com/DennisMitchell/jelly), ~~21~~ [20 bytes](https://github.com/DennisMitchell/jelly/blob/master/docs/code-page.md)
```
,“°ɲịĊs°gɗ»ṣ€⁶Œuḟ/Ḣ€
```
[Try it online!](http://jelly.tryitonline.net/#code=LOKAnMKwybLhu4vEinPCsGfJl8K74bmj4oKs4oG2xZJ14bifL-G4ouKCrA&input=&args=byBieXBhc3MgYSBsYXlieSBhbmQgdGFrZSBhbiBhbnRpIGJ5IGNha2U)
*(-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...
[Answer]
## Retina, 29 ~~31~~ ~~36~~ bytes
```
T`l`L
 |(AND|OR|BY|OF)\b|\B.
```
Intended newline at the end. 
Thanks to [Martin Büttner](https://codegolf.stackexchange.com/users/8478/martin-b%C3%BCttner) for saving 5 bytes
[Try it online](http://retina.tryitonline.net/#code=VGBsYEwKIHwoQU5EfE9SfEJZfE9GKVxifFxCLgo&input=TGlnaHQgQW1wbGlmaWNhdGlvbiBieSAgIFN0aW11bGF0aW9uIG9mIEVtaXR0ZWQgUmFkaWF0aW9u)
```
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
```
[Answer]
## 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.
[Answer]
# 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
[Answer]
# 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](https://codegolf.stackexchange.com/users/21348/edc65) and [@Cyoce](https://codegolf.stackexchange.com/users/41042/cyoce)!
[Answer]
# CJam, ~~28~~ ~~24~~ 22 bytes
```
qeuS/"AOBONRYFD"4/z-:c
```
[Try it online](http://cjam.aditsu.net/#code=qeuS%2F%22AOBONRYFD%224%2Fz-%3Ac&input=Light%20Amplification%20by%20Stimulation%20of%20Emitted%20Radiation). 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!
[Answer]
# 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!
[Answer]
## 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](https://codegolf.stackexchange.com/a/75463/3808).
[Answer]
# 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](https://codegolf.stackexchange.com/a/75463/20469), namely convert to uppercase, get matches of the regular expression `\b(?!AND|OR|OF|BY)\S`, and join into a string.
[Try it here](https://repl.it/BviG/1)
Saved 2 bytes thanks to manatwork!
[Answer]
## Python, 81 bytes
```
lambda s:''.join(c[0]for c in s.upper().split()if c not in'AND OF OR BY'.split())
```
[Answer]
# 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.
[Answer]
# 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;}
```
[Answer]
# 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
};
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), ~~34~~ 27 bytes
*1 byte fewer thanks to @AandN*
```
KkYb'OF AND OR BY'YbX-c1Z)!
```
[**Try it online!**](http://matl.tryitonline.net/#code=WGtZYidPRiBBTkQgT1IgQlknWWJYLWMxWikh&input=J1VuaXRlZCBTdGF0ZXMgT2YgQW1lcmljYSc)
```
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
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), ~~33~~ ~~32~~ 28 bytes
Code:
```
‘€ƒ€—€‚€‹‘ð¡)Uuð¡)vXyQO>iy¬?
```
Uses **CP-1252** encoding.
[Answer]
# 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"
```
[Answer]
# 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.
[Answer]
# 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](http://meta.codegolf.stackexchange.com/questions/6915/how-do-we-calculate-the-length-of-lambda), 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.
[Answer]
# 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 & "ß";
```
* Saved 7 bytes by using bitwise AND instead of using `ucwords`.
* Saved 3 bytes by using ISO-8859-1 encoding and using `ß` (binary `11011111`) for binary `AND` instead of a negated space (binary `00100000`).
[Answer]
# [R](https://www.r-project.org/), ~~77~~ 75 bytes
```
cat(substr(w<-toupper(scan(,'')),1,1)[!grepl('^(AND|OR|OF|BY)$',w)],sep='')
```
[Try it online!](https://tio.run/##DcrBCsIwDADQX6kgNIV42F0Pinh04G0MhdhFGWhXkpRd@u/Vd37SWiQDLU81gXW/s6XkzAIaKQF6HwJ22IVx8xbOH/APOF7Ptb/V/lJPQ9h6XMMdlfPhf1tJs/Hk1MhY3fJylCZHX5Y5UvsB "R – Try It Online")
-1 byte thanks to [Dominic van Essen](https://codegolf.stackexchange.com/users/95126/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.
[Answer]
# [K (ngn/k)](https://bitbucket.org/ngn/k), 34 bytes
```
{`c$-32+*'(" "\_x)^$`and`or`by`of}
```
[Try it online!](https://tio.run/##PYzLCsIwFER/5RIKWqUb3enKhRsRBEXciCZtkvZiHpLegkX89hgtdDkzZ86jcLWLUa/evMqK5WI@m0wZsOv9ld8yLpzkPvCy515/ok7T2SEpCScSpFrwGjZWBawEW7M91g2l/DSoU0PoHZR9QtF2ZoiJ31qkn@EoJP7L9OwGaTtKxSjd@SCFg4MGahRcfDCS5fEL "K (ngn/k) – Try It Online")
* `_x` lowercase the input
* `(" "\...)` split input on spaces
* `(...)^$`and`or`by`of` remove and/or/by/of
* `*'` take the first character of each remaining word
* ``c$-32+` convert to uppercase
[Answer]
# Mathematica, ~~132~~ 117 bytes
```
ToUpperCase[First/@Characters@DeleteCases[StringDelete[StringSplit@#,"of"|"and"|"or"|"by",IgnoreCase->True],""]<>""]&
```
15 bytes saved thanks to @CatsAreFluffy.
[Answer]
# 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.
[Answer]
## 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
```
[Answer]
# 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!
[Answer]
# 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)
```
[Answer]
# 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
> 
> 
> 
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~19~~ 18 bytes
```
m←¤-w¨BYΘRΘF⁴ND¨ma
```
[Try it online!](https://tio.run/##ATcAyP9odXNr//9t4oaQwqQtd8KoQlnOmFLOmEbigbRORMKobWH///9Kb3JkYW4gT2YgdGhlIFdvcmxk "Husk – Try It Online")
-1 byte from Dominic Van Essen.
[Answer]
# [Stax](https://github.com/tomtheisen/stax), ~~16~~ 12 [bytes](https://github.com/tomtheisen/stax/blob/master/docs/packed.md#packed-stax)
```
î♣}ïû┴N=a,╥Ç
```
[Run and debug it](https://staxlang.xyz/#p=8c057d8b96c14e3d612cd280&i=United+States+of+America%0ALight+Amplification+by+Stimulation+of+Emitted+Radiation%0Aunited+states+of+america%0AJordan+Of+the+World&m=2)
]