text:
Draw the arc of a ball
Draw the parabolic trajectory of a thrown ball.
The input is the ball's initial upward velocity, a positive integer v. Every second, the ball moves 1 space right and v spaces vertically, and then v decreases by 1 to due to gravity. So, the upward velocity eventually steps down from v to 0 and down to -v, finally falling back down to its initial height.
The ball's positions trace a parabola. At horizontal position x, its height is y=x*(2*v+1-x)/2, with (0,0) the ball's initial position at the bottom left.
Output ASCII art of the ball's trajectory with O's on the coordinates it ever occupies. The output should be a single multi-line piece of text, not an animation of the path over time.
The output should have no leading newlines and at most one trailing newline.  The bottom line should be flush with the left edge of the screen, i.e. have no extra leading spaces. Trailing spaces are OK. You may assume the output line width fits in the output terminal.
v=1
 OO
O  O

v=2
  OO
 O  O

O    O

v=3
   OO
  O  O

 O    O

O      O

v=4
    OO
   O  O

  O    O

 O      O

O        O

v=10
          OO
         O  O

        O    O

       O      O

      O        O

     O          O

    O            O

   O              O

  O                O

 O                  O

O                    O

Related: Bouncing ball simulation

Leaderboard:

var QUESTION_ID=111861,OVERRIDE_USER=20260;function answersUrl(e){return"https://api.stackexchange.com/2.2/questions/111861/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="
"+e.body.replace(OVERRIDE_REG,"")+"
")});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;/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}
 <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b">

Leaderboard

	Author	Language	Size

Winners by Language

Language	User	Score

{{PLACE}}	{{NAME}}	{{LANGUAGE}}	{{SIZE}}	Link

{{LANGUAGE}}	{{NAME}}	{{SIZE}}	Link

Can we ouput a list of lines?

@Riker Nope, string with newlines.

loosely related: http://codegolf.stackexchange.com/q/110410

Do I only need to account for V > 0?

Yes, v will be positive.

Wow, middle-school-math-that-I-didn't-listen-to-that-much-so-I-don't-like-them-but-whatever-:P

Charcoal, 18 16 13 bytes
-3 bytes thanks to @Neil!
Ｆ⊕Ｎ«←OＭ⊕ι↓»‖Ｃ

Explanation
Ｆ⊕Ｎ«        »    For ι (implicitly from 0) to (1 + input as number)
       ←O          Print O, with print direction rotated 180 degrees
         Ｍ⊕ι↓     Move 1+ ι units down

                ‖Ｃ Reflect (in the default direction, right), leaving original intact

Try it online! Link is to verbose code.

I like this one a lot, +1; Also OP's output uses uppercase "O". (Not that it matters at all lol)

If you use ↘O then you can loop from 0 to N inclusive instead which saves you two bytes immediately.

@Neil Thanks! Also, this is a very old post :P (and I wonder if I should be using newer features. Probably not?)

Strictly speaking I've only saved you 1 byte so far as the other two bytes were you replacing ⁺¹ with ⊕. However now that you've moved the ← from the ‖Ｃ to the O you can save another byte by writing ↙OＭι↓, so I'm back up to a two byte saving again.

Also you forgot to update your TIO link. And technically I believe we now allow newer features, but I can't claim credit for those bytes.

C, 93 92
(Note, someone got to 87 in the comments)
y,n;f(s){for(y=0;y<=s;){printf("%*c%*c",s-y+1,79,y*2+1,79);for(n=++y;s+1-n&&n--;)puts("");}}

Try it online!

Readable:
y,n;f(s){
    for(y=0;y<=s;){
        printf("%*c%*c",s-y+1,79,y*2+1,79);
        for(n=++y;s+1-n&&n--;)puts("");
    }
}

Notes:
I can collapse both for loops into just one for loop by iterating the total number of lines outputted, which is given by the formula: n*-~n/2+1
y,n,r;f(s){
    for(r=s,y=n=0;r<s*-~s/2+1;)
        y==n?printf("%*c%*c",s-y+1,79,y*2+1,79),y=0,++n:r++,y++,puts("");
}

But it ends up being even more bytes than just using two seperate for-loops

You can save one byte by incrementing s at the beginning, like this: y,n;f(s){++s;for(y=0;y<s;){printf("%*c%*c",s-y,79,y*2+1,79);for(n=++y;s-n&&n--;)puts("");}}

@Steadybox won't compile for me. Also I got 90 bytes when I counted that (after removing whitespace characters)

All I did was adding the ++s; at the beginning and then changing y<=s to y<s and s-y+1 to s-y and s+1-n to s-n, so it should compile (and should be 91 bytes).

It seems that there is something wrong with the encoding of the code block in my comment. Copying and pasting the code from the comment won't compile for me either.

87 bytes

@ceilingcat Another great one, well done!

Python 2, 65 bytes
f=lambda n,x=0:(n and f(n-1,x+1)or'')+'\n'*n+' '*x+'O'+'  '*n+'O'

Try it online!

GNU sed, 41

Score includes +1 from -r flags to sed.

s/$/OO/
:
s/(\s*) O( *)O$/&\n\1O \2 O/
t

Input is in unary, as a string of spaces - the length of string is the input.
Try it online.

MATL, 19 17 bytes
Q:tqYsQ79Z?PtPv!c

Try it at MATL Online! Or verify all test cases.
Explanation
Q        % Implicitly input v. Add 1
:        % Push [1 2 ... v+1]
tq       % Duplicate and subtract 1: pushes [0 1 ... v]]
Ys       % Cumulative sum: gives [0 1 3 6 ...]
Q        % Add 1: gives [1 2 4 7 ...]
79       % Push 79 (ASCII for 'O')
Z?       % Create sparse matrix from column indices [1 2 3 4 ...],
         % row indices [1 2 4 7 ...], and data 79
P        % Flip vertically
tP       % Duplicate, flip vertically
v        % Concatenate the two matrices vertically
!        % Transpose
c        % Convert to char. Implicitly display. Char 0 is shown as space

05AB1E, 18 14 bytes
Saved 4 bytes thanks to Adnan
ƒ¶N×'ONúRÂJ}.c

Try it online!
Explanation
ƒ                   # for N in [0 ... input]
 ¶N×                # push N newlines
    'O              # push "O"
      Nú            # pad with N spaces in front
        RÂ          # reverese and create a reversed copy
          J         # join everything to a string
           }        # end loop
            .c      # pad lines until centered

For 14 bytes: ƒ¶N×'ONúRÂJ}.c :)

@Adnan Thanks! I tried .c with a different version, but it didn't work well then. Forgot about trying it with this one and complete forgot that ú exists :)

Definitely better than the zip method I chose, interesting approach vertically.

JavaScript (ES6), 98 92 89 84 78 bytes
(-20 bytes thanks to Arnauld!)
f=(v,i=0)=>i>v?"":" "[r="repeat"](v-i)+0+" "[r](2*i)+0+`
`[r](i++<v&&i)+f(v,i)

A recursive solution. This is also my first ever answer in JavaScript, so please be gentle! I am still learning all this neat language has to offer, so golfing tips are very much appreciated. :)
Test Snippet
You may need to scroll to see the entire output.

f=(v,i=0)=>i>v?"":" "[r="repeat"](v-i)+0+" "[r](2*i)+0+`
`[r](i++<v&&i)+f(v,i)
<input id=i min=1 type=number><button onclick=alert(f(document.getElementById("i").value))>Submit</button>

Also, including variables inside backtick strings with ${} only saves bytes when the variable part is surrounded by static parts. As such, these strings should always start and end with static parts.

@Arnauld Thanks for all the tips! I really appreciate it! :)

@Luke Thanks for the advice. That will come in handy. :)

You can safely use 0 instead of "0". They'll be coerced to strings. And on second thought: i++<v&&i is actually one byte shorter than (i<v)*++i.

@Arnauld Thank you once again! :)

My pleasure. Happy JS golfing!

Bash, 76 bytes
for((n=$1+1;--n;));{
yes ''|head -$n
r=$r›${n}AO
t=›${n}BO$t
}
echo O${r}O$t

Only works in a terminal since it uses ANSI escape sequences. › represents the CSI byte (0x9b).
Test run
$ # The terminal's encoding must be set to ISO-8859-1.
$
$ xxd -g 1 arc.sh
0000000: 66 6f 72 28 28 6e 3d 24 31 2b 31 3b 2d 2d 6e 3b  for((n=$1+1;--n;
0000010: 29 29 3b 7b 0a 79 65 73 20 27 27 7c 68 65 61 64  ));{.yes ''|head
0000020: 20 2d 24 6e 0a 72 3d 24 72 9b 24 7b 6e 7d 41 4f   -$n.r=$r.${n}AO
0000030: 0a 74 3d 9b 24 7b 6e 7d 42 4f 24 74 0a 7d 0a 65  .t=.${n}BO$t.}.e
0000040: 63 68 6f 20 4f 24 7b 72 7d 4f 24 74              cho O${r}O$t
$
$ bash arc.sh 1
 OO
O  O
$ bash arc.sh 2
  OO
 O  O

O    O
$ bash arc.sh 3
   OO
  O  O

 O    O

O      O
$ bash arc.sh 4
    OO
   O  O

  O    O

 O      O

O        O

You can use sed $nq to save a byte.

Sadly, no. I'd have to use sed ${n}q which is longer.

Argh, I see, you can do sed $n\q instead, but that does not make much sense either, as it would be the same byte count as head !

Suggest ((n=$1;n;--n)) for -1 byte

Python 2, 76 bytes
x=input()
for i in range(x):print' '*(x-i),'O'+' '*i*2+'O'+'\n'*(i-x+1and i)

Pretty simple. The i-x+1and i is to prevent a bunch of trailing newlines.

Moving the newline to the beginning of the print, like '\n'*(i-1)saves 7 bytes while avoiding the trailing newlines.

Retina, 35

2 bytes saved thanks to @MartinEnder

Port of my sed answer:
.+
$* OO
+`(\s*) (O *)O$
$&¶$1O $2 O

Try it online.

Retina, 29 19 bytes
 ?
$.`$*¶$&$'O$`$`O

Try it online!
Takes input in unary as a run of spaces. Port of my JavaScript answer. Edit: Saved 10 bytes thanks to @MartinEnder♦.

I´m only waiting for someone to come up with a Retina spin off called Retsina.

R, 89 bytes
a=2*v+3
x=matrix(" ",a,v^2+1)
for(k in 0:v)x[c(1-k,k+2)+v,k^2+1]="o"
x[a,]="\n"
cat(x,sep="")

Create a matrix of spaces (the variable a is the width of this matrix, saving a couple of bytes)
Fill in "o"s at the required locations, working from the top of the arc downwards and outwards
Add a newline at the end of each matrix row
Collapse the matrix down to a single string and print

This is my first attempt at golfing, comments welcome...

RProgN 2, 37 bytes
x=0xR{y@xy-` *`o` y2**`o...2y{[` };};

Getting in with my kind-of-golfy language before the proper golfy langauges jump in.
Explained
x=              # Set 'x' to the input
0xR{            # For everything between the input and 0
    y@          # Set the iteration value to y, for this function only.
    xy-` *      # Subtract y from x, repeat the string " " that many times.
    `o          # Push an "o" to the stack.
    ` y2**      # Push 2*y " "'s to the stack
    `o          # Push another "o" to the stack
    ...         # Concatenate the parts of this string together, giving us the two balls.
    2y{[` };    # For all numbers between 2 and y, add a newline.
};              #

Try it online!

Röda, 53 52 bytes
f n{seq 0,n|{|i|["
"*i," "*(n-i),"O"," "*i*2,"O"]}_}

Try it online!
Usage: main { f(5) }
Ungolfed version:
function f(n) {
    seq(0, n) | for i do
        push("\n"*i, " "*(n-i), "O", " "*i*2, "O")
    done
}

Can you use a literal newline instead of \n and save 1 byte?

@KritixiLithos That works. Thanks!

Befunge, 75 73 bytes
<vp00:&
1<-1_:v#\+55:g01\-g01g00" O"1\*2g01" O"1p0
#@_\:v>$$:!
1\,:\_^#:-

Try it online!
The first line reads in the velocity, v, and saves a copy in memory. The second line then counts down from v to zero, with the index i, and on each iteration pushes a sequence of character/length pairs onto the stack.
Length  Character
-----------------
1       'O'
i*2     ' '
1       'O'
v-i     ' '
i       LINEFEED

This sequence represents a kind of run-length encoding of the required output in reverse. The last two lines then simply pop these character/length pairs off the stack, outputting length occurrences of each character, until the stack is empty.

Java 8, 129 124 109 bytes
Golfed:
v->{String s="",t="";for(int j,y=0;y<=v;++y){for(j=0;j<v;++j)s+=j<y?"\n":" ";s+="o"+t+"o";t+="  ";}return s;}

Try it online!
Ungolfed:
public class DrawTheArcOfABall {

  public static void main(String[] args) {
    for (int i = 1; i < 6; ++i) {
      System.out.println(f(v -> {
        String s = "", t = "";
        for (int j, y = 0; y <= v; ++y) {
          for (j = 0; j < v; ++j) {
            s += (j < y ? "\n" : " ");
          }
          s += "o" + t + "o";
          t += "  ";
        }
        return s;
      } , i));
      System.out.println();
      System.out.println();
    }
  }

  private static String f(java.util.function.IntFunction<String> f, int v) {
    return f.apply(v);
  }
}

Try it online!

For the second nested for loop, I think for(;j<v;++) would work, because at this point in time j==y.  Also, you could remove the third by adding a second string variable inside the main for loop String t=""; (12) and t+="  "; (8) inside the first nested loop.  Then the third loop just becomes s+="o"+t+"o";

Also, you can combine the first two nested loops to for(j=0;j<v;++j)s+=j<y?"\n":" "; although I'm not sure how this meshes with my previous comment about t

You can initialize t="" alongside s in the beginning, and then add t+="  " each loop around after you do s+="o"+t+"o"

05AB1E, 18 13 bytes
ÝηROÂ«ð×'O«ζ»

Try it online!
Ý                # [0..n]
 €LRO            # [0.sum(), 0..1.sum(), ..., 0..n-1.sum(), 0..n.sum()]
     Â«          # Mirror image the array [0, 0..n.sum(), 0]
       ð×'O«     # Push that many spaces with an O appended to it.
            .B   # Pad small elements with spaces to equal largest element length.
              ø» # Transpose and print.

VBA, 124 112 85 88 66 63 59 bytes
For i=0To[A1]:?Space([A1]-i)"O"Space(2*i)"O"String(i,vbCr):Next

Saved 29 bytes in total thanks to Taylor Scott
This must be run the in VBA Immediate window and print the result in the same.
Expanded / Formatted, it becomes:
For i=0 To [A1]
   Debug.Print Space([A1]-i) & "O" & Space(2*i) & "O" & String(i,vbCr)
Next

(It turns out that concatenation in a print command is automatic without an operator.)

b & s & Spaces alert!

I tried and it erred the first time. Going back, I realized it'll expand b &s &String but not b&s&String. Also, at first I thought you meant to use the Space function which I totally should have and that ended up saving more bytes.

You can condense for i=0 To v and debug.? b to for i=0To v and Debug.?b, respectively for -2 bytes. And just so you know, the community consensus is that for languages with autoformatting, you may count before it is autoformatted, meaning after you make these changes you should have a byte count of 85 Bytes

On a second look, this is a snippet - not a function or subroutine; so it is not a valid solution. I believe that you could fix this by converting it an Excel VBA immediate window function and taking input from [A1] (v=[A1]) Also, I don't think you actually need the s variable.

@TaylorScott You're right on both points. I appreciate your continued efforts to improve the Excel and VBA answers on PPCG; I've learned much.

I did a bit of rearranging on what you made to squeeze some extra bytes out of if - give For i=0To[A1]:?Space([A1]-i)"O"Space(2*i)"O"String(i+1,vbCr):Next a try - 65 Bytes

@TaylorScott That seems like an obvious improvement in retrospect but I did not know that concatenation did not require an operator in the immediate window. That'll save me some bytes in the future. I did have to add a ; to the end of the print command, though, because it kept adding an extra line break by default. Thanks!

@EngineerToast I had not noticed that when golfing it down - but I think that you may actually be able to remove the +1 and ; in String(i+1,vbCr); in order to get to the correct number of linebreaks

@TaylorScott That should have been obvious, in retrospect.

@EngineerToast OH one last thing - I always forget this - convert the Space(...) calls to Spc(...) calls for -4 Bytes; Also in the autoformatted section of your answer the compiler adds ; after every non-terminal entry to the ? call

Haskell, 69 bytes
r=replicate
f n=[0..n]>>= \a->r a '\n'++r(n-a)' '++'O':r(2*a)' '++"O"

Usage example: f 3 -> "   OO\n  O  O\n\n O    O\n\n\nO      O". Try it online!.

MATLAB, 114 Bytes
function p(v),for i=0:v,fprintf([repmat(' ',1,v-i),'o',repmat(' ',1,2*i),'o',repmat('\n',1,(i*(i~=v)+1))]);end,end

ungolfed:
function p(v)
   for i=0:v
       fprintf([repmat(' ',1,v-i),'o',repmat(' ',1,2*i),'o',repmat('\n',1,(i*(i~=v)+1))]);
   end
end

Jelly, 17 16 bytes
‘Ḷ+\Ṛ⁶ẋ;€”Om0z⁶Y

Try it online!
How?
‘Ḷ+\Ṛ⁶ẋ;€”Om0z⁶Y - Main link: v         e.g. 3
‘                - increment: v+1            4
 Ḷ               - lowered range             [0,1,2,3]
  +\             - reduce with addition      [0,1,3,6]
    Ṛ            - reverse                   [6,3,1,0]
     ⁶           - a space                   ' '
      ẋ          - repeat (vectorises)       ['      ','   ',' ','']
       ;€        - concatenate each with
         ”O      -     an 'O'                ['      O','   O',' O','O']
           m0    - concatenate reflection    ['      O','   O',' O','O','O','O ','O   ','O      ']
             z⁶  - transpose with space fill ['   OO   ','  O  O  ','        ',' O    O ','        ','        ','O      O']
               Y - join with line feeds      ['   OO   \n  O  O  \n        \n O    O \n        \n        \nO      O']
                 - implicit print

JavaScript (ES6), 87 bytes

f=
n=>' '.repeat(n+1).replace(/./g,"$`#$'O$`$`O").replace(/ *#/g,s=>[...s].fill``.join`
`)
<input type=number min=0 oninput=o.textContent=f(+this.value)>

Nonrecursive solution. Indexing requirement was annoying, both in the above and the following 62-byte (I don't know whether it would result in a shorter Retina port) recursive solution:
f=n=>~n?` `.repeat(n)+`OO`+f(n-1).replace(/^ *O/gm,`
$&  `):``

PHP, 76 bytes
for(;$argn>=0;$s.="  ")echo($r=str_repeat)("
",$i++),$r(" ",$argn--),o,$s,o;

Run with echo <v> | php -nR '' or test it online.
loops $argn down from input to 0 and $i up from 0;
prints - in that order - in each iteration

$i newlines (none in the first iteration)
left padding: $argn spaces
left ball: o
inner padding: 2*$i spaces
right ball: o

V, 23 19 bytes
2éoÀñYço/^2á O
HPJ>

Try it online!
Explain
2éo            " Insert two 'o's
   Àñ          " <Arg> times repeat
     Y         " Yank the current (top) line.  This is always '\s*oo'
      ço/      " On every line that matches 'o'
         ^     " Go to the first non-whitespace character (the 'o')
          2á   " Append two spaces (between the two 'o's
             O " Add a blank line on top of the current one
H              " Go to the first line
 P             " Paste in front ('\s*oo')
  J            " Join this line with the blank line immediately after it
   >           " Indent once

Perl 5, 48 bytes
47 bytes code + 1 for -n.
$_++;print$/x$-,$"x$_,O,$"x($-++*2),O while$_--

Try it online!

MathGolf, 17 bytes
r{n*íï- *'oï *+_x

Try it online!
Explanation
r                   range(0, n)
 {                  start block or arbitrary length
  n                 newline char, or map array with newlines
   *                pop a, b : push(a*b)
    í               get total number of iterations of for loop
     ï              index of current loop, or length of last loop
      -             pop a, b : push(a-b)
                    space character
        *           pop a, b : push(a*b)
         '          push single character
          o         print TOS without popping
           ï        index of current loop, or length of last loop
                    space character
             *      pop a, b : push(a*b)
              +     pop a, b : push(a+b)
               _    duplicate TOS
                x   reverse int/array/string

J, 29 bytes
[:|:@(,~|.)' O'#~1,.~i.+/\@,]

Try it online!
Turned out very similar to Razetime's APL answer, though solved independently.  I tried about 3 other approaches before realizing this one would be shortest.

Stacked, 67 63 bytes
args 0#1+:@x:>{!n x\-1-' '*'O'+n 2*' '*+'O'+x 1-n!=n*LF*+out}"!

Initial attempt, 67 bytes
args 0# :@v 1+2*:>[:v:+1+\-2/*' '*'O'+''split]"!fixshape tr rev out

Full program. Generates something like:
('O'
 ' ' 'O'
 ' ' 'O'
 'O')

Which is the padded, transposed, reversed, and outputted.

Batch, 163 bytes
@set l=@for /l %%i in (1,1,%1)do @call
@set s=
%l% set s= %%s%%
@set t=
%l%:c&for /l %%j in (2,1,%%i)do @echo(
:c
@echo %s%O%t%O
@set s=%s:~1%
@set t=  %t%

Ruby, 52 bytes
->x{(0..x).map{|a|$><<$/*a+' '*(x-a)+?O+' '*a*2+?O}}

No trailing newline (allowed by the rules: "at most one trailing newline")

AHK, 93 bytes
m=0
n=1
f=%1%-1
Loop,%1%{
r=%r%{VK20 %f%}O{VK20 %m%}O{`n %n%}
m+=2
n++
f--
}
FileAppend,%r%,*

If I could figure out how to do math inside of repeating keystrokes, that'd be great.
 - VK20 equates to a space
 - FileAppend outputs to stdout if the filename is *

Haskell, 77 bytes
n!x=[1..n]>>x
-1#i=[]
x#i=(x-1)#(i+1)++x!"\n"++i!" "++'O':(2*x)!" "++"O"
(#0)

Try it online! Usage: (#0) 5

Python 2, 59 bytes
f=lambda n,r='O':(r*n and f(n-1,' '+r))+'\n'*n+r+'  '*n+'O'

Try it online!

Pyth, 26 bytes
VyhQ=+Y+*Zd\O=+ZQ=tQ)j_.tY

Try it Online
Explanation
VyhQ=+Y+*Zd\O=+ZQ=tQ)j_.tY
                            Implicit Q=input() (speed), Z=0 (position), Y=[].
VyhQ                )       For N in [0,...,2Q+2]...
       +*Zd\O               ... prepend Z spaces to 'O'...
    =+Y                     ... add that line to Y...
             =+ZQ=tQ        ... then update position and speed.
                     j_.tY  Combine the lines to form the parabola.

APL (Dyalog Unicode), 27 25 bytes
(⌽,⊢)⍉↑↑∘'O'¨1,1-1↓+\⍳⎕+1

Try it online!
-2 bytes from kritixilithos at the APL Orchard.
-2 bytes from Adám.
Explanation
 (⌽,⊢)⍉↑↑∘'O'¨1,1-1↓+\⍳⎕+1
                      ⍳⎕+1  range 1 - n+1
                    +\      cumulative sum over each element
                  1↓        drop the first value (0)
                1-          subtract 1 from each value
              1,            prepend 1 to it.
             ¨              for each element,
        ↑∘'O'               prepend(element-1) spaces to 'O'.
       ↑                    convert to matrix
      ⍉                     transpose
 (⌽,⊢)                      prepend its reverse (palindromize).


text:
Solve Math Problem Notation
Imagine I have an infinite number of homework problems (!) each given an integer number.
Math Problem Notation is a notation for describing subsets of the problem using problem specifiers.
An MPN expression can consist of several things:

A single value. This represents a set containing the number: 99 -> {99}.
A simple range. This represents the set containing all the numbers from the beginning to the end of the range: 10~13 -> {10, 11, 12, 13}. If the left or right sides are missing, then they are assumed to be -Infinity or Infinity respectively: ~10 -> {x|x ≤ 10}; ~ -> ℤ.
An MPN expression, followed by "skip" and another MPN expression. This represents the difference of the two sets: 10~20 skip 12~14 -> {10, 11, 15, 16, 17, 18, 19, 20}.
Two MPN expressions, separated by a comma. This represents the union of two sets: 1,8~9,15~17 -> {1,8,9,15,16,17}.

The "skip" operator binds tighter than the comma operator, so 16,110~112 skip 16 -> {16,110,111,112} (16 is not included in the set {110,111,112}, so the excluding 16 does not matter.)
You can also put expressions in parentheses for disambiguation:
1~9 skip (2~8 skip (3~7 skip (4~6 skip 5))) -> {1,3,5,7,9}
This is the grammar:
<expr>  ::= "(" <expr> ")"
         || <number>
         || [<number>] "~" [<number>]
         || <expr> "skip" <expr>
         || <expr> "," <expr>

Your task is to write a program that takes two inputs:

An MPN expression
A number

and outputs some truthy or falsey value depending on whether that problem is in the set described by the MPN expression.
Specifications

You can assume that the first input is a well-formed MPN expression (i.e. that it matches the above grammar)
Numbers in an MPN expression are always integers. They can be negative or zero, but will never have a fractional part.
This is code-golf, so the shortest valid submission (measured in bytes) wins.
You can use different characters for ~ and ,, if you want.

Test Cases
10~20             14 -> True
10~20             20 -> True
10~20 skip 14~18  17 -> False
~ skip 6          8  -> True
16,17 skip 16     16 -> True
(16,17) skip 16   16 -> False
~10,5~            8  -> True
~10,5~            4  -> True
6 skip 6,~        6  -> True

Is it possible to use other characters to represent operators?.For example using # instead of ~

@rahnema1 For ~ and ,, but not for skip.

Why is ~10,5~ false for 4? Because that is the union of -infinity to 10 and 5 to infinity, the first of which includes 4

@ev3commander Edited. I always mess up on my test cases. I bet my challenges would be clearer if I didn't add them :P

@Challenger5 it doesn't look like it was updated. In any case, I think you need a bunch more test cases for the trickier aspects (mostly revolving around the infinities and them being able to be anywhere), like 10~20,~ skip 15. I can think of easier solutions that can handle all the listed test cases but will fail on strange placing of open-ended ranges.

@briantist Funny, it must not have updated.

@Challenger5 I've added a test case 6 skip 6,~ which I believe I've interpreted correctly. The other 2 answers so far don't satisfy it (again, assuming I'm interpreting correctly). If I've misunderstood please correct it and clarify, but from my understanding, it should match anything (it's the union of a set that matches nothing with a set that matches everything). These are the kinds of cases I was talking about earlier that I think could help out a lot when testing our solutions.

PowerShell, 189 195 bytes
param($m,$q)('$m',"'(\d*)~(\d*)','($q-ge(`$1)-and$q-le(`$2))'","'\(\)',$q","'((?<=,|skip )\d+|\d+(?=,| skip))','($q-eq`$1)'","'skip','-and!'"-join'-replace'|iex|% Sp* ','|%{"($_)"})-join'-or'|iex

Try it online! (with a single MPN and value)
Try all test cases with -100..100 as values
View the intermediate code generated, for all test cases (with 666 as the value)

Explanation
I realized early on that the infinities make this untenable for generating arrays and testing for values.
I looked into ranges but in .Net they don't have the range needed (the length of the range is limited to a signed (32 bit) integer, so even if it were ok to limit the range to a signed 32-bit int, I wouldn't have been able to handle all ranges.
So I started to just think about this in terms of starts and ends, and ultimately a series of boolean tests and started creating a bunch of regex replaces to turn an MPN into a boolean expression that PowerShell understands.
I basically broke this down into a few rules:

Ranges were easier to work with first because they can't be expressions on either end, but the open-endedness was a pain to implement shortly. The premise is 2~8 is like saying n >=2 && n <=8, but when one of the ends is missing, leave out the && and the missing side. When both are missing, I was going to originally just replace it with $true. What I ended up doing was not really testing for the missing sides at all, but I made sure to wrap each number in ().
and then do a straight substitution that replaces empty parentheses () with the input value. So, in the case of an MPN like ~8 with an input value of 55, the first replace will generate (55-ge()-and55-le(8)), then the second replace comes along to make it (55-ge55-and55-le(8)), essentially nullifying that part of the range.
Next I had to deal with individual numbers in the MPN, but had to take care not to mess with the ones I inserted from before. It's really just numbers in comma , separated lists, and individual numbers before or after a skip, so I used unfortunatley long lookarounds.
skip is basically the same as -and -not so I do a straight replace of skip to -and! (using ! as shorthand for -not).
The next tricky thing was the low order of precendence for the remaining commas. I originally just replaced them with -or but it didn't account for subsequent expressions so 16,17 skip 16 was generating code like ($n-eq16)-or($n-eq17) -and! ($n-eq16). It needed parentheses, but that seemed unworkable with a straight replace. Since all the other things were replaced except commas, and they have the lowest precedence, I just split the entire generated string on the remaining commas, then wrapped each element in parentheses, and rejoined it with -or.

Ultimately the generated code is just piped into Invoke-Expression (iex) to be executed and then we get the boolean result (you can see the code that gets generated instead of the result here).
This took way too long, and I'm sure there's some room to squeeze out a few more bytes, but I can't look at it anymore :-p

Perl, 99 130 bytes
sub f{($_,$n)=@_;s/(-?\d+)?~(-?\d+)?|(-?\d+)/!(defined$3?$n!=$3:length$1&&$1>$n||length$2&&$n>$2)+0/ge;s/skip/&&!/g;s/,/||/g;eval}

Try it on Ideone.
Ungolfed:
sub f {
    my ($e, $n) = @_;

    $e =~ s/(-?\d+)?~(-?\d+)?|(-?\d+)/ (defined($3) ? $n == $3 : (!length($1) || $n >= $1) && (!length($2) || $n <= $2)) + 0 /ge;
    $e =~ s/skip/ && ! /g;
    $e =~ s/,/ || /g;

    return eval($e);
}

Fails for ~-2 for input -2. Also when inserting -? before all three \d*

@KjetilS. Fixed for negative numbers and zero.

nice code (full blown grammar parsing often not needed, regexes are easier)

JavaScript (ES6), 221 292 287 309 274 277 278 bytes
(-5 bytes thanks to Okx)
(j,v,m=1/0,Z=/(skip)([^,]+)/g)=>eval(j[M='replace'](/(-?\d*)~(-?\d*)/g,(e,a,b)=>(a[M]('-','#')||-m)+'<='+(T=v[M]('-','#'))+'&&'+T+'<='+(b[M]('-','#')||m))[M](Z,i=o=>o.match(Z)?i(o[M](Z,'&&!($2)')):o)[M](/,/g,'||')[M](/(^|[^=&#\d])(\d+)([^<\d]|$)/g,'$1$2=='+v+'$3')[M](/#/g,'-'))

Wow. This was not easy because of all the edge cases, but I think I did it. I just hope there are no special cases that could break the regular expressions used. I will golf this more whenever I can.
Test Snippet

D=(j,v,m=1/0,Z=/(skip)([^,]+)/g)=>eval(j[M='replace'](/(-?\d*)~(-?\d*)/g,(e,a,b)=>(a[M]('-','#')||-m)+'<='+(T=v[M]('-','#'))+'&&'+T+'<='+(b[M]('-','#')||m))[M](Z,i=o=>o.match(Z)?i(o[M](Z,'&&!($2)')):o)[M](/,/g,'||')[M](/(^|[^=&#\d])(\d+)([^<\d]|$)/g,'$1$2=='+v+'$3')[M](/#/g,'-'))
MPN Expression:<input type="text" value="1~9 skip (2~8 skip (3~7 skip (4~6 skip 5)))" id="MPN"></input>
<br>
Integer:<input type="number" id="INT" value=6></input>
<input type="button" value="Submit" onclick="T=r=>document.getElementById(r).value;console.log(D(T('MPN'),T('INT')))"></input>

@AriaAx It should work now.

@R.Kap You could use  1/0 for Infinity.

@R.Kap I tried value 6 with the expression 6 skip 6,~ which I believe should be true but it returns false.

@briantist Actually, I believe that should return false as skip applies to everything that follows it  (6,~ in this case) as long as it is not wrapped inside parenthesis. Therefore, I believe it should return true on (6 skip 6),~ rather than 6 skip 6,~ with integer input 6.

@briantist In other words, 6 skip 6,~ should match nothing as it represents the difference between the set {6} and the set {6,-Infinity...Infinity}.

@R.Kap I think it's the other way because of this: The "skip" operator binds tighter than the comma operator, so skip should be interpreted first.

@briantist Sorry it took so long as I am on my phone.  It should work now.

@R.Kap just discovered another one sorry! (this one actually throws an error): 6 skip 6,~ skip 6

@briantist I knew I should not have gotten rid of that match-all regex flag... Yeah, it should work (hopefully) perfectly now. It just took a small bug fix, and again, sorry about taking so long as I am at school on my phone.

@R.Kap no need to apologize, I didn't even post this challenge,  just trying to be helpful!

@briantist Yeah, and thanks for all the help! I really appreciate it! :)

Röda + bc, 183 bytes
f x{{["x=",x,"\n"];replace" ","",",","||","skip\\(","&&!","skip([0-9~]+)","&&!($1)","(?<!~|\\d)(\\d+)(?!~|\\d)","x==$1","(\\d*)~(\\d*)","x>=($1)&&x<=($2)","\\(\\)",x;["\n"]}|exec"bc"}

This is similar to the PowerShell answer (or I think so, I don't understand PowerShell). It takes the number as an argument and the code as a value in the input stream, like this: main { push("1~9") | f(5) }.
I think it works, at least it solves all test cases. The script below can be used to verify this.
main {
    readLines("/tmp/tests.txt") | split(sep=";") | for code, num, ans do
        push(code, " -> ")
        print(code) | replace" ","",",","||","skip\\(","&&!","skip([0-9~]+)","&&!($1)","(?<!~|\\d)(\\d+)(?!~|\\d)","x==$1","(\\d*)~(\\d*)","x>=($1)&&x<=($2)","\\(\\)",num
        a := push(code) | f(num) | head()
        result := push("OK") if [ (a = "0" and ans = "False") or (a = "1" and ans = "True") ] else push("FAIL")
        print code, " ; ", num, " -> ", a, " ", ans, " (", result, ")\n"
    done
}

And the tests:
10~20;14;True
10~20;20;True
10~20 skip 14~18;17;False
~ skip 6;8;True
16,17 skip 16;16;True
(16,17) skip 16;16;False
~10,5~;8;True
~10,5~;4;True
6 skip 6,~;6;True

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Convert λ-expressions to SK-expressions
The λ-calculus, or lambda calculus, is a logical system based on anonymous functions. For example, this a λ-expression:
λf.(λx.xx)(λx.f(xx))

However, for the purposes of this challenge, we'll simplify the notation:

Change λ to \ (to make it easier to type): \f.(\x.xx)(\x.f(xx))
The . in lambda headers is unnecessary, so we can drop it: \f(\xxx)(\xf(xx))
Use the Unlambda-style prefix notation with ` for application rather than writing the two functions together (for a full explanation of how to do this, see Convert between Lambda Calculus Notations): \f`\x`xx\x`f`xx
This is the most complicated substitution. Replace each variable with a number in brackets based on how deeply nested the variable is relative to the lambda header it belongs to (i.e. use 0-based De Bruijn indexing). For example, in \xx (the identity function), the x in the body would be replaced with [0], because it belongs to the first (0-based) header encountered when traversing the expression from the variable to the end; \x\y``\x`xxxy would be converted into \x\y``\x`[0][0][1][0]. We can now drop the variables in the headers, leaving \\``\`[0][0][1][0].

Combinatory logic is basically a Turing Tarpit made out of the λ-calculus (Well, actually, it came first, but that's irrelevant here.)
"Combinatory logic can be viewed as a variant of the lambda calculus, in which lambda expressions (representing functional abstraction) are replaced by a limited set of combinators, primitive functions from which bound variables are absent."1
The most common type of combinatory logic is the SK combinator calculus, which uses the following primitives:
K = λx.λy.x
S = λx.λy.λz.xz(yz)

Sometimes a combinator I = λx.x is added, but it is redundant, as SKK (or indeed SKx for any x) is equivalent to I.
All you need is K, S, and application to be able to encode any expression in the λ-calculus. As an example, here's a translation from the function λf.(λx.xx)(λx.f(xx)) to combinatory logic:
λf.(λx.xx)(λx.f(xx)) = S(K(λx.xx))(λf.λx.f(xx))
λx.f(xx) = S(Kf)(S(SKK)(SKK))
λf.λx.f(xx) = λf.S(Kf)(S(SKK)(SKK))
λf.S(Sf)(S(SKK)(SKK)) = S(λf.S(Sf))(K(S(SKK)(SKK)))
λf.S(Sf) = S(KS)S
λf.λx.f(xx) = S(S(KS)S)(K(S(SKK)(SKK)))
λx.xx = S(SKK)(SKK)
λf.(λx.xx)(λx.f(xx)) = S(K(S(SKK)(SKK)))(S(S(KS)S)(K(S(SKK)(SKK))))

Since we are using the prefix notation, this is ```S`K``S``SKK``SKK``S``S`KSS`K``SKK`.
1 Source: Wikipedia
The Challenge
By now, you've probably guessed what is: Write a program that takes a valid λ-expression (in the notation described above) as input and outputs (or returns) the same function, rewritten in SK-combinator calculus. Note that there are an infinite number of ways to rewrite this; you only need to output one of the infinite ways.
This is code-golf, so the shortest valid submission (measured in bytes) wins.
Test Cases
Each test case shows one possible output. The expression on top is the equivalent λ-calculus expression.
λx.x:
\[0]                        -> ``SKK
λx.xx:
\`[0][0]                    -> ```SKK``SKK
λx.λy.y:
\\[0]                       -> `SK
λx.λy.x:
\\[1]                       -> K
λx.λy.λz.xz(yz):
\\\``[2][0]`[1][0]          -> S
λw.w(λx.λy.λz.xz(yz))(λx.λy.x):
\``[0]\\[1]\\\``[2][0]`[1][0] -> ``S``SI`KS`KK

Related: http://codegolf.stackexchange.com/q/105991/56725

I think your second test case is not correct. The last contains a number not in brackets.

Related: http://codegolf.stackexchange.com/q/53250/134

How did you get λx.f(xx) = S(Kf)(SKK)? Shouldn't it rather be λx.f(xx) = S(Kf)(SII) = S(Kf)(S(SKK)(SKK))? When converting λx.f(xx), I get S {λx.f} {λx.xx} which reduces to S (Kf) {λx.xx} and the expression in brackets is nothing else than ω=λx.xx, which we know is represented as SII = S(SKK)(SKK), right?

@BarbaraKwarc Right, I meant SII, not SKK. That was a mistake.

For the last test case input \\`[0]\[1]\\\[2][0]`[1][0], wouldn't the equivalent lambda expression be λw.w(λx.λy.x)(λx.λy.λz.xz(yz))instead ofλw.w(λx.λy.λz.xz(yz))(λx.λy.x)? In other words, isn't \\[0]EFequivalent toλw.wEFinstead of toλw.wFE`?

Haskell, 251 237 222 214 bytes
15 bytes saved thanks to @Ørjan_Johansen (also see his TIO links in the remarks)!
8 more bytes saved thanks to @nimi!
data E=S|K|E:>E|V Int
p(h:s)|h>'_',(u,a)<-p s,(v,b)<-p u=(v,a:>b)|h>'['=a<$>p s|[(n,_:t)]<-reads s=(t,V n)
a(e:>f)=S:>a e:>a f
a(V 0)=S:>K:>K
a(V n)=K:>V(n-1)
a x=K:>x
o(e:>f)='`':o e++o f
o S="S"
o K="K"
f=o.snd.p

p parses the input, returning the remaining unparsed part in the first component of the resulting pair. The first character of its argument must be a backtick, a backslash or an opening bracket. The pattern guards of p check these cases in this order. In the first case, denoting an application, two more expressions are parsed and combined to an element of the E data type with the infix constructor :>. In the lambda case, the following expression is parsed and immediately given to the a function. Otherwise it is a variable, we get its number with the reads function (which returns a list) and drop the closing bracket by pattern matching with (_:t).
The a function does the quite well known bracket abstraction. To abstract an application, we abstract the two subexpressions and use the S combinator to distribute the argument to both. This is always correct, but with more code we could do much better by handling special cases in order to get shorter expressions. Abstracting the current variable gives I or, when we don't have that, SKK. Usually the remaining cases can just add a K to the front, but when using this notation we have to renumber the variables as the inner lambda is abstracted.
o turns the result to a string for output. f is the complete function.
As in many languages, backslash is an escape character, so it has to be given twice in a string literal:
*Main> f "\\[0]"
"``SKK"
*Main> f "\\`[0][0]"
"``S``SKK``SKK"
*Main> f "\\\\[0]"
"``S``S`KS`KK`KK"
*Main> f "\\\\[1]"
"``S`KK``SKK"
*Main> f "\\\\\\``[2][0]`[1][0]"
"``S``S`KS``S``S`KS``S`KK`KS``S``S`KS``S``S`KS``S`KK`KS``S``S`KS``S`KK`KK``S`KK``SKK``S``S`KS``S``S`KS``S`KK`KS``S`KK`KK``S`KK`KK``S``S`KS``S``S`KS``S`KK`KS``S``S`KS``S`KK`KK``S``S`KS`KK`KK``S``S`KS``S``S`KS``S`KK`KS``S`KK`KK``S`KK`KK"

On the second line, you can use (a,(b,v))<-p<$>p s. 2. The '\\' can be just _ if you move that match last.

Actually, scratch the first part: It's shorter to swap the tuple order and use p(_:s)=a<$>p s for the (moved) '\\' line.

Try it online! for your current version. Which by the way is only 236 bytes, you can drop the final newline.

Try it online! with my suggestions.

How come all my λ-calculus problems are solved in Haskell? Does it have some λ-expression manipulation capabilities?

@Challenger5 I think it's mostly due to the fact that haskell is based on lambda calculus, so people proficient in haskell are more likely to be attracted to this kind of questions :)

@Challenger5 I agree with Leo, plus your sample size is not that big. Stateless parsing doesn't help golfing, a concise notation for algebraic data types does (but that's not used in the other challenge).

You can define p with a single expression with three guards, rearrange the cases and drop a superfluous pair of (): p(h:s)|h>'_',(u,a)<-p s,(v,b)<-p u=(v,a:>b)|h>'['=a<$>p s|[(n,_:t)]<-reads s=(t,V n).

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Construct the natural numbers with sets
This construction is a way of representing the Natural Numbers.
In this representation, 0 is defined as the empty set and for all other numbers, n is the union of {0} and {n-1}.
For example to construct 3 we can follow the algorithm:
3 =
{ø, 2} =
{ø, {ø, 1}} =
{ø, {ø, {ø}}}

Task
As you may have guessed your task is to take in a natural number (including zero) and output its construction.
You may output as a either a string or as a set object if your language of choice supports such objects.
If you choose to output as a string you should represent a set with curly braces ({}).  You may optionally represent the empty set as ø (otherwise it should be a set with no entries {}).  You may also choose to add commas and whitespace between and after entries in the set.
Order is not important, however you may not have any repeated elements in the sets you output (e.g. {ø,ø})
This is code-golf so the goal is to have the fewest bytes
Test cases
Here are some test cases with some example outputs.
0 -> {}
1 -> {{}}
2 -> {{}{{}}}
3 -> {{}{{}{{}}}}
4 -> {{}{{}{{}{{}}}}}

@mbomb007 It doesn't matter whether the definition is "wrong" or not. It's still a fine challenge (and a different one).

Closely related.

@mbomb007 The test cases and the definition given in this challenge match up, and are different from the other challenge. If anything, the link could be improved, but I don't think the link is relevant to the challenge itself.

He called it the Von Neumann construction, though, and that's not what this challenge is. That's what the dup is. It follows that each natural number is equal to the set of all natural numbers less than it

Can we return a set-like object such as a list of lists from a function or print our language's representation to STDOUT?

@Dennis Yes that is fine

Python, 28 bytes
lambda x:"{{}"*x+x*"}"or"{}"

Try it online!
This is a pretty bland solution to the problem.  For numbers greater than zero you can get the representation with the string formula "{{}"*x+"}"*x.  However this doesn't work for zero where this is the empty string.  We can use this fact to short circuit an or to return the empty set.
I wanted to use python's builtin set objects to solve this problem but unfortunately:
TypeError: unhashable type: 'set'

You cannot put sets inside of sets in python.

You can move the x to "{{}"*x+x*"}"or saving a byte

f= could be removed.

cf. http://codegolf.stackexchange.com/a/111696/62084

There's frozenset but ain't nobody got bytes for that...

Haskell, 37 bytes
f 0="{}"
f n=([1..n]>>)=<<["{{}","}"]

Try it online!
Until 10 minutes ago an answer like this would have made no sense to me. All credits go to this tips answer.
Basically, we use >> as concat $ replicate (but passing it a list of n elements instead of simply n), and =<< as concatMap, replicating then n times each of the strings in the list and concatenating the result into a single string.
The 0 case is treated separately as it would return an empty string.

@Laikoni I tried something like that too, but you would need to special case f 1 too to make it work correctly

Indeed. Then I like your version even more.

JavaScript, 28 bytes
f=n=>n?--n?[[],f(n)]:[[]]:[]

Represents sets using arrays. 38-byte nonrecursive solution:
n=>'{{}'.repeat(n)+'}'.repeat(n)||'{}'

Returns the example output strings.

Mathematica, 27 bytes
I've got two solutions at this byte count:
Nest[{{}}~Union~{#}&,{},#]&
Union//@Nest[{{},#}&,{},#]&

Near miss at 32 bytes: #//.{1->{{}},x_/;x>1->{{},x-1}}&. Although I guess it messes up input 0

Perl 6, 37 bytes
{('{}','{{}}',{q:s'{{}$_}'}...*)[$_]}

Try it
Expanded:
{   # bare block lambda with implicit parameter ｢$_｣

  (
    # generate a sequence

    '{}',   # seed it with the first two values
    '{{}}',

    {   # bare block lambda with implicit parameter ｢$_｣

      q         # quote
      :scalar   # allow scalar values

      '{{}$_}'  # embed the previous value ｢$_｣ in a new string

    }

    ...         # keep using that code block to generate values

    *           # never stop

  )[ $_ ] # get the value at the given position in the sequence
}

Are you missing a quote terminator : or is this something new to Perl 6?

@CraigR8806 You can't use colons to delimit quoting constructs in Perl 6 because the are used for adverbs. (look at the expanded version)

Röda, 37 bytes
f n{[[[],f(n-1)]]if[n>1]else[[[]]*n]}

05AB1E, 6 5 bytes
Code
ƒ)¯sÙ

Uses the CP-1252 encoding. Try it online! or Verify all test cases!.
Explanation
ƒ       # For N in range(0, input + 1)..
 )      #   Wrap the entire stack into an array
  ¯     #   Push []
   s    #   Swap the two top elements
    Ù   #   Uniquify the array

F¯), does that not work?

@carusocomputing I don't think that works for n=0, since the output is empty (not an empty set).

Retina, 22 bytes
.+
$*
\`.
{{}
{

^$
{}

Try it online!
Explanation
.+
$*

Convert the input to unary.
\`.
{{}

Replace each unary digit with {{} and print the result without a trailing linefeed (\).
{

Remove the opening {s, so that the remaining } are exactly those we still need to print to close all the sets. However, the above procedure fails for input 0, where we wouldn't print anything. So...
^$
{}

If the string is empty, replace it with the empty set.

I was wondering how to repeat a string n times in Retina...

Brain-Flak, 135 bytes
Includes +1 for -A
(({}())<{({}[()]<((((((()()()()()){}){}){}())()){}{})>)}{}({}[()()])>)(({})<{({}[()]<(((({}()())[()()])))>)}{}>[()]){(<{}{}{}>)}{}{}{}

Try it online!
(({}())<                 # Replace Input with input + 1 and save for later
  {({}[()]<              # For input .. 0
    (...)                # Push '}'
  >)}{}                  # End for and pop counter
  ({}[()()])             # change the top '}' to '{'. This helps the next stage
                         # and removes the extra '}' that we got from incrementing input
>)                       # Put the input back on

(({})<                   # Save input
  {({}[()]<              # For input .. 0
    (((({}()())[()()]))) # Replace the top '{' with "{{{}"
  >)}{}                  # end for and pop the counter
>[()])                   # Put down input - 1
{(<{}{}{}>)}             # If not 0, remove the extra "{{}"
{}{}{}                   # remove some more extras

CJam, 11 bytes
Lri{]La|}*p

Prints a set-like object consisting of lists of lists. CJam prints empty lists as empty strings, since lists and strings are almost interchangeable.
Try it online!
Explanation
L            Push an empty array
 ri          Read an integer from input
   {    }*   Run this block that many times:
    ]          Wrap the entire stack in an array
     La        Wrap an empty list in an array, i.e. [[]]
       |       Set union of the two arrays
          p  Print the result

Old answer, 21 18 bytes
This was before it was confirmed that it was OK to print a nested list structure. Uses the string repetition algorithm.
Saved 3 bytes thanks to Martin Ender!
ri{{}}`3/f*~_{{}}|

Explanation
ri                  Read an integer from input
  {{}}`             Push the string "{{}}"
       3/           Split it into length-3 subtrings, gives ["{{}" "}"]
         f*         Repeat each element of that array a number of times equal to the input
           ~_       Dump the array on the stack, duplicate the second element
             {{}}|  Pop the top element, if it's false, push an empty block, which gets
                      printed as "{}". An input of 0 gives two empty strings on the
                      repetition step. Since empty strings are falsy, we can correct the
                      special case of 0 with this step.

Jelly, 6 bytes
⁸,⁸Q$¡

This is a niladic link that reads an integer from STDIN and returns a ragged array.
Try it online!
How it works
⁸,⁸Q$¡  Niladic link.

⁸       Set the return value to [].
    $   Combine the three links to the left into a monadic chain.
 ,⁸     Pair the previous return value with the empty array.
   Q    Unique; deduplicate the result.
     ¡  Read an integer n from STDIN and call the chain to the left n times.

Cardinal, 51 50 bytes
%:#>"{"#? v
x  ^?-"}{"<
v <8/ ?<
>  8\
v"}"<
>?-?^

Try it online!
Explanation
%:#
x

Receive input and send down and left from the #
   >"{" ? v
   ^?-"}{"<

Print "{" one time then print "{}{" n-1 times if n>1 then print "{}" if n>0
       #

v <8/ ?<
>  8\

Hold onto the input value until the first loop completes
v"}"<
>?-?^

Print "}" once then repeat n-1 times if n>1

Python 3, 32 bytes
f=lambda n:[[],n and f(n-1)][:n]

Not the shortest way, but I just had to do this with recursion.
Try it online!

AHK, 55 bytes
IfEqual,1,0
s={{}{}}
Loop,%1%
s={{ 2}{}}%s%{}}
Send,%s%

It's not the shortest answer but I enjoyed this because the idiosyncrasies of AutoHotkey make this recursion method look super wrong. If and Loop statements assume the next line is the only thing included if brackets aren't used. Curly brackets are escape characters so you have to escape them with other curly brackets to use them as text. Also, the variable 1 is the first passed argument. When I read the code without knowing those tidbits, the logic looks like this:

If 1=0, then set s equal to the wrong answer
Loop and add a bunch of brackets to the beginning and a few to the end every time
Return by sending the resulting string to the current window

Without all the bracket escape characters, it would look like this:
IfEqual,1,0
   s={}
Loop,%1%
   s={{}%s%}
Send,%s%

JavaScript 50 bytes
g=n=>n==0?"":"{{}"+g(n-1)+"}"
z=m=>m==0?"{}":g(m)

when a number is equal to 0 it is a falsy value for JavaScript. So you can remove the ==0 if you reverse your ternary expressions

Pure Bash, 49 48 41 bytes
for((;k++<$1;)){ s={{}$s};};echo ${s-{\}}

Try it online!

tinylisp, 52 bytes
(d f(q((n)(i n(i(e n 1)(c()())(c()(c(f(s n 1))())))(

Try it online! (test harness).
Explanation
Note that (cons x (cons y nil)) is how you build a list containing x and y in Lisp.
(d f           Define f to be
 (q(           a quoted list of two items (which acts as a function):
  (n)           Arglist is a single argument n
  (i n          Function body: if n is truthy (i.e. nonzero)
   (i(e n 1)     then if n equals 1
    (c()())       then cons nil to nil, resulting in (())
    (c            else (if n > 1) cons
     ()            nil to
     (c            cons
      (f(s n 1))    (recursive call with n-1) to
      ())))         nil
   ()))))        else (if n is 0) nil

C (gcc), 52 bytes
n(i){putchar(123);i>1&&n(0);i&&n(i-1);putchar(125);}

Taking advantage of some short circuit evaluation and recursion.
Try it online!

48 bytes

dc, 46 bytes
[[{}]]sx256?^dd3^8d^1-/8092541**r255/BF*+d0=xP

Try it online!
Input on stdin, output on stdout.
This works by computing a formula for the desired output as a base-256 number.  The P command in dc is then used to print the base-256 number as a string.

Further explanation:
Let n be the input n.  The dc program computes the sum of
A = floor(256^n / 255) * 125     (BF is interpreted by dc as 11*10+15 = 125)
and
B = floor((256^n)^3 / (8^8-1)) * 8092541 * (256^n).

For A:
Observe that 1 + 256 + 256^2 + ... + 256^(n-1) equals (256^n-1)/255, by the formula for a geometric progression, and this equals floor(256^n / 255).  So this is the number consisting of n 1's in base 256.
When you multiply it by 125 to get A, the result is the number consisting of n 125's in base 256 (125 is a single digit in base 256, of course). It's probably better to write the digits in base 256 as hex numbers; 125 is hex 7D, so A is the base-256 number consisting of n 7D's in a row.

B is similar:
This time observe that 1 + 16777216 + 16777216^2 + ... + 16777216^(n-1) equals (16777216^n - 1)/16777215, and this equals floor(16777216^n/16777215).
Now, 256^3 = 16777216, and 8^8-1 = 16777215, so this is what we're computing as floor((256^n)^3 / (8^8-1)).
From the geometric series representation, this number in base 256 is 100100100...1001 with n of the digits being 1 and the rest of the digits being 0.
This is multiplied by 8092541, which is 7B7B7D in hexadecimal.  In base 256, this is a three-digit number consisting of the digits 7B, 7B, and 7D (writing those digits in hex for convenience).
It follows that the product written in base 256 is a 3n-digit number consisting of the 3 digits 7B 7B 7D repeated n times.
This is multiplied by 256^n, resulting in a 4n-digit base-256 number, consisting of the 3 digits 7B 7B 7D repeated n times, followed by n 0's.  That's B.

Adding A + B now yields the 4n-digit base-256 number consisting of the 3 digits 7B 7B 7D repeated n times, followed by n 7D's.  Since 7B and 7D are the ASCII codes for { and }, respectively, this is the string consisting of n copies of {{} followed by n copies of }, which is exactly what we want for n > 0.  The P command in dc prints a base-256 number as a string, just as we need.
Unfortunately, n=0 has to be treated as a special case. The computation above happens to yield a result of 0 for n=0; in that case, I've just hard-coded the printing of the string {}.

That's a very interesting approach using the less known behavior of that printing command. Nicely done! An explanation of how this works would improve the answer.

@seshoumara Thanks -- I've added a detailed explanation.

Java 7, 61 bytes
String p(int p){return p<1?"{}":p<2?"{{}}":"{{}"+p(p-1)+"}";}

Try it online!

Batch, 88 bytes
@set s={}
@if %1 gtr 0 set s=&for /l %%i in (1,1,%1)do @call set s={{}%%s%%}
@echo %s%

05AB1E, 5 3 bytes
F¯)

Try it online!
This version is after he clarified that sets are okay.
F   # From 1 to input...
 ¯  # Push global array (default value is []).
  ) # Wrap stack to array.

Old version (that makes use of ø):
05AB1E, 5 4 bytes
FX¸)

Try it online!
Where 1 is equivalent to ø.
F    # From 1 to input...
 X   # Push value in register X (default is 1).
  ¸  # Wrap pushed value into an array.
   ) # Wrap whole stack into an array.
     # Implicit loop end (-1 byte).
     # Implicit return.

Brainf***, 99 bytes
>+>+>+>+<[>[-<+++++>]<-<]>--[->+>+<<]
>[-<+>]>++<,[[->>+>+<<<]>>[-<<<..>>.>]>[-<<.>>]+[]]<.>>.

(newline for aesthetics)
Since it's brainf***, it takes input as ascii char codes (input "a" corresponds to 96)
Braineasy, 60 bytes
Also, in my custom language (brainf** based, interpreter here):
#123#[->+>+<<]>++<,[[-<+<+>>]<[->>>..<.<<]<[->>>.<<<]!]>>.<.

You have to hardcode the program input into the interpreter because i'm lazy.

Welcome to the site! Why is there a []?  It seems like it could be removed

If you don't have that, it will output an extra {} at the end (it infinitely loops).

dc, 33 bytes
[[{}]n1-d0<m]sr[[{]nd0<r[}]n]dsmx

Try it online!
Not as clever as the other dc answer, but rather shorter

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Terra Mystica: Cycling Power
The boardgame Terra Mystica has some very interesting mechanics for one of the primary resources, power. Instead of gaining and spending units of power from a bank, each player starts the game with exactly 12 units of power which are distributed over three "bowls", which are labelled I, II and III. Gaining and spending power then simply shifts power between these bowls:

To spend a unit of power, move it from bowl III to bowl I (provided you have a unit in bowl III).
When you gain a unit of power, if there is a unit in bowl I, move it to bowl II. If there are no units in bowl I, but there is a unit in bowl II, move it to bowl III. If all units are already in bowl III, nothing happens.
When you gain or spend multiple units at once, they are processed one unit at a time.

Here is an example. Say, a player starts with the following power distribution (given in order I | II | III):
5 | 7 | 0

Their power changes as follows if they gain and spend power a few times:
               5 |  7 |  0
Gain  3  ==>   2 | 10 |  0
Gain  6  ==>   0 |  8 |  4   (move 2 power from I to II,
                              then the remaining 4 from II to III)
Gain  7  ==>   0 |  1 | 11
Spend 4  ==>   4 |  1 |  7
Gain  1  ==>   3 |  2 |  7
Spend 7  ==>  10 |  2 |  0
Gain 12  ==>   0 | 10 |  2   (move 10 power from I to II,
                              then the remaining 2 from II to III)
Gain 12  ==>   0 |  0 | 12   (the two excess units go to waste)

Your task is to compute the result of one such gaining or spending event.
The Challenge
You are given four integers as input. The first three, I, II, III, represent the amount of power in each of the three bowls. They will be non-negative, and they will sum to 12. The fourth number, P, is the amount of power gained or spent, and will be in the inclusive range [-III, 24] (so you may assume that the player will never try to spend more power than they currently can, but they might be gaining more power than they need to move all power into bowl III).
You may take these numbers in any consistent order, as separate arguments, as a list of integers, or as a string containing these integers. You can also take P as one argument, as I, II, III as a separate list argument.
You should output three integers I', II', III' which represent the amount of power in each bowl after P units were gained or spent, following the rules explained above.
You may write a program or a function and use any of the our standard methods of receiving input and providing output.
You may use any programming language, but note that these loopholes are forbidden by default.
This is code-golf, so the shortest valid answer – measured in bytes – wins.
Test Cases
I II III P => I' II' III'
5 7 0 3    => 2 10 0
2 10 0 6   => 0 8 4
0 8 4 7    => 0 1 11
0 1 11 -4  => 4 1 7
4 1 7 0    => 4 1 7
4 1 7 1    => 3 2 7
3 2 7 -7   => 10 2 0
10 2 0 12  => 0 10 2
0 10 2 12  => 0 0 12

I recommend removing gender-specific pronouns and replacing them with gender-neutral ones (or restructuring sentences): gamers do not have to be male.

@GregMartin Of course. Did I catch them all?

Look like it; thank you for thinking about it! Also, is Terra Mystica as awesome as I've heard?

@GregMartin yes. :)

@GregMartin I confirm :)

It looks like Settlers of Catan meets Civilization V.

No power burns from bowl 2? This just feels so incomplete.

seconding @moreON. I want answers with sacrificing power!

@GregMartin: No. It's móre awesome than you've heard.

@moreON I thought a while about including it but couldn't find a good way to do so that didn't feel tacked on.

I'm tempted to try this in BrainFuck this evening. No promises that I'll ever actually accomplish a solution, but given that BF doesn't support negative numbers, would you be OK with me using a sign-and-magnitude representation for P?

@ymbirtt Yes, but you could also treat the tape cells as 2's complement so 255 would represent -1 etc.

I'm not quite sure which would make my life easier at this point, but I'll bear both options in mind.

Is it safe to assume no one will try and spend more power than they have?

@aslum "(so you may assume that the player will never try to spend more power than they currently can, but they might be gaining more power than they need to move all power into bowl III)"

@ymbirtt I'm pretty sure there are BF implementations that have negatives, but you can't take a negative number as input.

@mbomb007, The standard I/O formats say nothing about BF specifically, but does allow stack-based languages to start with their input on the stack and leave their output on the stack. It also allows TMs to start with their input on the tape and leave their output on the tape. I think it's reasonable for BF to start with its input on the tape and leave its output on the tape, but obviously OP can have the final say here.

@ymbirtt This has already been discussed (can't find where). BF is not a Turing machine. Maybe Martin can give his opinion, since I think he's the one that told me that. Considering that BF's standard method of I/O is , and ., those should be used.

C, 97 94 bytes
f(i,j,k,n){for(;n;n-=n/abs(n))n<0?k?++i+--k:0:i?++j+--i:j?++k+--j:0;printf("%d %d %d",i,j,k);}

In ungolfed form:
f(i, j, k, n) {
    while (n) {
        if (n < 0) {
            if (k) {
                ++i; --k;
            }
            ++n;
        } else {
            if (i) {
                ++j; --i;
            }
            else if (j) {
                ++k; --j;
            }
            --n;
        }
    }
    printf("%d %d %d", i, j, k);
}

Mathematica, 52 bytes
{x=#-#4~Min~#,y=Max[#2+#-Abs[#4~Max~0-#],0],12-x-y}&

This is an unnamed function that takes a list {I, II, III, P} as input and returns a list {I', II', III'}.
A closed-form solution. It doesn't really feel optimal yet...

Thought I could shorten, but {##,12-+##}&[#-#4~Min~#,Max[#2+#-Abs[#4~Max~0-#],0]]& is a byte longer. I like the 12-+## though.

@GregMartin I tried the same thing :)

Python 2, 104 bytes
def f(i,d,t,g):
 x=min(i,g);i-=x;q=g>0;g-=x
 if q:d+=x;x=min(d,g);g-=x;d-=x;t+=x
 else:t+=x
 print i,d,t

Try it online
Ungolfed:
def f(i,d,t,g):
 if g>0:
    x=min(i,g)
    g-=x
    i-=x
    d+=x
    x=min(d,g)
    g-=x
    d-=x
    t+=x
 else:
    x=min(i,g)
    g-=x
    i-=x
    t+=x
 print(i,d,t)

Röda, 100 94 bytes
f a,b,c,p{{c+=p;a-=p}if[p<0]else{{a--;b++;p--}while[p*a>0];{b--;c++;p--}while[p*b>0]};[a,b,c]}

Ungolfed:
f a,b,c,p {
    if [ p < 0 ] do
        c += p
        a -= p
    else
        { a-=1; b+=1; p-=1 } while [ p > 0 and a > 0 ]
        { b-=1; c+=1; p-=1 } while [ p > 0 and b > 0 ]
    done
    return a, b, c
}

Doesn't Röda have the ++ and -- operators?

@KritixiLithos Thanks! Yes it does.

Haskell, 58 bytes
f(a,b,c)d|m<-min a d,z<-min(c+d-max 0 m)12=(a-m,b+c+m-z,z)

The intermediate value m denotes the amount of power going from (or to, if negative) the first bowl, z denotes the amount of power in the third bowl after the action. A last minute one byte optimization changed the old expression for the second bowl from 12-a+m-z using the identity a+b+c=12.
The natural result type is a triple for the bowls, so the input also takes the bowls as a triple and the power change as a second argument. This allows to handle all test cases with one application of scanl:
*Main> scanl f (5,7,0) [3,6,7,-4,0,1,-7,12,12]
[(5,7,0),(2,10,0),(0,8,4),(0,1,11),(4,1,7),(4,1,7),(3,2,7),(10,2,0),(0,10,2),(0,0,12)]

JavaScript, 61 59 bytes
(a,b,c,d)=>[r=a-d>0?a-d:0,s=r?b:b-d+2*a>0?b-d+2*a:0,12-r-s]

Try it online!

GNU sed, 66 bytes
Includes +1 for -r
/-/!{:
s/1,(.* )1/,1\1/
t}
s/(.*)(1+) -\2/\2\1/
s/(,,1{12}).*/\1/

Uses unary (see this consensus).
Try it online!
/-/!{                  # If there is not a '-'
  :                    # start loop
  s/1,(.* )1/,1\1/     # move a 1 from before a ',' to after the ',' for every 1 after the space
                       # sed reads left to right, so this takes everything from the first bowl before starting on the second
  t                    # loop if something changed
}                      # end if
s/(.*)(1+) -\2/\2\1/   # take all of the 1s from after a '-' and move them to the begining.
                       # at the same time, remove that many 1s from the 3rd bowl
s/(,,1{12}).*/\1/      # remove everything after 12 1s in the third bowl

Retina,  46  41 39 38 bytes
Thanks to Martin Ender for multiple helpful suggestions!
+`1,(.*¶)1
,1$1
(.*)(1+)¶-\2$
$2$1
G`,

Takes input in unary. The first line contains the amounts of power in the three bowls, comma separated, the second line the amount of power to cycle.
Test suite - Takes all inputs on a single line and converts from decimal to unary and vice-versa for convenience of use.
Explanation
+`1,(.*¶)1
,1$1

Positive case: we repeatedly remove the leading 1 from the second line, and move a 1 from the first non-empty bowl to the following one, as long as this operation is possible (i.e. the number of power to cycle is non-zero and not all power is in the third bowl). The s modifier means single-line, allowing . to match also the newline.
(.*)(1+)¶-\2$
$2$1

Negative case: done all in one step, moving the amount of power indicated by the last input from the third to the first bowl. This will also remove the line containing the negative amount of power to move.
G`,

Keep (grep) only lines containing a comma. This will get rid of the eventual remains of the first line.

Python 2, 91 bytes
Based on this answer
def f(i,d,t,g):
 x=min(i,g);i-=x
 if g>0:y=min(d+x,g-x);d+=x-y;t+=y
 else:t+=x
 print i,d,t

Try it online
Ungolfed:
def f(i,d,t,g):
 if g>0:
    x=min(i,g)
    y=min(d+x,g-x)
    i-=x
    d+=x-y
    t+=y
 else:
    x=min(i,g)
    i-=x
    t+=x
 print(i,d,t)

Welcome to the site!

Batch, 87 bytes
@set/a"i=%4-%1,j=%4*(-%4>>5)-%2-2*i*(-i>>5),i*=i>>5,j*=j>>5,k=12-i-j
@echo %i% %j% %k%

Use the following formulae:
I' = min(I - P, 0)
II' = min(II + min(P, 0) - 2 * min(P - I, 0), 0)
III' = 12 - I' - II'

Since Batch doesn't have a less than operator, I calculate i = min(-i, 0) using i*=i>>5.

Perl 6, 99 bytes
->\a,\b,\c,\d{d>0??[»+»] (a,b,c),|(|((-1,1,0)xx a),|((0,-1,1)xx a+b),|(0 xx*))[^d]!!(a- d,b,c+d)}

Let a, b, and c be the number of starting tokens in bowls I, II, and III respectively.  Then, for the adding power case, a list is created that contains a copies of the triplet (-1, 1, 0), followed by a + b copies of the triplet (0, -1, 1), followed by infinite copies of 0.  The first d elements of this list, d being the amount of power to add, are added elementwise to the starting power distribution.
For subtracting power (negative d), a simple closed form is used: (a - d, b, c + d).

tinylisp, 134 bytes
(d f(q((x y z p)(i p(i(l p 0)(f(s x p)y(a z p)0)(i x(f(s x 1)(a y 1)z(s p 1))(i y(f x(s y 1)(a z 1)(s p 1))(f x y z 0))))(c x(c y(c z(

Defines a function f that takes four arguments, the three bowls (x y z) and the amount of power transacted (p), and returns a list of the three bowls after the transaction. Here's a properly spaced version with all test cases: Try it online!
(d f                         Define f to be
 (q(                          a quoted two-item list (which acts as a function):
  (x y z p)                    Arglist: the three bowls x y z and power p
  (i p                         If p is nonzero
   (i (l p 0)                   then if p is negative (spending power)
    (f(s x p)y(a z p)0)          then take -p from z, add -p to x, and recurse with p=0
    (i x                         else (gaining power), if x is nonzero
     (f(s x 1)(a y 1)z(s p 1))    then take 1 from x, add to y, decrement p and recurse
     (i y                         else if y is nonzero
      (f x(s y 1)(a z 1)(s p 1))   then take 1 from y, add to z, decrement p and recurse
      (f x y z 0))))               else no moves possible; recurse with p=0
   (c x(c y(c z())))))))        else (p=0), cons x y z into a list and return it


text:
Help me juice my avocados
In this challenge, I have a field of avocados which I'd like to juice as quickly and completely as possible. Can you write a program or function to help me work out how to juice all the avocados perfectly?
As input, you'll get the avocados as an mxm square grid, where m is an integer between 3 and 6. Each square contains exactly one avocado. Avocados have several stages of juiciness:
Stage 1: The avocado has not been juiced at all.
Stage 2: The avocado has been partially juiced.
Stage 3: The avocado has been completely juiced.
Stage 4: The avocado has exploded due to over-juicing.
When you use a juicing tool, the avocados in that juicing tool's area of effect move to the next stage. Exploding avocados have a lot of force and will destroy the entire avocado field, so make sure none of the avocados explode!
Here is an example of a grid of avocados. In these examples, I've used the  coordinate 0,0 for the bottom-left corner, and the coordinate 2,2 for the top-right corner, although you can adjust the coordinate system to suit your language.
112
221
231

The goal is to make all the avocados perfectly juiced (i.e. stage 3). To achieve this you have three different juicing tools in your possession. Each juicing tool have a different area of effect, but they all increase the juiciness of affected avocados by 1.
Here are all the tools you have at your disposal. You use the juicers by specifying the first letter of the tool, then the coordinates which you want to juice. For example, to use the Slicer on square 5,2, you would output S 5,2.
Slicer: Juices the target coordinate and the avocado on either side.
112     112     112
221 --> XXX --> 332
231     231     231

Grater: Juices the target coordinate and the avocado above and below.
112     1X2     122
221 --> 2X1 --> 231 --> kaboom!
231     2X1     241

Rocket Launcher: Juices the target coordinate and all adjacent avocados.
112     1X2     122
221 --> XXX --> 332
221     2X1     231

Sample Inputs and Outputs
323
212
323

G 1,1
S 1,1

3312
3121
1213
2133

R 0,0
R 1,1
R 2,2
R 3,3

22322
22222
22222
33233
33333

G 0,3
G 1,3
G 2,2
G 3,3
G 4,3

222332
333221
222332
333222
222333
333222

S 1,5
S 1,3
S 1,1
S 4,5
S 4,3
S 4,1
G 5,4

You don't seem to explicitly say this, but does the solution have to definitely take the fewest moves?

What do we do if there is no solution? Or will input without a solution not be given?

This has ignored some constructive comments from the sandbox. Here's one: I suppose you should flexibly allow the user to choose their coordinate system (e.g., where the origin is, 0-indexed or 1-indexed).

@FryAmTheEggman No. Although with the sample inputs the only solution is the fewest one as well.

@LevelRiverSt There will always be a solution.

@Pavel thanks so much for not posting that as an answer or a question.

I saw this question, and I was ready to downvote, VTC, and flag as spam. Instead, +1.

@Pavel I was so tempted to make that the title...

Related

Mathematica — 350 bytes
Not a very short solution, but better than no solution at all, right?
t[x_]:=Flatten@Table[x/@{G,S,R},{i,n},{j,n}];""<>Cases[StringReplace[(First@Solve[(Table[G[i,j]+G[i-1,j]+G[i+1,j]+S[i,j]+S[i,j-1]+S[i,j+1]+R[i,j]+R[i-1,j]+R[i+1,j]+R[i,j-1]+R[i,j+1],{i,n=Length@#},{j,n}]/.(G|S|R)[___,0|n+1,___]->0)==3-#&&And@@t[#[i,j]>=0&],t[#[i,j]&],Integers])/.{(x_->m_):>ToString[m x]},{"["->" ","]"->"\n",", "->","}],Except@"0"]&

A more readable version (with extra spaces and indents and stuff):
t[x_] := Flatten@Table[x /@ {G, S, R}, {i, n}, {j, n}];
"" <> Cases[
   StringReplace[(First@
       Solve[(Table[
             G[i, j] + G[i - 1, j] + G[i + 1, j] + S[i, j] +
              S[i, j - 1] + S[i, j + 1] + R[i, j] + R[i - 1, j] +
              R[i + 1, j] + R[i, j - 1] + R[i, j + 1], {i,
              n = Length@#}, {j, n}] /. (G | S | R)[___,
              0 | n + 1, ___] -> 0) == 3 - # &&
         And @@ t[#[i, j] >= 0 &], t[#[i, j] &],
        Integers]) /. {(x_ -> m_) :> ToString[m x]}, {"[" -> " ",
     "]" -> "\n", ", " -> ","}], Except@"0"] &

Input is an array (e.g. {{3,2,3},{2,2,2},{3,2,3}}), output is a string (with a trailing newline — if this is unacceptable, enclose the function in StringDrop[...,-1] for an extra 15 bytes). I used the coordinate system that says (1,1) is the top-left corner, (n,n) is the bottom right (where n is the dimension of the matrix). Sometimes, if the solution requires doing the same operation multiple times, the output includes things like 3 G 2,2 (for "use the grater at (2,2) three times") — since you didn't say what to do in this case, I hope that's OK.
Explanation:

Table[G[i,j]+G[i-1,j]+G[i+1,j]+S[i,j]+S[i,j-1]+S[i,j+1]+R[i,j]+R[i-1,j]+R[i+1,j]+R[i,j-1]+R[i,j+1],{i,n=Length@#},{j,n}] creates an array with the variables G[i,j] in each place that's affected by using the grater at (i,j), and similarly for S[i,j] and R[i,j]. These variables represent the number of times the tool is used at that position.
.../.(G|S|R)[___,0|n+1,___]->0 removes the effects of using tools at positions outside the avocado field.
...==3-# compares this to the difference between the input and a field of perfectly juiced avocados.
...&&And@@t[#[i,j]>=0&] says the variables G[i,j], S[i,j], R[i,j] must be non-negative (you can't un-juice the avocados!), using the shorthand t[x_]:=Flatten@Table[x/@{G,S,R},{i,n},{j,n}].
First@Solve[...,t[#[i,j]&],Integers] finds the first integer solution to our equations in terms of the variables G[i,j], S[i,j], R[i,j].
/.{(x_->m_):>ToString[m x]} hides the variables that equal zero, while also putting the solution in a nice string form.
StringReplace[...,{"["->" ","]"->"\n",", "->","}] turns strings like "2 G[1, 4]" into strings like "2 G 1,4", and adds a newline on the end.
""<>Cases[...,Except@"0"] removes all the leftover "0"s and joins all the strings together.

Python3, 362 bytes
E=enumerate
M=[(0,1),(0,-1),(1,0),(-1,0)]
def f(a):
 q=[({(x,y):u for x,r in E(a)for y,u in E(r)},[])]
 while q:
  m,j=q.pop(0)
  if{3}=={*m.values()}:return j
  for x,y in m:
   for G,s in[('S',M[:2]),('G',M[2:]),('R',M)]:
    if len(S:=[(x+X,y+Y)for X,Y in s+[(0,0)]if(C:=(x+X,y+Y))in m])==len(O:={C:m[C]+1for C in S if m[C]+1<=3}):q+=[({**m,**O},j+[(G,x,y)])]

Try it online!
The code above is a basic brute-force solution. However, it times out for the last test case, so below is an optimized solution (at the cost of 101 bytes) that solves all the test cases in a far more reasonable amount of time:
Python3, 463 bytes
E=enumerate
M=[(0,1),(0,-1),(1,0),(-1,0)]
def f(a):
 q=[({(x,y):u for x,r in E(a)for y,u in E(r)},[])]
 while q:
  m,j=q.pop(0)
  if{3}=={*m.values()}:return j
  D={'G':{},'S':{},'R':{}}
  for x,y in m:
   for G,s in[('S',M[:2]),('G',M[2:]),('R',M)]:
    if len(S:=[(x+X,y+Y)for X,Y in s+[(0,0)]if(C:=(x+X,y+Y))in m])==len(O:={C:m[C]+1for C in S if m[C]+1<=3}):D[G][len(S)]=D[G].get(len(S),[])+[({**m,**O},j+[(G,x,y)])]
  for i in D:
   if D[i]:q+=D[i][max(D[i])]

Try it online!
Further optimizations could be added, including flood fills to check that a juicing process does not strand unjuiced avocados in a patch that can never be reached again.


text:
Maximal Skittle Enjoyment
You've been given a bag of Skittles.  Everybody knows that in order to appreciate the different flavors the most, you need to rotate between the flavors.
Basics:

You can only eat 1 skittle at a time
The order that you eat your skittles must be periodic.
Each period cannot contain a particular flavor more than once.
Your bag only has so many skittles.  You cannot eat more of a particular flavor of skittle than appears in your bag.
You want to eat as many skittles as you can (it may not always be possible)

Examples:
Lets say you start with 3 Red, 2 Blue, and 3 Green skittles:
R B G R B G R G       Invalid:  The last R must be followed by a B, not a G
R B G R B G R         Valid, but sub-optimal
R R R                 Valid, but sub-optimal
R G B R G B R G       Valid and optimal
G R B G R B G R       Also valid and optimal (there are multiple good solutions)

Input/Output

You are passed a non-empty list of positive integers for the color counts.  (The above example would be [3,2,3]).
You need to return a list containing valid and optimal ordering.
Instead of using colors, you will use the indices from input list.  (The last example output above would be [2,0,1,2,0,1,2,0]).
Your output may be 0-indexed or 1-indexed.  My examples will be 0-indexed

Test Cases
1                          0
4                          0 0 0 0
4 1                        0 0 0 0
3 1                        0 1 0                   or  0 0 0
5 2 2                      0 1 2 0 1 2 0
2 3 5                      2 1 0 2 1 0 2 1         or  1 2 0 1 2 0 1 2
2 4 5                      2 1 2 1 2 1 2 1 2
3 4 5                      2 1 0 2 1 0 2 1 0 2 1   or  1 2 0 1 2 0 1 2 0 1 2
1 1 1 1 1 6                5 0 1 2 3 4 5           (lots of other solutions)
1 1 1 1 1 8                5 5 5 5 5 5 5 5
2 4 6 8                    3 2 1 3 2 1 3 2 1 3 2 1 3 2

This is a code-golf, so make your solutions as short as possible in your favorite language!

May as well be linked to this

@JonathanAllan and that is why I need a computer to ensure my skittle enjoyment :)

JavaScript (ES6), 177 175 bytes
a=>a.map((n,i)=>[n,l=i]).sort((a,b)=>a[0]-b[0]).reduce((P,x,i,a)=>(v=a.reduce((p,c,j)=>j<i?p:p+Math.min(c[0],x[0]+1),0))>m?[...Array(m=v)].map((_,k)=>a[l-k%(l+1-i)][1]):P,m=0)

Formatted and commented
a => a                              // given an array a:
.map((n, i) => [n, l = i])          // map it to [value, index] arrays / set l = length - 1
.sort((a, b) => a[0] - b[0])        // sort it by values in ascending order
.reduce((P, x, i, a) =>             // for each reference entry x at position i:
  (v = a.reduce((p, c, j) =>        //   for each entry c at position j:
    j < i ?                         //     if c is before x:
      p                             //       keep the previous sum (which is 0)
    :                               //     else:
      p + Math.min(c[0], x[0] + 1), //       add minimum(value[j], value[i] + 1)
    0                               //   initialize the sum at 0
  )) > m ?                          //   if the new sum v is better than our current best m:
    [...Array(m = v)].map((_, k) => //     update m to v and update the result to an array
      a[l - k % (l + 1 - i)][1]     //     of length m filled with indices picked repeatedly
    )                               //     between i and l
  :                                 //   else:
    P,                              //     keep the previous result
  m = 0                             // start with best score m = 0
)                                   // the final result is returned by the outer reduce()

Used formula
Below is a table showing how the formula F(i, j) = minimum(value[j], value[i] + 1) is working, here with i = 0 and the input [ 5, 2, 2 ].
This formula can be interpreted as follows: for each Skittle type, we can select no more than the number of the least available type plus one.
 j | Sorted    | value[j] | F(0, j) | Selected        | Output
   | input     |          |         | Skittles        | (starting from bottom left)
---+-----------+----------+---------+-----------------+-----------------------------
 0 | 2 2       |     2    |    2    | [2] [2]         | \
 1 | 1 1       |     2    |    2    | [1] [1]         |  > 0 1 2 0 1 2 0
 2 | 0 0 0 0 0 |     5    |    3    | [0] [0] [0] 0 0 | /

Test cases

let f =

a=>a.map((n,i)=>[n,l=i]).sort((a,b)=>a[0]-b[0]).reduce((P,x,i,a)=>(v=a.reduce((p,c,j)=>j<i?p:p+Math.min(c[0],x[0]+1),0))>m?[...Array(m=v)].map((_,k)=>a[l-k%(l+1-i)][1]):P,m=0)

console.log(JSON.stringify(f([ 1                ]))); // 0
console.log(JSON.stringify(f([ 4                ]))); // 0 0 0 0
console.log(JSON.stringify(f([ 4, 1             ]))); // 0 0 0 0
console.log(JSON.stringify(f([ 3, 1             ]))); // 0 1 0
console.log(JSON.stringify(f([ 5, 2, 2          ]))); // 0 2 1 0 2 1 0
console.log(JSON.stringify(f([ 2, 3, 5          ]))); // 2 1 0 2 1 0 2 1
console.log(JSON.stringify(f([ 2, 4, 5          ]))); // 2 1 2 1 2 1 2 1 2
console.log(JSON.stringify(f([ 3, 4, 5          ]))); // 2 1 0 2 1 0 2 1 0 2 1
console.log(JSON.stringify(f([ 1, 1, 1, 1, 1, 6 ]))); // 5 4 3 2 1 0 5
console.log(JSON.stringify(f([ 1, 1, 1, 1, 1, 8 ]))); // 5 5 5 5 5 5 5 5
console.log(JSON.stringify(f([ 2, 4, 6, 8       ]))); // 3 2 1 3 2 1 3 2 1 3 2 1 3 2

Are the reduce initialisations of the sum (0) and m being at the end of the "loops" golf-induced or is it just how JS is?

@JonathanAllan That's the JS way: the initial value of reduce() is located after the callback. Putting m=0 here is golf-induced, however, because I don't care about the initial value of this loop (it's going to be overwritten anyway). Initializing m there is convenient.

Ah I see it's more like a function call than a loop (like Python's reduce function has an optional initial value).

@JonathanAllan Yes, exactly. [1,2,3].reduce((x, y) => x+y, 10) in JS would be reduce(lambda x,y: x+y, [1,2,3], 10) in Python (I think), both resulting in 16.

Jelly, 22 bytes
ċÐ€ṢN
ỤṚ;\Ṛẋ"‘Ṣ$ḣ"ÇLÞṪ

1-based indexing.
Try it online!
How?
Repeats each prefix of the indexes sorted by value descending one more time than would be achievable with the given bag of skittles, then removes the final skittle or skittles from each of these as necessary to make them achievable, and returns the one with the most skittles.
The number that should be removed from one extra periodic repetition is just the number with the minimum count across that prefix.
ỤṚ;\Ṛẋ"‘Ṣ$ḣ"ÇLÞṪ - Main link                   e.g. [6,4,2,8]
Ụ                - grade up: sort indices by value  [3,2,1,4]
 Ṛ               - reverse                          [4,1,2,3]
   \             - cumulative reduce with
  ;              -     concatenation (get prefixes) [[4],[4,1],[4,1,2],[4,1,2,3]]
    Ṛ            - reverse                          [[4,1,2,3],[4,1,2],[4,1],[4]]
         $       - last two links as a monad
       ‘         -     increment                    [7,5,3,9]
        Ṣ        -     sort                         [3,5,7,9]
      "          - zip with
     ẋ           -     list repetition              [[4,1,2,3,4,1,2,3,4,1,2,3],[4,1,2,4,1,2,4,1,2,4,1,2,4,1,2],[4,1,4,1,4,1,4,1,4,1,4,1,4,1],[4,4,4,4,4,4,4,4,4]]
            Ç    - call last link (1) as a monad    [-1,-1,-1,-1]
          "      - zip with
           ḣ     - head list to (remove excess)     [[4,1,2,3,4,1,2,3,4,1,2],[4,1,2,4,1,2,4,1,2,4,1,2,4,1],[4,1,4,1,4,1,4,1,4,1,4,1,4],[4,4,4,4,4,4,4,4]]
              Þ  - sort by
             L   -     length                       [[4,4,4,4,4,4,4,4],[4,1,2,3,4,1,2,3,4,1,2],[4,1,4,1,4,1,4,1,4,1,4,1,4],[4,1,2,4,1,2,4,1,2,4,1,2,4,1]]
               Ṫ - tail                             [4,1,2,4,1,2,4,1,2,4,1,2,4,1]

ċÐ€ṢN - Link 1: head amounts (negative of skittle excess of each N+1 repeated period)
   Ṣ  - sort                                        [2,4,6,8]
 Ð€   - for each mapped over right argument
ċ     - count                                       [1,1,1,1]
    N - negate                                      [-1,-1,-1,-1]

Python3, 174 172 167 Bytes
Idea
Given e.g. 3 Red, 2 Blue, and 3 Green skittles one can arrange them in a grid, sorted by color and amount:
r g
r g b
r g b

If one tries to eat exactly i skittles, one can at least eat i*c skittles in total, where c is the number of skittles in the r-th column, e.g. for i=2 one can at least eat 6 skittles.
r g
# # #
# # #

The only thing left to do is count how many additional skittles can be eaten by an incomplete period.
Golfed
def f(a):
 r=range;f=m=0;s=r(len(a));b=sorted(zip(a,s))[::-1]
 for i in s:
  c=b[i][0];n=-~i*c+sum(c<e[0]for e in b)
  if n>m:f,m=i+1,n
 return[b[j%f][1]for j in r(m)]

Commented
def f(a):
    r = range;
    f = m = 0;                          - Some variables we need later on
    s = r(len(a));                      - Integers from 0 to (num_skittles - 1)
    b = sorted(zip(a,s))[::-1]          - Zip with s to remember initial order,
                                          then sort and reverse
    for i in s:
        c = b[i][0]
        n = (i+1)*c                     - If we attempt to eat i different skittles,
                                          we can surely eat (i+1)*c skittles.
          + sum(1 for e in b if e[0]>c) - The additional sum corresponds to an incomplete period.
        if n>m:                         - If a better way of eating skittles is found:
            f,m = i+1,n                 - update variables
    return [b[j%f][1] for j in r(m)]

Try it online!
Edit: Replaced (i+1) with -~i to save 2 bytes.
Edit: -5 bytes thanks to Dead Possum

You can change sum(1for e in b if e[0]>c) to sum(c<e[0]for e in b). It would convert True to 1 implicitly and save you 5 bytes