[Question]
  [
Skittles are colored candy where there are 5 distinct flavors; grape, green apple, lemon, orange, and strawberry represented by (p)urple, (g)reen, (y)ellow, (o)range, and (r)ed respectively. I used to eat skittles by sorting all the different colors, then eating them in sequence. After getting a few weird looks in the office, I now pretend to eat them like a normal person. Your task is to emulate this:
Your code (full program or function) will receive an array of skittles (10x10) as input (in any reasonable format). This array will represent a pile of unsorted skittles. Your task is to "eat" them from your least favorite to favorite color. My preferred order is grape, green apple, lemon, orange, strawberry, but you are free to choose any order so long as it is consistently enforced (please list your preference in your submission so I can judge you for it). After eating each piece of candy your code will output (in the same format you take input) the remaining pile with the eaten piece replaced by a space. You will repeat until only your favorite remains. You may choose any skittle to eat (may be random or deterministic). Trailing spaces must be kept.
For example, your output sequence could look like this (using 5x5 for brevity and showing spaces as `.`)
```
start   1     2     3     4     5        n 
.org. .org. .org. .org. .or.. .or..    ..r..
prgrg .rgrg .rgrg .rgrg .rgrg .r.rg    .r.r.
gggpr gggpr ggg.r ggg.r ggg.r ggg.r    ....r
oyyor oyyor oyyor oyyor oyyor oyyor    ....r
.r.p. .r.p. .r.p. .r... .r... .r...    .r...
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so shortest code in bytes wins
**TL;DR Rules:**
* Submission may be full program or function
* Input may be taken in any reasonable format (string, list, matrix, etc) by any reasonable method (STDIN, function arguments, etc.). However there must be some delineation between rows
* Output must be produced in the same format as input by any reasonable method (STDOUT, function return, ect.). Intermediate output may or may not be delimited
* First output shall be the first input
* Trailing spaces must be preserved
* Any color order may be used (list in your answer)
* Any skittle of the current color may be eaten
* Last output shall be only your favorite color and spaces
* If possible, include a link to an online compiler to test your submission
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~16 14~~ 13 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
Ṅ⁶ỤṪ$¦µQL>3µ¿
```
**[TryItOnline!](http://jelly.tryitonline.net/#code=4bmE4oG24buk4bmqJMKmwrVRTD4zwrXCvw&input=&args=IG9yZyAKcHJncmcKZ2dncHIKb3l5b3IKIHIgcCAKCg)**
Most to least favourite, as for anyone serious about their O.C.D., is alphabetical!
Takes input and outputs as text (i.e. the rows are delimited by new lines).
3 bytes saved by reversing the direction and using a different method: grade up rather than finding characters from the alphabet.
### How?
```
Ṅ⁶ỤṪ$¦µQL>3µ¿ - Main link: Skittle text
      µ    µ  - monadic chain separation
            ¿ - while
       Q      - unique items
        L     - length
         >3   - greater than 3 (until only new lines, spaces and 'g's remain)
Ṅ             -     print z and a line feed, yield z
    $         -     treat last two links as a monad
  Ụ           -         grade up (get indices of: new lines; spaces; gs; os; ps; rs; ys)
   Ṫ          -         tail (the last of those, so last y if there is one, else last r, ...)
 ⁶            -     space character
     ¦        -     apply at index (replace that index with a space)
```
[Answer]
## JavaScript (ES6), ~~74~~ ~~75~~ 74 bytes
Flavors are ordered as described in the challenge: grape, green apple, lemon, orange, strawberry.
Intermediate outputs are separated by newlines.
```
f=(s,n=3,r=s)=>(S=s.replace('oygp'[n],' '))!=s&&(r+=`
`+S)||n--?f(S,n,r):r
```
### Test case
This test case is using the 5x5 example. Any other grid size should work as expected.
```
f=(s,n=3,r=s)=>(S=s.replace('oygp'[n],' '))!=s&&(r+=`
`+S)||n--?f(S,n,r):r
console.log(f(
` org 
prgrg
gggpr
oyyor
 r p 
`))
```
[Answer]
# Bash, ~~48~~, 46 bytes
UPDATE:
* Saved two bytes by using raw parameters to printf;
**Golfed**
```
sed -nz "p;:a;`printf "s/%s/ /p;ta;" p g y o`"
```
Takes input at stdin, prints to stdout.
Eats purple, green, yellow and then orange.
An equivalent *sed* program would be:
```
p;:a;s/p/ /p;ta;s/g/ /p;ta;s/y/ /p;ta;s/o/ /p;ta
```
**Sample output** (delimiters are for clarity only)
```
-----
 org 
prgrg
gggpr
oyyor
 r p 
-----
-----
 org 
 rgrg
gggpr
oyyor
 r p 
-----
-----
 org 
 rgrg
ggg r
oyyor
 r p 
-----
-----
 org 
 rgrg
ggg r
oyyor
 r   
-----
-----
 or  
 rgrg
ggg r
oyyor
 r   
-----
-----
 or  
 r rg
ggg r
oyyor
 r   
-----
-----
 or  
 r r 
ggg r
oyyor
 r   
-----
-----
 or  
 r r 
 gg r
oyyor
 r   
-----
-----
 or  
 r r 
  g r
oyyor
 r   
-----
-----
 or  
 r r 
    r
oyyor
 r   
-----
-----
 or  
 r r 
    r
o yor
 r   
-----
-----
 or  
 r r 
    r
o  or
 r   
-----
-----
  r  
 r r 
    r
o  or
 r   
-----
-----
  r  
 r r 
    r
   or
 r   
-----
-----
  r  
 r r 
    r
    r
 r   
-----
```
[Try it online !](https://goo.gl/YxF4OT)
[Answer]
# Python 2, ~~60 57~~ 56 bytes
```
def f(s):print s;q=max(s);q>'g'and f(s.replace(q,' ',1))
```
**[repl.it](https://repl.it/EiNJ/2)**
Recursive function that eats in reverse alphabetical order, leaving the greens for last.
Input `s` is a string with a row delimiter with an ordinal less than that of a `'g'` (for example a new line or a comma).
The function prints its input, and then recurses if that input contains anything greater than a 'g', passing the input with the first occurrence of the maximum character replaced by a space.
(Almost a port of [my Jelly answer](https://codegolf.stackexchange.com/a/102342/53748).)
[Answer]
# Perl, ~~53~~ 46 + 2 = 48 bytes
Run with `-0n`
-10 bytes thanks to @Dada
*Edit: Also thanks to @Dada for pointing it out, I forgot to print the input as the first output. That's been fixed.*
```
say;eval sprintf"say while s/%s/./;"x4,p,o,g,r
```
There's a little bit of trickery involved in this answer, so I'll break down what's going on.
First of all, Perl doesn't like multi-line parameters being passed. The variable `$/` is the input record separator, and whenever any input encounters the character stored in it, the interpreter terminates that input and begins a new input. The default content is the newline character `\n`, which means that passing a multi-line string is not possible. To do that, we must unset `$/` from its contents. That's where the `-0` flag comes in: setting `-0` will store `null` in the variable `$/`, allowing the interpreter to read everything into the implicit variable `$_` at once.
The next bit of trickery is the `eval` statement. Just what exactly are we `eval`ing? We're `eval`ing the result of the `sprintf` statement, which is broken down as follows:
The first thing that `sprintf` is passed is the string `"say while s/%s/./;"` repeated 4 times, so:
```
say while s/%s/./;say while s/%s/./;say while s/%s/./;say while s/%s/./;
```
Then, `sprintf` is passed four bareword characters, `p,o,g,r`, which are interpolated into the `sprintf` statement, replacing each instance of `%s`. What we then get is the following string, which is passed to the `eval` function:
```
say while s/p/./;say while s/o/./;say while s/g/./;say while s/r/./;
```
Each `while` loop evaluates the expression `s/[color]/./`, which replaces the first instance of whatever color it is in the implicit variable `$_` with a period. If a substitution is made, it returns `1`, otherwise it returns nothing. Since `s///` has side-effects, it modifies the original variable `$_`, whose contents are then printed via `say`. Four versions of this loop are performed, replacing the purples, the oranges, the greens, and then the reds, leaving only the yellows.
The reason that the yellows are left is because `y` cannot be a bareword, because it's actually a function, and having a `y` instead of any of those letters would throw an error. I could change this by putting quotes around it (+2 bytes), or using a capital Y and making the regex case-insensitive (+1 byte), but for [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), every byte counts, so I decided that I actually *like* lemon skittles the most.
TL;DR: `Grape, Orange, Green Apple, Strawberry, Lemon`
[Answer]
# Perl, ~~30~~ ~~31~~ 33 + 2 = ~~32~~ ~~33~~ 35 bytes
```
for$x(g,o,p,r){say;s/$x/ /&&redo}
```
Run with `-n0` (2 byte penalty).
Apparently, I like to eat Skittles in alphabetical order, because the program turns out shorter that way. The program doesn't really need much explanation: `-n0` reads the input implicitly (`-n` means "read input implicitly", `-0` means "don't break input on newlines"); `for$x(g..r)` runs a loop with `$x` set from each letter from `g` to `r` in turn; `say;` prints the current input, after any mutations; `s/$x/ /` replaces one copy of `$x` (specifically, the first) with a space if possible; and `&&redo` repeats the code inside the braces (without advancing the loop counter) if the replacement was successful.
This program can easily be generalized to more flavours of Skittle without changing its length, and will work with a pile of any size.
[Here's an Ideone link where you can test it.](http://ideone.com/EGa30Y) (Ideone doesn't allow you to specify command-line options, so I had to add a couple of lines at the start to set `-n0` and the `-M5.010` that you get for free.)
[Answer]
# C#, ~~134~~ 148 bytes
Order: `G -> O -> Y -> P -> R`
```
I=>{var v=new string(I)+";\n";int i,j=0,c;for(;j<4;){c="goyp"[j++];for(i=0;i<I.Length;i++)if(I[i]==c){ I[i]='.';v+=new string(I)+";\n";}}return v;};
```
Used some similar things from @Poke's answer, currently a bit longer though since I need to convert the character array to a string ;(
[Answer]
# Java 7, ~~139 135 130 151 138~~ 135 bytes
```
void t(char[]s){int i,j=-1;for(;++j<5;)for(i=-1;++i<109;)if(j>3|s[i]=="yogp!".charAt(j)){System.out.println(s);if(j>3)return;s[i]=32;}}
```
Eats skittles in the order: Yellow, Orange, Green, Purple, Red
I guess this is better than 2 print statements >.>
[Answer]
# C 145 - 5 - 18 - 1 = 121 bytes
```
#define l(a)for(a=0;a<10;a++)
i,j,k,b='a';F(char a[][11]){while(b++<'x')l(i)l(j)if(a[i][j]==b){a[i][j]=32;l(k)puts(a[k]);puts("");}}  
```
### ungolfed + pretty
```
#include<stdio.h>
#include<windows.h>
i,j,k;
F(char a[][11])
{
    char b='a';
    while(b++<'x')
        for(i=0;i<10;i++)
            for(j=0;j<10;j++)
                if(a[i][j]==b)
                {
                    system("cls");
                    a[i][j]=32;
                    for(k=0;k<10;k++)
                        puts(a[k]);
                    puts("");
                    Sleep(35);
                }
}
main()
{
    char a[][11]={
            "gggggggggg",
            "goooooooog",
            "goppppppog",
            "goprrrrpog",
            "gopryyrpog",
            "gopryyrpog",
            "goprrrrpog",
            "gopppppppg",
            "goooooooog",
            "gggggggggg"
    };
    for(i=0;a[i][j];)
        puts(a[i++]);
    F(a);
}  
```
Here `a[][11]` means taking n-strings of length 11 where 1 char is required for termination so, technically only 10 visible chars.
**order : alphabetical**  
this function checks for `'g'` in the given input and eliminates it 1/1 then increments the variable holding `'g'` until it finds a next match(probably letter `'o'`) and then eliminates those matched characters.  
The downside is that this function is just too careful.So, if your skittels were of `26` different colors code-named from letters a-z, this function will handle that input too...
[Answer]
# Octave, 49 bytes
Eats skittles in alphabetical order, highest ascii-code first.
```
A=input("");do [~,p]=max(A(:));A(p)=32 until A<33
```
[Answer]
# ES6 (Javascript), ~~72~~,71 bytes
EDITS:
* Minus 1 byte, by using template literal with *of*
A non-recursive version in Javascript.
**Golfed**
```
s=>{r=s;for(c of`pogy`)while(s!=(s=s.replace(c,' ')))r+=`
`+s;return r}
```
Input and output are multiline strings, eats pills in the "purple=>orange=>green=>yellow" order.
**Test**
```
S=s=>{r=s;for(c of`pogy`)while(s!=(s=s.replace(c,' ')))r+=`
`+s;return r}
console.log(
S(` org 
prgrg
gggpr
oyyor
 r p `)
);
```
[Answer]
# Python 3 - ~~141~~ ~~99~~ 75 bytes
```
s=input();[exec("print(s);s=s.replace(c,' ',1);"*s.count(c))for c in'orgy']
```
Program eats skittles in this order - `Orange Red Green Yellow Purple`.
**Edit** - Thanks to [Flp.Tkc](https://codegolf.stackexchange.com/users/60919/flp-tkc) who helped to cut down 24 bytes!
```
Input - 
ygro  goppr rppog rppog orgy
Output - 
ygro  goppr rppog rppog orgy
ygr   goppr rppog rppog orgy
ygr   g ppr rppog rppog orgy
ygr   g ppr rpp g rppog orgy
ygr   g ppr rpp g rpp g orgy
ygr   g ppr rpp g rpp g  rgy
yg    g ppr rpp g rpp g  rgy
yg    g pp  rpp g rpp g  rgy
yg    g pp   pp g rpp g  rgy
yg    g pp   pp g  pp g  rgy
yg    g pp   pp g  pp g   gy
y     g pp   pp g  pp g   gy
y       pp   pp g  pp g   gy
y       pp   pp    pp g   gy
y       pp   pp    pp     gy
y       pp   pp    pp      y
        pp   pp    pp      y
        pp   pp    pp  
```
I believe it can be further golfed as it looks very simple.
[Answer]
# Vim ~~57~~ 55 bytes
Saving two bytes by removing my line delimiter. Unfortunately it makes it a lot harder to read and check for correctness :(.
```
:set ws!
yGP/o
qqnr G9kyGGp@qq@q/y
@q/p
@q/g
@qdG
```
Unprintables:
```
:set ws!
yGP^O/o
^Oqq^Hnr G9kyGGp@qq@q/y
^O@q/p
^O@q/g
^O@qdG
```
[TryItOnline](http://v.tryitonline.net/#code=OnNldCB3cyEKeUdQDy9vCg9xcQhuciBHOWt5R0dwQHFxQHEveQoPQHEvcAoPQHEvZwoPQHFkRw&input=IG9yZyAgb3JnIApwcmdyZ3ByZ3JnCmdnZ3ByZ2dncHIKb3l5b3JveXlvcgogciBwICByIHAgCiBvcmcgIG9yZyAKcHJncmdwcmdyZwpnZ2dwcmdnZ3ByCm95eW9yb3l5b3IKIHIgcCAgciBwIA)
Eats in the order oypg, leaving all of the r's for the end :)
[Answer]
# Mathematica, 67 bytes
```
Most[#/.(i=0;#:>"."/;i++≤0&/@Characters@"ryop")&~FixedPointList~#]&
```
Eats reds, then yellows, then oranges, then purples.
[Answer]
# Java 7, 125 bytes
Purple, Yellow, Green, Red, Orange. I'm enjoying that I get to pick my order in this solution. :D
## Golfed
```
String s(String p){String r=p;for(String c:"pygr".split(""))for(;p.contains(c);r+="\n\n"+p)p=p.replaceFirst(c," ");return r;}
```
## Ungolfed
```
String s(String p) {
    String r=p;
    for (String c : "pygo".split("")) {
        for (; p.contains(c); r += "\n\n" + p) {
            p = p.replaceFirst(c, " ");
        }
    }
    return r;
}
```
[Try it here!](http://ideone.com/8GYE37) 
A different approach to the other Java answer by @Poke. We start by making a copy of the original string. Iterating through each color, we replace it each time it's found with a space, then append the new layout to the output string, returning after we've eaten everything but orange.
## Notes
Seperation between steps is done with a double newline `\n\n`, but if the input grid can be taken with a trailing newline at the end, it can be shorted to just `\n`.
[Answer]
## Haskell, 60 bytes
```
f x|(a,b:c)<-span(<maximum x)x,b>'g'=(:)<*>f$a++' ':c|1<2=[]
```
Input is a single string where the rows are separated with `,`. Return value is a list of strings with all intermediate steps. Order is alphabetically, largest first, so green remains. Usage example:
```
*Main> mapM_ putStrLn $ f " org ,prgrg,gggpr,oyyor, r p "
 org ,prgrg,gggpr,o yor, r p 
 org ,prgrg,gggpr,o  or, r p 
 o g ,prgrg,gggpr,o  or, r p 
 o g ,p grg,gggpr,o  or, r p 
 o g ,p g g,gggpr,o  or, r p 
 o g ,p g g,gggp ,o  or, r p 
 o g ,p g g,gggp ,o  o , r p 
 o g ,p g g,gggp ,o  o ,   p 
 o g ,  g g,gggp ,o  o ,   p 
 o g ,  g g,ggg  ,o  o ,   p 
 o g ,  g g,ggg  ,o  o ,     
   g ,  g g,ggg  ,o  o ,     
   g ,  g g,ggg  ,   o ,     
   g ,  g g,ggg  ,     ,     
```
Simple recursion. Save the input list in for the return value, replace the largest element greater `g` with a space and call the function again. Base case is when there's no element left to remove.
[Answer]
# MATL, 24 bytes
```
`tDX:t2#X>wx32w(10etun2>
```
[Try it online!](http://matl.tryitonline.net/#code=YHREWDp0MiNYPnd4MzJ3KDEwZXR1bjI-CgonLS0tLS0tLS0tLSdEICUgRGlzcGxheSBkZWxpbWl0ZXIuIE5vdCByZXF1aXJlZCBieSBjaGFsbGVuZ2Ugc3BlY3Mu&input=WydycCAgZyB5cm95JzsneSBvb3Jwb2dvZyc7J3BvcHl5eXJwcnknOydwb2d5Z29ncGdwJzsnb3lncCBvZyB5byc7J3kgcnJ5cnAgbyAnOydwcHJvcm9nIHlwJzsncm95IHJwZ3lvcic7J2dncmdwciB5cm8nOycgcnByIGd5cHB5J10) I prefer eating my skittles in reverse alphabetical order: green is my favourite colour. Explanation:
```
                           % Take input implicitly.
`                          % Start do ... while loop
 tD                        % Duplicate skittle pile (nom!), but give away for display
   X:                      % Put skittles in long row (like normal people do)
     t2#X>                 % Get least favourite skittle name and number in the row
          wx               % Discard the skittle name
            32w            % Put an eaten skittle on the stack (ASCII 32)
               (           % Put the eaten skittle back in the row of skittles.
                10e        % Shape the row back into a 10x10 array
                   tun     % Check the number of unique skittles
                      2>   % Loop while this number >2 (eaten skittles + favourite skittles)
                           % Implicit end of do... while loop. 
                           % Display last iteration implicitly, since it's still on the stack.
              
```
[Answer]
# QBasic, 125 bytes
Creative rules abuse!
```
DATA 71,89,82,79
?INPUT$(109)
DO
READ s
FOR r=1TO 10
FOR c=1TO 10
IF s=SCREEN(r,c)THEN SLEEP 1:LOCATE r,c:?" "
NEXT
NEXT
LOOP
```
This submission assumes a lot of things are okay:
* Input and output are uppercase (`GORPY`)
* Input is taken as 109 successive keypresses, which are not echoed to the screen until the last one is entered. At the end of each row except the last one, the user must enter a carriage return.
* Instead of printing the Skittles pile multiple times, the program displays it on the screen with a 1-second pause before each step. (QBasic doesn't have output scrollback, so printing the pile multiple times would only give you the last 2 1/2 steps. Also, this method is a much better depiction of how your pile of Skittles evolves as you eat them.)
* The program ends with an error.
I also have a 130-byte version that uses lowercase and doesn't error.
Here's a sample run in [QB64](http://qb64.net), with `109` changed to `29` for a 5x5 grid:
[![Eating Skittles](https://i.stack.imgur.com/5gBwb.gif)](https://i.stack.imgur.com/5gBwb.gif)
### Explanation
`DATA 71,89,82,79` stores the ASCII codes of `G`, `Y`, `R`, and `O`.
`?INPUT$(109)` gets 109 keypresses from the user and prints them.
We then enter an infinite `DO ... LOOP` construct. Each time through, we `READ` the ASCII code of the current Skittle into `s`. Then we loop over rows and columns from 1 to 10. `SCREEN(r,c)` gets the ASCII code of the character on the screen at row `r`, column `c`. If this is equal to the current Skittle `s`, we `SLEEP` for one second and then print a space at `r`, `c`.
The main loop runs four times, removing the green, yellow, red, and orange Skittles. On the fifth iteration, `READ` errors because we're out of data.
]