user
Task

Implement a **CopyPasta Language** interpreter or compiler. These are the commands used by CopyPasta Language:

| Command | Description |
| --- | --- |
| `Copy` | Copy the text of the following line to the clipboard |
| `CopyFile` | Copy the text of the file cited in the following line to the clipboard or in the case where the next line is TheF\*ckingCode copies the code to the clipboard |
| `Duplicate` | Duplicate the text in the clipboard as many times as the following line specifies |
| `Pasta!` | Display the clipboard and stop the program |
assistant
(formerly Perl 6)

```
sub CopyPasta ($code) {
    my @code = $code.split("\n")>>.trim.grep: *.so;
    return "Program never ends!" unless grep { $_ eq 'Pasta!' }, @code;

    my @cb;
    my $PC = 0;
    loop {
        given @code[$PC] {
            when 'Copy'      {        @cb.push: @code[++$PC] }
            when 'CopyFile'  { $PC++; @cb.push: @code[$PC] eq 'TheF*ckingCode' ?? @code !! slurp @code[$PC] }
            when 'Duplicate' {        @cb = (flat @cb) xx @code[++$PC] }
            when 'Pasta!'    { return @cb }
            default          { return "Does not compute: @code[$PC]" }
        }
        $PC++;
    }
}

spurt 'pasta.txt', "I'm the pasta.txt file.";

(say $_ for .&CopyPasta; say '')
    for
    "Copy \nRosetta Code\n\tDuplicate\n2\n\nPasta!\nLa Vista",
    "CopyFile\npasta.txt\nDuplicate\n1\nPasta!",
    "Copy\nInvalid\n Duplicate\n1\n\nGoto\n3\nPasta!",
    "CopyFile\nTheF*ckingCode\nDuplicate\n2\nPasta!",
    "Copy\nRosetta Code\nDuplicate\n2\n\nPasta";

unlink 'pasta.txt';

```

Output:

```
Rosetta Code
Rosetta Code

I'm the pasta.txt file.

Does not compute: Goto

CopyFile TheF*ckingCode Duplicate 2 Pasta!
CopyFile TheF*ckingCode Duplicate 2 Pasta!

Program never ends!
```