text:
yes is 91 lines long
yes, from coreutils, is 91 lines long. Many of them are comments, but that is still WAY too long.
Edit from September 2019: the source file grew over the past five years and is now 126 lines long.
Write a program that imitates yes:

outputting to stdout an infinite stream of "y\n"'s
there must be an option to stop it other than killing the process with SIGKILL: but SIGINT and SIGPIPE are fine
you are not allowed to use "y" or "\n" or their ASCII values (121, 0x79, 0171, 10, 0xA or 012)

Shortest answer wins.
Bonus:

subtract 10 from your code length, if you can receive a phrase in stdin and print it out instead of "y" (but still including the line-break). The program doesn't have to print y on an empty input.

For the bonus, should it still print y for empty STDIN?

"you are not allowed to use "y" or "\n"" -- should I read this as "You may not use y or \n inside of a string literal"?

@MartinBüttner Optionally.

@apsillers In the source code, nothing that evaluates to y or \n. Not in a literal, not as a constant, not as a variable name. Nothing.

@RamonSnir Wait, so I can just print empty lines for empty STDIN if I go for the bonus?

This is impossible in Java, without using System

@Ypnypn Here's my best guess: Perhaps a rule of thumb might be "if a source-code token has a y in it, you must be able to replace it with a synonymous token without a y." For example, if you have System.out.print("y"), you can do something like Sstem = System and Sstem.out.print would work fine (at least conceptually). By contrast, if you replace the literal  "y" with something else, you're not going to get the same result. I think this should probably clarified in the spec.

On a related note, GNU true.c is 80 lines long.

@Ypnypn It is possible. There are more ways than one to get System.out.

@TheBestOne Indeed; I just solved this with reflection.

@DennisWilliamson On a similarly related note, false.c is 2 lines long.... ;_;

Is providing output in a different character encoding permissible (eg. using PETSCII rather than ASCII-1967)?

@RamonSnir Just to be sure, is my C# answer valid? It uses System (which I cannot get rid of, because it's the top namespace and everything is in it), but in your previous comment you said "nothing that evaluates to y". It does not evaluate to y. Is that answer valid?

@Ypnypn I just solved this without reflection.

the coreutils yes takes an optional argument on the command line, not stdin.

@RamonSnir and I started this after git cloneing coreutils and getting angry that ls is 8000 lines long. This post is all about getting candidates for replacing the "bloated" coreutils :)

@DennisWilliamson: Let me introduce you to GNU Hello

@NateEldredge: I call foul though since that's an example program and not a standard utility. ;-)

@RamonSnir "Nothing that evaluates to y or \n" would make the challenge impossible. Please clarify what you mean.

I don't get GNU: Why would you possibly need a program which spams you with ys?

@MrLore: to pipe into other programs that might constantly ask for confirmation of the various things they are doing, so you dont have to sit there typing the ys yourself.

OMG there's no \n at the end of the file O_o that's horrible!

@mrl i regularly do yes | sudo pacman -Syu because i'm a terrible person

@undergroundmonorail the whole story started when I did alias aurauy="yes | ( aura -Suy && aura -Auy )" :)

There are lots of answers which use 121 + 1 to get y's ascii code. Are those invalid? Can I have newlines outside string literals?

Microsoft, 1 Steve Ballmer — developers, developers, developers, developers, ...

How do you get to 91 from that page while counting comments? I see 130.

@FabianRöling This question is from 6 years ago. Back then it was 91 but since then the file grew up to 130 lines long.

CJam, 13 bytes - 10 = 3
l_'x)?{_oNo}h

You'll need to use the Java interpreter for this, because the online interpreter only returns once the program terminates.
You can abort the program with SIGINT (by pressing Ctrl-C). It will read a line from STDIN, and print that line, or y if the input was empty.
Explanation
l             "Read line from STDIN.";
 _            "Duplicate.";
  'x          "Push character x.";
    )         "Increment to get y.";
     ?        "Ternary operator. Replaces line with y if it was empty.";
      {    }h "Repeat while true. Leaves condition on the stack, which is the output string.";
       _o     "Duplicate line and print.";
         No   "Push string with newline and print.";

After clarification of the OP, the following seems more to spec:
l{_o9c)o1}g

I'll wait with updating the submission until the OP replies to my comment, though.

I like that your program happens to match /no/i, considering what the challenge it.

Brainfuck - 38 bytes
++++++++++[>++++++++++++>+<<-]>+[.>.<]

It doesn't use 10 or 121, because +-<>.,[] are all the meaningful characters in the language anyway, but it does calculate them pretty naively (0+1+1+1+1+1+1+1+1+1+1=10, 10*12+1=121).
This probably depends on the interpreter, but it dies to ^C on my machine.
Brainfuck - (63-10)=53
++++++++++[>,]<<[[<]>>[[.>]<[<]>]]>[>++++++++++++>+<<-]>+[.>.<]

@fry I couldn't get it below 39 that way. I need 10 anyway, so I'm either adding 1 to 120 or subtracting 1 from 11, and it's shorter to do the former.

Yeah, I noticed after that you reused the 10, sorry :P

Instead of 1012+1, why not 1111? I think that could save you a char.

@pro I couldn't get it below 39 that way. I need 10 anyway, so I'm either adding 1 to 120 or subtracting 1 from 11, and it's shorter to do the former.

@undergroundmonorail Ah, I see.

Python 3, 27 bytes
Works with at least CPython and Jython.
while 1:print(str(help)[1])

SIGINT stops it.

Make it python2 and you can shorten it to while 1:print\help`[1]`.

Haha, nice. I completely forgot that there "used to" be a backtick operator in python :)

You could use chr(11**2) to save a few characters as well

@RamchandraApte You're not allowed to use 121.

Why does this output y's?

@user1354557 "help" in python return: "Type help() for interactive help, or help(object) for help about object." so the second character (index 1) is "y"

Pyth, 10 9 6 bytes - 10 = 0 -1 -4
#|zePG

I've been trying for ages to get one that I'm satisified with.  Basically converts to:
#      = while True
(implied print)
|      = or
z      = (automatically initialized from stdin)
ePG    = second-to-last lowercase letter = 'y'

The "z" variable is initialized from stdin, then the value is simply used after that.  Found a short way to get the ascii value without writing it explicitly.

Switched from "^11 2" to "^hT2" to save a character.

Hi swstephe, I'm excited to see another user of the language! A couple of golfs: # has equivalent functionality to W1, and ePG is a much shorter way to get the character y than C^hT2.

Thanks, I'll apply those changes.  Still new at this golf thing.  I like Pyth, but wish had a few more contextual functions and bit manipulation.

Marbelous 14 bytes
0978
]]/\++
!!

This is pretty straightforward, the '/\' device places two copies on its left and right, the right one is incremented by ++ and then falls off the board and is printed. The ]] device pushes any marble to the right if STDIN is empty but lets the first byte on STDIN fall down if it isn't. This will then trigger the !! device, which exits the board. So this will print y\n until you enter anything on stdin.
This only works in the python interpreter.

C#, 81 78 76 bytes
Cannot compete with the other languages, but here it is anyway:
class A{static void Main(){for(;;)System.Console.WriteLine((char)('x'+1));}}

Can be killed with SIGINT by pressing Ctrl+C.
No bonus, because it would take more than 10 bytes to get it.

Can't you use while(1)? Saves two characters.

@toothbrush I have tried that, but that doesn't work in C#.

for(;;) should work.

How about class A{static void Main(string[]a){for(;;)System.Console.WriteLine(a[0]);}}? It requires input, but it classifies as 63 bytes!

@core1024 Thanks, that works!

@toothbrush Good idea, but the question says that input should be given through STDIN, not command line.

@ProgramFOX I didn't realise.

How about 'x'+1 instead of 'G'+'2'? Two bytes less.

@tomsmeding That works, thanks!

For some reason, this code still has a y in it. Please examine System.

@TheBestOne That System cannot be removed. it is the top namespace in the .NET Framework, all classes/other namespaces are in it, so reflection won't help here. But not sure if it's invalid. See Ramon's comment: "nothing that evaluates to y or \n". This does not evaluate to y. I'm leaving a comment on the question to ask Ramon whether this is valid.

Java, 178
class C{public static void main(String[]a)throws Exception{for(char c='x'+1;;)((java.io.PrintStream)Class.forName("java.lang.S"+c+"stem").getField("out").get(null)).println(c);}}

Printing requires System, but the y character is forbidden. Hence, I had to use reflection.

FileDescriptor.out is what I meant.

You can save a ; by putting char c='x'+1; into the for loop declaration, so for(char c='x'+1;;) since you have an empty semicolon in there anyway

@corsiKa Good point.

Perl: 18 bytes - 10 = 8
The string is from STDIN.
$_=<>;{print;redo}

Does it print y\n repeatedly if it doesn't receive input from STDIN? If not, then it doesn't properly imitate yes.

@vurp0 yes does not take input from STDIN after all :)

It doesn't, but the code golf question here specified that if it doesn't receive input, it should repeatedly print y\n.

@vurp0 Where? Any program that reads from a stream will hang without input.

@vurp0 See the OP's comment on the question.

Ruby, 30 23 18 bytes
loop{puts ?x.succ}

Can be killed with SIGINT by pressing Ctrl+C.
Thanks to manatwork for sharing improvements!

loop{puts [*?x..?z][1]} – 23 chars, loop{puts ?x.succ} – 18 chars

@manatwork Thanks! Updated.

Perl, 26 bytes
{print chr$=*2+1,$/;redo}

Custom input from argument (like yes actually works), 22 bytes-10=12
{print @ARGV,$/;redo}

Custom input from stdin, 22 bytes-10=12
while(<>){print;redo}

@mar Nitz's program is only 14 bytes long and there's a very highly upvoted comment on your link that says it's chill for filenames to matter if you include them in the bytecount. This seems legit to me.

oh wait, i didn't see the "you can't use "y"" part of the question. nevermind this is bad

Right you are. Fixed it

Linux Bash - 19 bytes
This is probably cheating and subject to failure if you don't have /usr/bin/yes or have a /usr/bin/xes or /usr/bin/zes:
/usr/bin/[x-z]es $*

I think it meets the requirements, though maybe it's violating the "nothing that evaluates to y" rule. And perhaps  imitating yes by actually running yes is against the rules.
This could be optimized a bit (though less likely to work) to take it down to 11 bytes:
/*/*/?es $*

I couldn't figure out how to get the 10 point bonus by reading a string from stdin without adding more than 10 bytes to the code

/*/*/?es `line` , or /*/*/?es `head -n1`  if you don't have /usr/bin/line.

Or sed q for line.

C, 64 55 53 45 40 - 10 = 30
main(int c,int**a){for(;;)puts(a[c>1]);}
I'm not hugely happy with this, as it requires the program to be named "y", and to be called with `y` only, so it has to be in $PATH, but hey, first codegolf :)
Alternative:
C, 30 (+ 1 filename)
main(){for(;;)puts(__FILE__);}
Using the same technique as my esteemed colleague @Matt Windsor

EDIT: turns out getting round the no \n character made it shorter
EDIT2: "int" is shorter than "char"
EDIT3: didn't need that variable at all
EDIT4: a bit of slightly undefined behaviour never hurt anyone
EDIT5: add alternative version

dc, 12
[30986Pdx]dx

Only outputs y\n.  Doesn't read from stdin, so no bonus.
30986 is 0x790A (i.e. "y\n").  The P command simply converts the number to base 256, and prints the corresponding character for each base 256 digit.

That's pretty clever, how does 30986 evaluate to y\n?

I knew about P but didn't know it can do more than one character at a time.

Common Lisp : (30-10) = 20
(format t"~@{~a~%~:*~}"(read))

(read) from input stream
print to output stream: (format t ... )
iterate over all format arguments (only one here) : ~@{ ... ~}
inside the loop, for each argument:

print argument ~A followed by a newline ~%
rewind current element to the previous one ~:* (infinite loop)

You can break the loop with Ctrl+C, which signals an error with restart options (continue/abort).

Linux Bash, 33-10 = 23
read a; while :; do echo $a; done

Can be killed with SIGINT by pressing Ctrl+C.

You should read only one line and print the same line repeatedly. Your programs are not yes but cat programs.

My bad, I should not have tried it after à day of work.

How about read a;for((;;));{ echo $a;}

Rust, 52 chars
fn main(){loop{println!("{}",'Y'.to_lowercase())}}

There just isn't seemingly a nice way of computing y without being cheeky in Rust-- they've made too good a job of doing chars safely.  I:

Can't supply a non-literal string to println!, so no tricks allowed there;
Can't add 1 to 'x', because in Rust chars aren't numbers;
Can't ROT13 (why doesn't Rust have ROT13 in its standard library!?);
Can't easily do anything unsafe like dropping to C strings, converting from numbers to chars, etc without being incredibly verbose and going over 52c.

Nor is going for the code bonus worth it, because reading from stdin would require error handling =3
Much of the code reductions I could find involved doing increasingly rule-flouting things with the compiler environment:
Rust, 44 chars (+ at least 1 char for filename)
fn main(){loop{println!("{:.1}", file!())}}

Obsoleted by below. This one probably doesn't count, as the name of the source file needs to begin with y.
Edit: Rust, 36 chars (35 source, 1 filename)
fn main(){loop{println!(file!())}}

As above, but the file has to be called y (not y.rs, y).  Humorously, Rust will overwrite the source with the binary!  At least on my machine, the binary does work after that though.
Rust, 37 chars (+ equivalent of env K='y' on your platform)
fn main(){loop{println!(env!("K"))}}

This one is even worse: you need to set the environment variable K to y at compile time.
Edit: if you set K to y\n, you could drop the ln in println!, for a grand total of 35 chars and several facepalms:
fn main(){loop{print!(env!("K"))}}

Our usual policy for requiring certain file names or compiler flags is to simply include those in the byte count.

@MartinBüttner Fair enough.  Oddly enough, it would seem that rust isn't the best language for code golf >:P

You can add one to x in a fashion, but it's still not short: (b'x' + 1) as char

Commodore 64 Basic: 14 13 bytes
1?C|(11↑2):R╭

As usual, I've made substitutions for characters in PETSCII that are not present in Unicode.  | is used to represent SHIFT+H, while ╭ represents SHIFT+U.  Note that this outputs ASCII 'y' (byte value 121) rather than a character that the default Commodore character set displays as 'y'.
BASIC is supposedly an easy-to-learn, English-like programming language.  Throw in the typing shortcuts present in many early dialects, and you get something that is shorter and less readable than Perl.
EDIT: In "shifted mode", this gets two bytes shorter, thanks to lowercase "y" being encoded at decimal value 89.  Using a non-ASCII character set to get around the "not allowed to use their ASCII values" rule might be cheating, though.
1?cH(89):rU

With all the  that exists in unicode, it seems surprising that the full character set used by the C64 wouldn't be in there somewhere.

@kasperd, Unicode's box-drawing characters come mostly from the IBM "DOS" set, and pass through the center of the character cell.  PETSCII has a much larger set, much of which uses the edges of the character cell.  U+2502 is probably a decent approximation of the vertical bar produced by SHIFT+H, but the pipe character is easier to type.  There's nothing corresponding to the "lines on the top and left edges" produced by `SHIFT+O".

Very good, but you could save one byte by replacing "Goto 1" by "Run" : "1?cH(89):rU"

@LeFauve, Thanks.  I've also applied it to the ASCII-emitting version.

Fission, 5 bytes
Rx+!N

This is fairly competitive for Fission. :)
Control flow starts with a (1,0) right-going atom at R. x sets the mass to 120, and + increments it to give (121,0). Then ! prints the corresponding character (y) and N prints a newline. The source code wraps around at the edges, so the atom passes R again (which doesn't do anything now), x sets the mass to 120 again, + increments it and so on and so on...

AWK, 38 bytes
BEGIN{for(;;)printf("%c%c",60+61,5+5)}

Variant which will read the string on stdin: 14 bytes-10 = 4
{for(;;)print}

But since it cannot do both (revert to "y" if no stdin is provided), I'm not sure it counts... :o)
Both can be exited with Ctrl+C.

Ruby, 27 bytes - 10 = 17
It's just @ProgramFOX's solution with the bonus (it took my 9 bytes to solve the bonus question).
loop{puts ARGV[0]||?x.succ}

Haskell, 29 bytes
main=putStrLn[succ 'x']>>main

I believe this is stopped by both SIGINT and SIGPIPE.

suggestion: use '\89' instead of succ 'x'

dc, 21 bytes - 10 = 11
C1st?st[ltP[]ps0dx]dx

Note that the input needs to be wrapped in [], e.g. [no], because ? is the only way to take input, which executes it as dc code.

You can use C2 instead of 122.  In fact I would argue that 122 1- could be replaced with C1 as C1 is not explicitly banned in the question

C, 32 bytes
Requires little endian machine and compilation with -O2 (to avoid stack overflow).
a=11*11;main(){main(puts(&a));}

Perl, 31
Here is a Perl version that actually behaves like GNU yes, as far as I can tell:
{print "@ARGV"||chr 11**2;redo}

This works if it is okay to use perl's command line switches (-l for the newline), otherwise it would become 3 characters longer:
{print "@ARGV"||chr 11**2,$/;redo}

typo: is -l (not -e) the switch for the new line.

Also, the bonus is only if your script can read from the stdin. Yeah, I know that real yes does not read from the stdin, but from an argument, but that is the rule of the OP put; it has to be from stdin to have the bonus.

@chris-l fixed the type, thanks.  I also removed the claim regarding the bonus, but I will leave my answer as it is :-P

hehe sure, my own answer is like yours; it uses an argument instead of stdin. IMHO, the op should give the bonus to the ones who actually do what the real yes does.

Javascript, 39 37 bytes
for(;;)console.log(''+Function()[13])

Shorter alternative that only works in the browser, 36 bytes
for(n=''+crypto;;)console.log(n[10])

Alternative without console.log, only works in NodeJS, 58 57 56 bytes
for(n=''+Function()};;)process.stdout.write(n[13]+n[19])

Welcome to code golf, and nice answer!

@RedwolfPrograms Thanks!

Your second answer uses y in crypto!

@Matthew Jensen Indeed it does!

PowerShell, 27 − 10 = 17
param($s=$Host[1])for(){$s}

Might not work in Pash. A more robust alternative should be
param($s="$(gal gh*)"[2])for(){$s}

Lua, 42 bytes - 10 = 32
while 1 do print(...or('').char(90+31))end

Lua, 49 bytes - 10 = 39
y=...or(string.char(60+61))while 1 do print(y)end

Both were tested with Lua 5.1.4 and can be killed with SIGINT (Ctrl+C).

Awesome! My mom writes in Lua, I've never seen it in the wild before. (Hey mom! Guess what I saw!)

Fortran, 28
do1;1 print'(A1)',11**2;end

Compile with gfortran -ffree-form.

APL (Dyalog APL), 5 - 10 = -5 bytes
Warning: relies on an undocumented and unsupported feature/bug.
⎕←⍣≢⍞

Empty STDIN prints empty lines (not "y"), which is allowed and has been suggested.
Try it online!
⎕ STDOUT with trailing newlines,
← gets
⍣ repeatedly until
≢ it differs from
⍞ STDIN
i.e. never, but uninterruptible by pausing the thread.

Hmm. abusing bugs.. interesting.

@MatthewRoh Using, not abusing. The "feature" is using the operator ⍣ on assignment ←, even though ← isn't a real function proper, and thus not really eligible to be an operand. Still works through...

Ahead, 8 bytes
~W-1z'N~

Try it online!

i fixed it :)))

W s, 1-10 = -9 bytes
I

Explanation
Flag: s % We have to read from STDIN :(
 P      % Newline-print
a       % the STDIN input
  I     % Forever

W, 7 bytes
i12 1CE

Explanation
i     E % Foreach from 1 to positive infinity:
         % (Implicit print a newline on each iteration)
 12 1    % Space does nothing. Basically just pushes 121.
     C  % Convert to a character, rendering 'y'

Never thought I'd see a negative score.

@PkmnQ I'm going to make this score -9.

Ties your other answer in Husk.

@a'_' You're not allowed to use 12 1: "Not in a literal, not as a constant, not as a variable name. Nothing."

Zsh + POSIX utilities, 22 bytes
f()(tr 01 x-z<<<1;f);f

Thanks to pxeger for the shorter way to print y.
Try it online!
Pure zsh, 24 bytes
f()(<<<$SPROMPT[29];f);f

Try it online!
Bonus: mandatory phrase from stdin — 21 - 10 bytes
read a;f()(<<<$a;f);f

Try it online!

Shorter way to print y: tr 01 x-z<<<1

Zsh, 14 bytes
x=Y;<<<$x:l;$0

Try it online!
Set x=Y, then print $x, :lowercased. $0 recurses.

Python 3, 25 bytes
while 1:print(chr(97|25))

Try it online!

Apparently this isn't totally portable. My sys.version is 2.7.9 (default, Dec 11 2014, 04:42:00) \n[GCC 4.9.2], so if yours is different this might not work I guess.
Python 2 - (76-10)=66
import sys
s=sys.stdin;a=`help`[1]if s.isatty()else s.read()
while 1:print a

Pretty long, but I wanted to go for the bonus (even though it cost more than 10 bytes). Checking if stdin is empty or not without prompting for input is long, apparently.
At first, I misread the bonus as taking an argument instead of stdin. I'm proud of my solution for that, so I'm posting it anyway ;)
Python 2 - (52-10+∞)=∞ (invalid!)
import sys
while 1:print(sys.argv+[0])[1]or`help`[1]

sys.argv is a list where the zeroth element is the filename and every element afterwords is an argument given to the program. I add a falsey value to the end of the list; if there are no arguments, the first element is that falsey value, otherwise it's the first argument. a or b in Python returns the first value that confirms what the outcome will be: If a is truthy, we already know that the whole thing will be true, so it just gets returned. If it's false, b is returned (since False or b == b).

@fry I could, but it would prompt the user. I wanted it to start spitting out y\n immediately if stdin was empty.

@fry That's weird, it works for me. It might be dependant on cPython? I don't have any other ideas.

good idea, on it

r=raw_input();p=r if r else\help`[1]\nwhile 1:print p`
52 characters

Hmm, already the first line seems to have an y in it, the second one too.

Plan 9 rc: 20-10=10 (but not quite there)
f=`{cat};while()echo $f

The problem with this almost-solution is that it must have something on stdin.  I haven't yet been able to find a way to get it to print y if stdin isn't there.

Windows Batch: 24 bytes
A yes.bat file with this content will work on most Windows XP and later systems with default settings:
@echo %COMSPEC:~12,1%&%0

Else this slightly larger yes.bat file (34 bytes) will work in all cases:
@set "T=%~n0"
@echo %T:~0,1%
@%0

Can be made down to 13 bytes if the file is called y.bat instead of yes.bat, but I feel that's cheating:
@echo %~n0&%0

linux (Ba)sh, 13 to 26 (23 to 36 chars) (repeats 'y' or the input, like yes)
create an executable (+x) file, named as you like (ex: my_yes), containing one of those possible contents:
echo ${*:-y};exec $0 $*  #23 chars, score 13, but loses spaces, and will choke on many inputs

or
echo "${@:-y}";exec $0 "$@"  #27 chars, score 17, but will choke on some inputs

or
printf "%s\n" "${@:-y}";exec $0 "$@"  #36 chars, score 26, a tiny more robust, but "longer"

and then execute it with the arguments you want, it will repeat them ad-lib. (With no arguments, it repeats "y", as the yes command does too)
$ chmod +x my_yes
$ ./my_yes
y
y
y
[ctrl-C]

$ ./my_yes '  It looks ok!'
  It looks ok!
  It looks ok!
  It looks ok!
  It looks ok!
[ctrl-C]

some inputs that can make it choke on the first 2 : first argument starting with a "-", for example. (and many others)

I use "exec" to ensure I don't bring the computer down very quickly with recursive bash (which 'yes' doesn't do, usually ^^)

C89, 31 37 chars
main(){for(;;)printf("%c\n",'z'-1);}

Built on the idea of @LordAro, without filename requirements.

CFML, 247 bytes
This is more a "just for the heck of it" answer, as it's obviously hideously long (CFML earns no points for terseness); and I just realized it can't actually be killed without restarting the service, although it will indeed stop printing to the browser on an ESC character.
<html><body><cfflush><cfif isDefined("URL.i")><cfscript>a=URL.i;if(a is ""){a=chr(asc("x")+1);}while(1){writeOutput("#a#<br>");getPageContext().getOut().flush();}</cfscript><cfelse><form action="a.cfm"><input name="i"/></form></cfif></body></html>

C, 35 bytes
main(a,b){b='x'+1;for(;;)puts(&b);}

I don't know if this will compile correctly with all compilers on all platforms or not; if it doesn't work for you, let me know. I used several things here that I have never thought of using before. :)

Node.js, 53 chars (63 if you count node -e "")
update:

Reduced another 5 chars.
Silly extra char removed.
Reduced 2 chars, from  61 to 59.

The real yes does not uses stdin, but an argument, like:
yes n

Well, this answer works like that, it will print y\n over and over:
node -e "for(;;)console.log(process.argv[1]||34 .toString(36))"

And if you append an n after the line, it will print n\n instead:
node -e "for(;;)console.log(process.argv[1]||34 .toString(36))" n

No bonus, since I'm not using stdin.

CAPL1.5+ ; 6 without input; 10 - 10 = 0 with input
Sidenote
I have read somewhere [link?] that custom languages aren't allowed in golfing questions, as they could make built-in functions that do exactly what the question is asking, however I made CAPL to make golfing easier in general. If you think this is not allowed here, let me know!
I got some ideas from ><> and Befunge (You can move between lines and use hexadecimal characters to push numbers), some from Ruby and some from my own to make golfing easier.
CAPL reads from left to right, and goes one line down at the end of the line. If it is as the last line, the program will quit.
As no-one knows this language yet, I'll try to explain as much as possible.
Outputting y. 6 bytes
bb*.n<
bb* b is hexadecimal for 11, so bb* is 11*11=121, which is the UTF-8 equivalent of y. This value is pushed to the stack.
. Pops the top value from the stack, and outputs as UTF-8. As 121 is on top of the stack, the index is ignored here.
n Outputs a newline
< Sends the pointer back to the beginning of the line, thus repeating that line. As we don't expect input, we can do this safely without re-asking for the input.
Outputting from input. 10 bytes, 0 after bonus
i~a&{X:.)}
i Takes input from the user, pushes as UTF-8 on the top of the stack, and pushes the length after that. I.e. [72,101,108,108,111,5]
~ Pops a number from the stack, then reverses that amount of bytes. I.e. [111,108,108,101,72]
a Hexadecimal for 10, the newline character
&{...} Makes an infinite loop. We have input, so we can't send the pointer back to the line. I could place the function on the line below, which would safe me a byte, but newlines aren't allowed in this challenge.
X Removes the top value from the stack (The index from the loop)
:. Duplicates the top value, then outputs as UTF-8
) Turns stack right. ([1,2,3,4,5] -> [5,1,2,3,4])
Howver, this means we start with a newline, then start outputting the input, then a newline, then the input, etc. If we're not allowed to start with a newline, use the following code with 12 bytes, or 2 after subtracting the bonus.
iXa#~&{X:.)}
The only new command here is #, which pushes the amount of items on the stack to the stack.
I removed the length from i, because adding 1, then swapping with the newline is longer than removing and getting the length again.
Just for fun, here is a "Hello World" program
"Hello World"#~
#?!;.<

The ?! operation is the same as ><>'s

Actually the restriction applies to custom languages/libraries/features published after the question was posted.

@manatwork That would mean my answer is invalid. Thanks for the clarification. I made this language, and wanted to do some golfing challenges to test what I could improve for future versions, if that makes anything better.

In my opinion this is not invalid, just not eligible to win. The restriction's goal was to prevent cheating, but as you included the statement about the language's freshness, this could hardly be considered a cheating attempt.

SmileBASIC, 19 bytes - 10 = 9
INPUT C$@L?C$GOTO@L

QC 26 (26 - 10 = 16) bytes
(00600F014"0178)0101A01$14
The program requires an input on stdin because QC doesn't have a way to get arguments. Empty input just prints y.
Explanation
(00 read string into memory at address 00, address 00 is length, next bytes are the string itself
600F014 jump if values at 00 and F0, if not equal jump to address 14
"0178 Write 78(lowercase x) to address 01
)0101 increment value at address 01 by 01 which gives y
A01 print string and newline from address 01 until 00 is reached
$14 jump to address 14(print the next line)

Wait, It's decremented by 10, so it becomes 16 bytes, making this the ultimate answer!

Vitsy, 15 - 10 = 5 bytes
Because Vitsy waits for STDIN to be entered, I have made the bonus input come in as command line arguments.
zl)[bD*][:ZaOu]

Explanation:
z               Grab the entirety of the input stack and patch it on the current.
 l)[   ]        If the stack has no members...
    bD*         Push 11^2 to the stack (this is the ASCII value for 'y').
        [     ] Loop infinitely.
         :      Duplicate the current stack.
          Z     Push the entire contents of the stack to output, top first.
           aO   Push out a newline to the out.
             u  Flatten the top two stacks.

C(GCC) - 161 bytes
main(int argc,char**argv){if(argc>1){while(1){for(int i=0;i<argc-1;i++){printf("%s ",argv[i+1]);}puts("");}}else{char*c=malloc(1);c[0]='x'+1;while(1){puts(c);}}}

Uses malloc to allocate 1 byte and set its value 'x' + 1
If any input is provided as an argument(mulitple words work too) it will print it instead of y.
Ungolfed version:
main (int argc, char**argv) {
    if (argc > 1) {
        while (1) {
            for (int i=0; i < argc - 1; i++) {
                printf("%s ",argv[i+1]);
            }
            puts("");
        }
    } else {
        char* c = malloc(1);
        c[0] = 'x' + 1;
        while(1) {
            puts(c);
        }
    }
}

R, 51 bytes
while(T){cat(paste0(letters[25],'\\',letters[14]))}

Literally outputs "an infinite stream of "y\n"'s", rather than "y[newline]".
In RStudio the output is truncated but it is otherwise infinite.

R, 27-10 = 17 bytes
x=scan(,'');repeat print(x)

Repeats stdin over and over and over. No y or \n in the code.

><>, 6 bytes
b:*oao

By not including a ; at the end, the ><> will keep on swimming until he's released by a SIGINT.
Explanation
b:*oao
b         Push 11
 :        Duplicate
  *       Multiply top elements to get 121
   o      Print as character
    a     Push 10
     o    Print as character (yielding '\n')
          No program terminator, so our ><> will
          keep on swimming this path forever.
^----'

><>, 17 - 10 = 7 bytes
The previous is quite a boring solution, so here's one that takes input from stdin. This abuses the fact that the default way of supplying input to a ><> program is echo 'input' | fish.py yes.fish, where echo provides the \n character.
 i:0)?!v
0r}o:r~<

Explanation
 i:0)?!v     Load STDIN into the stack (reversed)

             NOP           <----------,
 i           Push a byte from STDIN   |
  :          Duplicate top element    |
   0         Push 0                   |
    )?       If (i > 0):              |
      !        Wrap around  ----------'
             Else:
       v       Move to the second part

0r}o:r~<     Print STDIN until halted

       <     Go right         <---------------,
      ~      Remove top element (duplicated   |
                -1 from EOF)                  |
     r       Reverse stack                    |
    :        Duplicate top element            |
   o         Output as character              |
  }          Rotate stack to right (go to     |
                next character)               |
 r           Reverse the stack                |
0            Push 0                           |
             Wrap around       ---------------'

The 0r at the end allow sfor the loop to happen by wrapping
around, where we still assume the stack to be reversed with a -1 on top.

Ohm, 17 - 10 = 7 bytes
IDö?.x1+;Ω
D,∞

Explanation:
IDö?.x1+;Ω  ■Main link
I           ■Input
 Dö?    ;   ■If(!input){
    .x1+    ■  Push 'x' and increment
            ■}
         Ω  ■Call link below

D,∞         ■Helper link
  ∞         ■while (true){
D,          ■  duplicate and print
            ■}

Perl 5 - (10-10) = 0 bytes
print;redo

Requires the -ne flags. Takes in a character(s) from STDIN, repeats the character(s) infinitely.
Example execution
perl -ne 'print;redo'

Explanation
This takes advantage of the -n flag in Perl, where it explicitly wraps while (<>) { ... } around the source code. The use of redo without an explicit label is also used. According to the documentation:
If the LABEL is omitted, the command refers to the innermost enclosing loop.

Mumps (M), 12 bytes - 10 = 2 bytes
Quite simple in Mumps (M), as the language allows single character commands and a newline is denoted by '!'...
R I F  W I,!

Breakdown:
Read STDIN into I,
For (with two spaces) = infinite loop,
Write contents of I, then newline (!)
Works on both InterSystems & YottaDB (GT.M).

Husk, 1 - 10 = -9 bytes
The wonderful thing about Husk's laziness is that computations involving infinite lists can be managed and used to produce useful output, like in this case :)
∞

Try it online!
Explanation
   Implicit argument
∞  Build an infinite list repeating forever
   Implicit join by newlines

Raku (raku -n) 9-10 = -1 bytes
.say;redo

Idea for redo from @booshlinux (I would have done: loop{.say})

05AB1E, -8 bytes
[,

Try it online!
[,  # full program
[   # forever...
 ,  # output...
    # implicit input

BRASCA, -3 bytes (7-10)
l,[:mo]

Try it online!
Explanation
<implicit input>
l           - Push 10 (\n)
 ,          - Reverse stack
  [   ]     - While non-zero:
   :mo      - Duplicate, move the duplicate to bottom, output top of stack

brainfuck, 60-10=50 bytes
+>>,[[>,]>+<]++++++++++>-[<[<+<++++++++++++>>-]]<[[<]>[.>]<]

Try it online!
Explanation:
+>> add one (120 to be adden on later yeilding 'y')
,[[>,]>+<]  if there is input, read it and set a flag to skip the next loop
++++++++++>-  '\n'
[
  <[<+<++++++++++++>>-] add 10*120 to first cell, shift \n back one cell
]
<[[<]>[.>]<] print the input or 'y\n'

Welcome to the site, and nice first answer!

JavaScript (Node.js), 86 80 bytes
with strict adherence to the you are not allowed to use "y" or "\n" or their ASCII values (121, 0x79, 0171, 10, 0xA or 012) rule
for(;;)console.log(eval('T\\u'+(+[])+(+[])+(38+38+3)+'peError').toString()[6+4])

Try it online!
-6 bytes thanks to me

Vyxal, -8 bytes (2-10 bytes)
Not the most original method, but it's short.
{,

Explanation
{         - While non-zero
 ,        - Print implicit input

Try it Online!

JavaScript, 32 31 bytes
for(;;)console.log((""+1/0)[7])

Edits

-1 byte: while(1) => for(;;)

Explanation

for(;;) is an infinite loop)
1/0: A division by zero returns Infinity in javascript
""+ converts Infinity into a string
[7] access the 8th character of "Infinity" (y)

To terminate the process do Ctrl+C (SIGINT)

GolfScript, 15 10-10=0 bytes
{.puts.}do

Try it online!
For some reason I thought the only way to get input from STDIN was "#{STDIN.read}, but I then realized that STDIN is already left on the stack by default.

Fig, \$2\log_{256}(96)\approx\$ 1.646 - 10 \$\approx\$ -8.354 bytes
(,

Try it online!
Prints the input forever. Simple.

Should this be -8 bytes?

oops :P thanks ineedmorechars

What??? a negative amount of bytes???

oh challenge specs

Go, 92 102 bytes
package main;import(."os";."fmt");func main(){s:=string('x'+1);if len(Args)>1{s=Args[1]};{Println(s)}}

Attempt This Online!
Go, 172 182 - 10 = 162 172 bytes
package main;import(."os";."fmt";"io");func main(){s:=string('x'+1);if len(Args)>1{s=Args[1]}else if f,_:=Stdin.Stat();f.Size()>0{b,_:=io.ReadAll(Stdin);s=string(b)};for{Println(s)}}

Attempt This Online!
+10 bytes for removing "y" and newlines.

this has an "y" in it, as far as I can tell...

Thunno, \$ 11 \log_{256}(96) \approx \$ 9.05 - 10 \$ \approx \$ -0.95 bytes
[z011D*C~ZK

Attempt This Online!
If calculating "11 squared" is cheating, here's one which doesn't have any numeric literals:
Thunno, \$ 12 \log_{256}(96) \approx \$ 9.88 - 10 \$ \approx \$ -0.12 bytes
[z0AzZHAK~ZK

Attempt This Online!
Explanations
[z011D*C~ZK  # Implicit input (if given)
[            # while True:
 z0          #  Push the first input if it
             #  was given, or [] if it wasn't
   11        #  Push 11
     D*      #  Square to get 121
       C     #  Get chr(121) ("y")
        ~    #  Do a logical OR, yielding the input
             #  if it was given, and "y" if it wasn't
         ZK  #  Print with a trailing newline

[z0AzZHAK~ZK  # Implicit input (if given)
[             # while True:
 z0           #  Push the first input if it
              #  was given, or [] if it wasn't
   Az         #  Push the lowercase alphabet
     ZH       #  Remove the last element, to get
              #  "abcdefghijklmnopqrstuvwxy"
       AK     #  Get the last element, i.e. "y"
         ~    #  Do a logical OR, yielding the input
              #  if it was given, and "y" if it wasn't
          ZK  #  Print with a trailing newline

Python, 25 Bytes
while 1:print(chr(~-122))

Never knew you could do bitwise operations on non-binary numbers!

...what's a non-binary number? Like a float(?), but you're not even using a float

Trilangle -f, 9 bytes
Doesn't contain a line feed (\n) but it does contain a form feed (\f).
"x")oo:,

Try it on the online interpreter! The -f flag has no meaning in the online version, but in the command line it means that closing stdout will terminate the program (e.g. trilangle -f yes.trg | head -n 10).
Since the form feed doesn't render, here's a hexdump (reversible with xxd -r):
00000000: 2278 2229 0c6f 6f3a 2c                   "x").oo:,

Notepad renders the form feed character as an up arrow, so I'll be using the symbol ↑ in place of the form feed for the explanation.
The code unfolds to this:
   "
  x "
 ) ↑ o
o : , .

For lack of redirections, this simply executes in order:

"x: Push the value of x (120) to the stack.
): Increment the top of the stack
o: Output the character corresponding to the top of the stack ('y')
"↑: Push the value of ↑ (12) to the stack.
:: Divide the two values, so the stack now contains a single number (10). Line feeds are ignored by the interpreter anyways, so doing arithmetic is the only way to get a 10 on the stack.
o: Output the character corresponding to the top of the stack ('\n')
,: Pop the value from the stack, keeping memory bounded since it loops forever
.: No-op

For lack of an explicit exit instruction, this loops forever.

JAGL V1.0 20 - 10 = 10 With Bonus, 14 Without
Tdn{78h[}Sf{p9[pDd}u

Coulda probably done better, but here is the explaination:
Td                               Get a line of text input, and duplicate on stack
  n                              Negate its truth value (for the if)
   {78h[}                        Push a block which will push the y character, if called
         Sf                      Swap top two values on stack and if no input, push y
           {p9[pDd}              Push block which prints the input (or y) and a newline
                   u             Do until loop. Output always evaluates to true

Can be killed by SIGINT
Without bonus:
'x  '{1+}/{pd}u

explaination:
'x  '                            Pushes the string '\tx'
      {1+}                       Adds 1 to each character in the string, making it 'y\n'
          {pd}u                  Infinitely prints and duplicates

Java, 157 154 bytes
Despite the common misconception that you have to use System.out to print anything to the console in Java, this program outputs to the console using a FileOutputStream to the file described by FileDescriptor.out. Accoding to the specification for FileDescriptor.out, it is "A handle to the standard output stream. Usually, this file descriptor is not used directly, but rather via the output stream known as System.out".
class A{public static void main(String[]a)throws Exception{for(;;)new java.io.FileOutputStream(java.io.FileDescriptor.out).write(new byte[]{120+1,9+1});}}

Pascal: 40 characters
begin while 1=1do Writeln(Succ('x'))end.

Outputs “y”, stops on SIGINT.

This works in my Befunge interpreter:
"z"1-.25*.

10 chars.
"z" means push the ascii value of the characted "z", 1 means push the number one, - means subtract, . means print the ascii value of it and * means multiply. For more info: http://en.wikipedia.org/wiki/Befunge

Lazy K, 167 bytes
`k````ssi``s`k``ss`k``siik``s`k`s``si`k```s``s`kski``s``s`ksk``s``s`ksk```s``s`kski``s``s`ksk``s``s`kski``s`kk``s`k`s``si`k``s``s`ksk```s``s`kski``s``s`ksk``s``s`kskik

It is probably too long...
```ssi``s`k``ss`k``siik                                              fixed-point combinator
``s``s`ksk```s``s`kski``s``s`ksk``s``s`kski                          \n
```s``s`kski``s``s`ksk``s``s`ksk```s``s`kski``s``s`ksk``s``s`kski    y

C 42
main(){while(1){putchar(11*11);puts("");}}

Microscript, 19-10=9
If['w2s]1{CaI#!Zx}h
Besides the initial input, takes an extra input after each iteration and halts when and if any of the additional inputs is non-empty (the specs for the question said to provide a way to make it halt).

PHP, 34 bytes - 10 = 24
for(;;)echo$argc>1?$argv[1]:y,"
";

Run with php -nr '<code>' or php -nr '<code>' '<string>'.
Or 56 bytes for an exact port:
for(;;)echo$argc>1?join(" ",array_slice($argv,1)):y,"
";

(-2 bytes with extended ASCII; -1 for the not-so-complete version)

Python 3, 40 bytes - 10 = 30
i=input()
while 1:print(i or chr(11**2))

Stops with SIGINT (Ctrl+C)

OIL, 23 bytes noncompeting
120
8

17

1

4

11
6
6

Increments 120, transforms it to a "y", and repeatedly print it and a newline.
Can be stopped with SIGINT / Ctrl+C.
Variant that receives something from stdin instead:
OIL, 13-10 = 3 bytes
5

4

11
6
2

AHK, 38 bytes - 10 = 28
c=%1%
Loop,3
FileAppend,% c Chr(9+1),*

I may have misunderstood, but I think the 9+1 is allowed. If not, I'll delete this.
If Loop is used without brackets {}, it is assumed that only the next line is part of the loop.
If Loop is used without a count, it will repeat until it encounters a Break.
Per the help file, if an asterisk is passed as the filename into FileAppend, it outputs to stdout.
%1% is the first passed argument.
If I could use the input variable %1% directly, that would have been nice. It gets funny with the Chr function following it, though, and would have ended up being more bites.

TI-BASIC, 8 bytes
While not(getKey:Disp Str0:End

Jelly, 7 - 10 = -3 bytes
ØyṪ³ȯṄß

Try it online!
Explanation
Øy             # The string "AEIOUYaeiouy"
  Ṫ            # Take the last element, namely "y"
    ³          # The cmdline argument (empty list if none supplied)
     ȯ         # Either the cmdline if supplied or "y"
      Ṅ        # Print with a newline
       ß       # Recurse

Thankfully Jelly programs can always be C-c-ed.
Alternative Sans Y; 10 - 10 = 0 bytes
“¢³ƒ»Ṫ³ȯṄß

If the 'y' in the original answer is unacceptable, here's one without. This works on the same principle, the string “¢³ƒ» is the compressed version of "Jelly"

Chip, 15+3 = 18 bytes
+3 for flag -w, which ignores stdin and generates an endless stream of null bytes for input instead.
dbae
*}++g
 `zf

Try it online!
Note about the TIO: instead of using the -w flag, it uses input. The behavior is the same, except that input is finite. One byte of output per byte of input.
Explanation
*}+
 `z

This is a 1-clock. On the first byte, the + is active, and on the second byte, the other three elements are active. The two states alternate endlessly.
d ae
* ++g
   f

This produces the output corresponding to 'y'. These letters each map to a bit: _gfed__a -> 0b01111001 -> 0x79 -> 'y'.
db
*}
 `z

This produces the output corresponding to '\n'. Similar to above, but we have these bits: ____d_b_ -> 0b00001010 -> 0x0a -> '\n'.

Tcl, 39 bytes
while 1 {puts [format %c [expr 11*11]]}

Try it online!

><>, 5 bytes - 10 = -5
a{:o!

Try it online!
Takes input via the -s flag and repeats it forever until the program is interrupted.

To qualify for the bonus, I think this should print y if no input is given.

@Cowsquack Nope, it's optional

MathGolf, 8 bytes -10 = -2
╜É'x)Äo∟

Try it online!
Explanation
╜É         else without if (executes block of 3 chars if input is empty)
  'x)      increment "x" to get "y"
     Ä     start block of length 1
      o    print TOS without popping
       ∟   do while true without popping

Quite straightforward, but gets the job done.

You don't need to print y if there's no input

maxb bug report for MathGolf: string input which contains spaces are automatically transformed to lists (even if they are already inside lists). I noticed this, because it screwed up the length builtins £ and h: Try it online.

@KevinCruijssen I think I overcomplicated the implementation of implicit input, which causes these errors. I'll see if I can switch to a pure ast.literal_eval statement for the input, which should solve a lot of issues.

Python 3, 25 bytes
while 1:print(chr(11*11))

Try it online!

Python 3, 26-10=16 bytes
x=input()
while 1:print(x)

Seems too easy. Never posted here before so probably done something dumb. What did I miss?
UPDATE
I don't think this is cheating (35-10=25):
exec("x=input()\nwhile 1:print(x)")

Welcome to the site!  I think this question doesn't allow newlines so you should use ; instead.  The question is a little confusing IMO and I've been here a while.

Does it satisfy constraint about closing program?

@WheatWizard, python doesn't support semicolons.

Oh right. So I'm not even allowed newlines in my source. Got it! :laugh:

Best I can get with the bonus is 27, and I need the walrus to do that: x,*_=iter(lambda:print(z),z:=input())

Actually, that will probably segfault eventually. A set can be used to keep it going indefinitely I think set(iter(lambda:print(z),z:=input()))

Kotlin, 23 - 10 = 13 bytes
{while(1>0)println(it)}

Try it online!

C (gcc), 30 - 10 = 20 bytes
f(a){for(gets(&a);puts(&a););}

Try it online!

Pxem, filename: 22 bytes + content: 4 bytes - bonus: 10 bytes = 16 bytes.

Filename (escaped unprintables): .w.i.c\001.+.a\013.+l.w.el.a
Content: .v.p

Try it online!
With comments
XX.z
# while size==0 || pop!=0; do
.a.wXX.z
  # push getchar; dup; push 1; push pop+pop;
  # NOTE EOF is -1
  .a.i.c\001.+XX.z
# done
.a.aXX.z
# push 11; push pop+pop;
.a\013.+XX.z
# push whatever not zero; while pop!=0; do call content; push whatever not zero; done
.al.w.el.a

XX.z
# get called, with my stack initialized to original one
# reverse; pop all to putchar for each of them
# implicitly return, pushing each content of
# my stack from bottom to pop to original one
.a.v.p

Pxem, filename: 14 bytes + content: 0 bytes = 14 bytes.

Filename: (unprintables are escaped) .w\005\005.+\001x.+.p.a
Content: empty.

Wow, shorter than above!
Try it online!

Zsh, 29 bytes
for ((;;))<<<${(#)$((11*11))}

tio example (times out)
Not cheating like the bash answer...

Shorter zsh answer (a recursive function saves 1 byte compared to for ((;;)), and I found a shorter way to construct y without y, there may well be even shorter ones)

Nooklang, 14 bytes
{120 1 + c p}t
Right now this isn't available on any online coding platform yet, so you will have to run the code from your computer.
Explaination:
{
  120 1 + # Returns 121 (aka ASCII value of y)
  c # Converts the value to character
  p # Prints out the character
} t # Infinite loop

Nim, 37 - 10 = 27 bytes
var x=readLine stdin;while 1>0:echo x
Attempt This Online!

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

authors: بنيان ال شريه

authors: حسين ابو بكور


text:
Shorter than a Split Second!
Challenge
You task for this question is to split an input array of integers on the second occurrence of every integer in that array.
Not clear enough ? Here is an example to help
Input array:
[2 1 1 2 3 2 2 4 5 6 7 3 7 0 5]

Output:
[[2 1] [] [3 2 2 4 5 6 7] [] [0] []]

Explanation:
Here is the array with just the second element highlighted in bold:
[2 1 1 2 3 2 2 4 5 6 7 3 7 0 5]
Now we put the splitting array blocks around these bold second occurrences:
[2 1] 1 [] 2 [3 2 2 4 5 6 7] 3 [] 7 [0] 5 []
and wrap these splitted arrays in an array to get the final
[[2 1] [] [3 2 2 4 5 6 7] [] [0] []]

Note that when adjacent second occurrences occur, there will be empty arrays.
Rules
As usual, you have to write a full program or a function taking the input array via STDIN, ARGV or function argument.
Input
The input consists on any convenient array (or array-like) format of integers.
For instance, any of the following would be acceptable:
2 1 1 1 4 5 6
[2 1 1 1 4 5 6]
[2, 1, 1, 1, 4, 5, 6]

Output
When outputting to STDOUT, your array can also be printed in any convenient (nested) array format, e.g. one of
[[2 1] [1 4 5 6]]
[[2, 1], [1, 4, 5, 6]]
{{2, 1}, {1, 4, 5, 6}}

(This will usually be the native string representation of arrays in your language.)
Also note that trailing empty arrays should be printed as the part of the array.
Scoring
This is code-golf so shortest code in bytes win!

@PeterTaylor many questions allow for different formats of arrays in both output and inputl.

What's the point of allowing "" as the empty array? This smells of favourism towards a specific golfing language.

@JanDvorak After discussion in chat, the intention was actually to be more inclusive and generally allow languages to use their native representation. I've edited the wording now to make that clearer.

Can I just output 2 1, 1 4 5 6?

@user23013 depends on the language you have chosen.

APL 25
1↓¨(1,∨⌿<\2=+\∘.=⍨a)⊂1,a←

Example:
]display 1↓¨(1,∨⌿<\2=+\∘.=⍨a)⊂1,a←2 1 1 2 3 2 2 4 5 6 7 3 7 0 5
┌→──────────────────────────────────────┐
│ ┌→──┐ ┌⊖┐ ┌→────────────┐ ┌⊖┐ ┌→┐ ┌⊖┐ │
│ │2 1│ │0│ │3 2 2 4 5 6 7│ │0│ │0│ │0│ │
│ └~──┘ └~┘ └~────────────┘ └~┘ └~┘ └~┘ │
└∊──────────────────────────────────────┘

Old One:
{1↓¨(1,(⍳⍴⍵)∊,{1↑1↓⍵}⌸⍵)⊂1,⍵}

This is a nice question for the key operator (⌸) which was introduced with Dyalog APL v14.
It takes the left argument function ({1↑1↓⍵}) and gives it for each unique argument, the indices in the vector for that argument.
Here I'm taking the second index, then i check which of the indices is present in this list ((⍳⍴⍵)∊) and use the resulting boolean for splitting the original vector.
Can be tried online here:
http://tryapl.org

Damn. Still not less than 24 ?

@Optimizer: 25... I'm trying ;-)

Accepting this instead of my own solution :)

Only 24, and a proper function: 1↓¨{1,∨⌿<\2=+\∘.=⍨⍵}⊂1∘,

APL (Dyalog 14) (31)
{1↓¨(1,(⍳⍴⍵)∊2⍳⍨¨↓+\∘.=⍨⍵)⊂0,⍵}

This is a function that takes an array and returns a nested array.
Test:
      +V← {1↓¨(1,(⍳⍴⍵)∊2⍳⍨¨↓+\∘.=⍨⍵)⊂0,⍵} 2 1 1 2 3 2 2 4 5 6 7 3 7 0 5
┌───┬┬─────────────┬┬─┬┐
│2 1││3 2 2 4 5 6 7││0││
└───┴┴─────────────┴┴─┴┘
      ⍝ this return value is a real nested array:
      ⎕←'Length: ',⍴V ⋄ (⍳⍴V){⎕←'Array #',⍺,': (', ⍵, ')'}¨V
Length:  6
Array # 1 : ( 2 1 )
Array # 2 : ()
Array # 3 : ( 3 2 2 4 5 6 7 )
Array # 4 : ()
Array # 5 : ( 0 )
Array # 6 : ()

Explanation:

0,⍵: Add a 0 to the front of ⍵, for easier processing. (It does not count as an occurrence.)
(...)⊂: Split the array according to the given bitmask. A new group starts at each 1 in the bitmask.

+\∘.=⍨⍵: for each value in (the original) ⍵, find all occurrences in ⍵. Then make a running sum for each value, giving a square matrix showing for each position in ⍵ how many of each value have already occurred.
↓: Split the matrix by its rows, giving for each value an array showing the amount of times it has occurred by each position.
2⍳⍨¨: In each of these arrays, find the index of the first 2.
(⍳⍴⍵)∊: For each possible index into ⍵, see if it is contained in the list of indices of second occurrences. (These start each group, except the first one.)
1,: Add an 1 to the front, marking the start of the first group.

1↓¨: Remove the first element from each group. (These are the added 0, and the second occurrence of each value.)

J, 28 24 char
Special thanks to randomra.
(1&,<;._1~1,2=+/@(={:)\)

It works like this. Over all prefixes (\) of the input array, we look at how many (+/@) elements of the prefix are equal to the last element (={:) of that prefix. When this number is 2, we know this is the second occurrence of that item in the array, so we split the array there using <;._1.
   a=.2 1 1 2 3 2 2 4 5 6 7 3 7 0 5
   (={:)\ a
1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 1 0 0 0 0 0 0 0 0 0 0 0 0
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
1 0 0 1 0 1 0 0 0 0 0 0 0 0 0
1 0 0 1 0 1 1 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
0 0 0 0 1 0 0 0 0 0 0 1 0 0 0
0 0 0 0 0 0 0 0 0 0 1 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 0 0 0 0 0 0 0 1 0 0 0 0 0 1
   +/@(={:)\ a
1 1 2 2 1 3 4 1 1 1 1 2 2 1 2

Old thing using sort tricks: (1&,<;._1~1,1=i.~(]-{)/:@/:).

(1&,<;._1~1,2=+/@(={:)\) is 4 bytes shorter and a lot simpler. (/:@/: is a nice trick though.)

Mathematica, 58 51 49 bytes
Rest/@SplitBy[(f@#=0;#)&/@{a}~Join~#,++f[#]==3&]&

This is an unnamed function which takes a list like
Rest/@SplitBy[(f@#=0;#)&/@{a}~Join~#,++f[#]==3&]&[{2,1,1,2,3,2,2,4,5,6,7,3,7,0,5}]

and returns a nested list like
{{2, 1}, {}, {3, 2, 2, 4, 5, 6, 7}, {}, {0}, {}}

How it works
This uses some pretty obscure magic with SplitBy.
I'm keeping track of the occurrences of each number in a function f. In Mathematica, you can define the value of a function for each input separately, and you don't need to specify the value for all possible inputs (it's more like a hash table on steroids).
So I start out by initialising f to 0 for values that are present in the input with (f@#=0;#)&/@.
Now SplitBy takes a list and a function and "splits list into sublists consisting of runs of successive elements that give the same value when f is applied" (note that SplitBy does not remove any elements). But the (undocumented) catch is, that f is called twice on each element - when comparing it to its predecessor and its successor. So if we do
 SplitBy[{1,2,3,4},Print]

we don't just get each number once, but instead this prints
 1
 2
 2
 3
 3
 4

which is 6 calls for 3 comparisons.
We can split the list before each second occurrence, if we write a function which always returns False but returns True when a second occurrence is compared to the element before it. That is the third check on that element (two checks on the first occurrence, plus the first check on the second occurrence). Hence, we use ++f[#]==3&. The nice thing is that this already returns False again on the second check of the second occurrence, such that I can return True for consecutive second occurrences, but still split between them. Likewise, this won't split after second occurrences, because the function already returns False again on the second check.
Now, the question wants us to also remove those second occurrences, so we drop the first element from each list, with Rest/@. But of course, we don't want to remove the very first element in the input, so we actually start off, by adding an element a to the beginning of the list with {a}~Join~#. a is an undefined variable, which Mathematica just treats as an unknown, so it won't affect any other values of f. This also ensures that the first actual element in the input gets its two checks like every other element.

That's pretty clever. You also actually don't need Boole in there.

@swish Ah, thanks for reminding me... I noticed that while on mobile, but wanted to test it before changing it.

Python, 148 bytes
def s(a):z=len(a);x=[-1]+sorted({[i for i in range(z)if a[i]==n][1]for n in a if a.count(n)>1})+[z];return[a[x[i]+1:x[i+1]]for i in range(len(x)-1)]

Pretty horrendous solution. There's got to be a better way...
Call with s([2, 1, 1, 1, 4, 5, 6]).
Ungolfed version
def split(array):
  indices = [-1]
  second_occurrences = set()

  for n in array:
      if array.count(n) > 1:
          occurrences = [i for i in range(len(array)) if array[i] == n]
          second_occurrences.add(occurrences[1])

  indices += sorted(second_occurrences)
  indices += [len(array)]

  return [array[indices[i]+1:indices[i+1]] for i in range(len(indices)-1)]

What the what… Could you edit in an un-golfed version? XD 148 characters is a very long line ;)

@SeanAllred I didn't want to post an explanation since I was sure I could do better, but since I'm having trouble I've posted the ungolfed version :P

Haskell, 115 113 106 88
f?(x:s)|1<-f x=[]:x%f?s|a:b<-x%f?s=(x:a):b
f?x=[x]
(x%f)h=sum$f h:[1|x==h]
r s=(\_->0)?s

this stores the amount every element appeared so far as a function from elements to their respective amount, which is an interesting trick.
this works using %, a function that given a function f and an argument x returns a new function that returns f applied to it's argument if it is different than x, and 1 + f x otherwise.
for example, 3 % const 0 is a function which returns 0 for every argument except 3, for which it returns 1.
update:
fused the foldl to get a much smaller program.

This looks interesting. Could you provide an ungolfed version?

Ruby 66 demo
f=->a{c=Hash.new 0
r=[[]]
a.map{|e|2==(c[e]+=1)?r<<[]:r[-1]<<e}
r}

Ruby stabby lambda that takes an array as a parameter and returns an array of arrays.

Python: 100 byte
def g(l):
 i=j=0;o=[]
 for e in l:
  if l[:i].count(e)==1:o+=[l[j:i]];j=i+1
  i+=1
 return o+[l[j:]]

Straightforward solution. I iterate over the list, count how many times a character appeared before, and append the part since the last check to the output list.

Perl 5: 36
Not sure if this is acceptable as no actual splitting happens here.
#!perl -pa
$x{$_}++-1or$_=']['for@F;$_="[[@F]]"

Example:
$ perl spl.pl <<<"2 1 1 2 3 2 2 4 5 6 7 3 7 0 5"
[[2 1 ][ ][ 3 2 2 4 5 6 7 ][ ][ 0 ][]]

Totally acceptable.

Nice answer. But standard practice, I think, is to count -pa as two extra bytes (because it "costs" only two bytes, since you can write it as -pae instead of -e). So that'd be 38, not 36.

Ruby, 64 bytes
s=->a{x=[];b=[[]];a.map{|e|x<<e;x.count(e)==2?b<<[]:b[-1]<<e};b}

CJam, 25 24 bytes
q~{_L+:L1$a/,3=S@?}%Sa/p

Takes input from STDIN like
[ 2 1 2 1 0 2 2 1 1 3 4 3]

and outputs like
[[2 1] "" [0 2 2 1 1 3 4] ""]

I am basically iterating over all elements of the array, one by one putting them into another array. Then I get the count of the current element in the other array. If its 2, I start another array from that location. This kind of random array starting can only be achieved in a stack based language.
Code expansion:
q~{_L+:L1$a/,3=S@?}%Sa/p
q~{               }%             "Evaluate the input array and map it on this block";
   _                             "Copy the current element in iteration";
    L+:L                         "Add the copy to an initially blank array L and update L";
        1$a/                     "Make another copy of the element and split L on it";
            ,3=                  "This checks if the splitted array is of length 3";
                                 "which indirectly means that L contains the element twice";
               S@?               "If the above is true, replace the element by space";
                    Sa/          "Split the final array on space. This final array contains";
                                 "second occurrence of every integer replaced by a space";
                       p         "Print the stringified version of the final nested array";

Try it online here
1 byte saved from Martin's tip on chat

Ruby, 66
f=->a{s=Hash.new 0
r=[[]]
a.map{|e|(s[e]+=1)==2?r<<[]:r[-1]<<e}
r}

Explanation

e is a Hash of occurrence counts for each element, r is an Array in which the result is stored.
Loop trough the input, increment the occurrence count for each element by 1.

If the occurrence count is 2, we need to split. Add an empty Array to the result.
Otherwise just add the element to the last Array in result.

Nice hat!! Oh wait.

What an incredible coincidence! The answer I posted seconds before yours is almost identical. :)

Oh my, it's even 1 character shorter!

It's a saving you can easily apply to yours. I think it's awesome that we had the same idea at the same time. :D

Java, 223
This only works on Oracle or OpenJDK JRE, since I make use of this quirk in their implementation of quantifier and length check in look-behind to implement variable-length look-behind.
class W{public static void main(String a[]){System.out.print("["+new java.util.Scanner(System.in).nextLine().replaceAll(" *\\b(\\d+)\\b(?=(.*))(?<=^(?=(.*\\b\\1\\b){2}\\2).*)(?<!^(?=(.*\\b\\1\\b){3}\\2).*) *","] [")+"]");}}

Most of the work is done in the regex, which is shown below in raw form:
 *\b(\d+)\b(?=(.*))(?<=^(?=(.*\b\1\b){2}\2).*)(?<!^(?=(.*\b\1\b){3}\2).*) *

Before we look at the regex above, let us look at equivalent .NET regex, which is simpler, since it directly supports variable-length look-behind (.NET look-behind is most likely done by right-to-left matching mode):
 *\b(\d+)\b(?<=(.*\b\1\b){2})(?<!(.*\b\1\b){3}) *

 *\b(\d+)\b and  * at the end matches a number and the surrounding spaces (if any). The bound checks are to prevent partial number from being matched, since spaces on both sides are optional. It also captures the number to check whether it is the 2nd appearance in the array.
(?<=(.*\b\1\b){2}) checks that 2 instances of the number captured above can be found. (?<!(.*\b\1\b){3}) checks that no 3 instances of the number captured can be found. Both conditions combined asserts that there are only 2 instances of the number so far. The bound checks are there to make sure the whole number is tested.

Back to the Java version. To implement variable-length look behind, we transform
(?<=var-length-pattern)

to
(?<=^(?=.*var-length-pattern).*)

I am a bit hand-waving regarding the fact that . excludes line separators, but it can be fixed easily and I don't want to further complicate the syntax.
The look-ahead is always 0 in length, and the length check passes due to the implementation of * quantifier.
The ^ is not necessary to make it work, but it is there to make the failing case fails faster. Look-behind in Oracle/OpenJDK implementation is done by stepping back the minimum length of the pattern, then match, then rinse and repeat by incrementing the length until a match is found, or in the worst case, to the maximum length of the pattern. With ^, I make sure the prefix string is only matched once.
However, the look-ahead inside the look-behind is not limited by look-behind's right-boundary, so it can match all the way to the end of the string. In order to assert the boundary, I capture the rest of the string into another capturing group inside a look ahead, and use it to limit the reign of the variable length pattern.
(?=(.*))(?<=^(?=.*var-length-pattern\m).*)
   ^--^                              ^
   mth capturing group               m is the number of the capturing group marked

Since my pattern already starts with .*, I don't need to add another .* in front.

CJam, 28 bytes
Lq~{1$1$a/,3=S2$?@++}/-2%S/`

Takes input on STDIN like
[2 1 1 2 3 2 2 4 5 6 7 3 7 0 5]

and prints the output to STDOUT like
[[2 1] "" [3 2 2 4 5 6 7] "" [0] ""]

Note that empty strings and empty arrays are the same thing in CJam, and are displayed as "" by default (this is the native representation of empty arrays).
(I started working on this a bit before the challenge was posted, because we were discussing how difficult the challenge would be.)
Explanation
Basically, I'm duplicating each element in the array, unless it's the second occurrence, in which case I replace the first copy with a space. For golfing reasons, this modified array is constructed in reverse. So [2 1 1 2 3 2 3] becomes
[3 S 2 2 3 3 2 S 1 S 1 1 2 2]

Then I pick out every second element from the end, which is the original array, but with second occurrences replaced by spaces, i.e.
[2 1 S S 3 2 S]

Finally, I simply split the array on spaces. Here is a breakdown of the code:
L                            "Push empty array.";
 q~                          "Read STDIN an evaluate.";
   {                }/       "For each element of the input.";
    1$1$                     "Copy the array and the element.";
        a/                   "Split the array by that element.";
          ,3=                "Check that it's split into 3 parts.";
             S2$?            "If so, push a space, else, copy the current number.";
                 @++         "Pull up the array from the bottom and add both to the beginning.";
                      -2%    "Pick every second element from the end.";
                         S/  "Split on spaces.";
                           ` "Get the string representation.";

Since this is my own challenge, I am giving a chance first :P. I have a 25 byte Cjam solution with me.

Doesn't display empty arrays correctly--obviously invalid!

@feersum displaying empty arrays as "" is explicitly allowed in the first revision of the question. The current revision states "any convenient format ... usually native string represtation of arrays".

Unix tools, 100 bytes
grep -o '[-0-9]*'|awk '{print(++A[$0]-2)?$0:"] ["}'|paste -sd' '|sed -e '/]/s/.*/[\0]/' -e's//[\0]/'

Excepts the input via stdin. It basically just replaces every second occurrence with "] [". Does not work with empty strings, [] will give an empty string, which I think is a convenient representation of an empty array :)

Well, then the answer is not meeting the spec, right ? (about negative integers). Also, what about 11 ? will it get converted to 1][ ?

It works well for 11, but you are right about negative numbers, fixed that, and it now also accepts singleton arrays.

APL, 42 characters
{'(',')',⍨⍵[(2=+/¨(↑=↓)¨⌽¨,\⍵)/⍳⍴⍵]←⊂')('}

Example:
{'(',')',⍨⍵[(2=+/¨(↑=↓)¨⌽¨,\⍵)/⍳⍴⍵]←⊂')('}2 1 1 2 3 2 2 4 5 6 7 3 7 0 5

Output:
( 2 1  )(   )(  3 2 2 4 5 6 7  )(   )(  0  )(  )

Tested here.
If I must output a string that is interpreted exactly as the right structure in APL... 49 characters
{'1↓1(',',⍬)',⍨⍵[(2=+/¨(↑=↓)¨⌽¨,\⍵)/⍳⍴⍵]←⊂',⍬)('}

How is a nested list actually represented in APL ? Maybe you might not need to do string manipulation

@Optimizer The outputed string is a valid list in an APL program. However it wouldn't be nested if there is only one list in it. Prepending a 1↓1 seemed to fix the problem, but that looks too weird.

Pyth 30 32
This is my first time experimenting with Pyth. It's the same solution as in my Python solution.
VQIq/<QN@QN1~Y]:QZN=ZhN;+Y]>QZ

You can try it online: Pyth Compiler/Executor
E.g. The input
[2,1,1,2,3,2,2,4,5,6,7,3,7,0,5]

will print
[[2, 1], [], [3, 2, 2, 4, 5, 6, 7], [], [0], []]

Explanation:
                                 # Q = input(), Y = [], Z = 0
VQ                               # for loop: N iterates over the indices of Q
  I                              # if
   q\<QN@QN1                     #    Q[N] appears exactly once in Q[:N]
            ~Y]:QZN              #         append the list [Q[Z:N]] to Y
                   =ZhN          #         and assign Z = N + 1
                       ;         # end if and for loop
                        +Y]>QZ   # print Y + [Q[Z:]]

Is there a better alternative for =Y+Y...?

this is - ~Y...

Python 2, 84
l=[[]];p=[]
for x in input():p+=[x];b=p.count(x)==2;l+=[[]]*b;l[-1]+=[x][b:]
print l

The list l is the output so far. We iterate over the elements. If the current one is the second appearance, we start a new empty sublist; otherwise, we add it to the latest sublist. The list of elements seen so far is stored in p. Strangely, reconstructing the list seems shorter than slicing the input.

Pure bash 111 94
81 for only splitting:
for i;do [ "${b[i]}" == 7 ]&&c+=("${d# }") d=||d+=\ $i;b[i]+=7;done;c+=("${d# }")
declare -p c

The second line declare -p c just dumping the variable
Sample:
splitIntFunc() {
    local b c d i
    for i;do
        [ "${b[i]}" == 7 ]&&c+=("${d# }") d=||d+=\ $i
        b[i]+=7
      done
    c+=("${d# }")
    declare -p c
}

Nota: the line local b c d i is only required for running the function several times.
splitIntFunc 2 1 1 2 3 2 2 4 5 6 7 3 7 0 5
declare -a c='([0]="2 1" [1]="" [2]="3 2 2 4 5 6 7" [3]="" [4]="0" [5]="")'

splitIntFunc 2 1 1 1 4 5 6
declare -a c='([0]="2 1" [1]="1 4 5 6")'

splitIntFunc $(sed 's/./& /g;w/dev/stderr' <<<${RANDOM}${RANDOM}${RANDOM})
1 6 5 3 2 2 4 3 9 4 2 9 7 7 4
declare -a c='([0]="1 6 5 3 2" [1]="4" [2]="9" [3]="2" [4]="7" [5]="4")'

splitIntFunc $(sed 's/./& /g;w/dev/stderr' <<<${RANDOM}${RANDOM}${RANDOM})
2 4 5 2 9 1 1 4 8 7 8 1 0 3
declare -a c='([0]="2 4 5" [1]="9 1" [2]="" [3]="8 7" [4]="1 0 3")'

For sexiest presentation (+26)
splitIntFunc() {
    local b c d i
    for i;do
        [ "${b[i]}" == 7 ]&&c+=("${d# }") d=||d+=\ $i
        b[i]+=7
      done
    c+=("${d# }")
    printf -v l "(%s) " "${c[@]}"
    echo "<$l>"

Will render something like:
splitIntFunc 2 1 1 2 3 2 2 4 5 6 7 3 7 0 5
<(2 1) () (3 2 2 4 5 6 7) () (0) () >

splitIntFunc $(sed 's/./& /g;w/dev/stderr' <<<${RANDOM}${RANDOM}${RANDOM})
4 3 8 1 4 5 7 9 2 7 8 4 0
<(4 3 8 1) (5 7 9 2) () (4 0) >

splitIntFunc $(sed 's/./& /g;w/dev/stderr' <<<${RANDOM}${RANDOM}${RANDOM})
3 1 3 0 2 5 3 6 6 9 2 5 5
<(3 1) (0 2 5 3 6) (9) () (5) >

splitIntFunc $(sed 's/./& /g;w/dev/stderr' <<<${RANDOM}${RANDOM}${RANDOM})
2 2 2 9 1 9 5 0 2 2 7 6 5 4
<(2) (2 9 1) (5 0 2 2 7 6) (4) >

}

Perl 108
map{$e[$_]==1?do{push@a,[@b];@b=();}:push@b,$_;$e[$_]++}split" ";push@a,[@b];s/.*/Data::Dumper->Dump(\@a)/e;

In action:
perl -MData::Dumper -pe '
    $Data::Dumper::Terse = 1;
    $Data::Dumper::Indent = 0;
    @a=@b=@e=();
    map{$e[$_]==1?do{push@a,[@b];@b=();}:push@b,$_;$e[$_]++}split" ";
    push@a,[@b];
    s/.*/Data::Dumper->Dump(\@a)/e;
' <<<$'2 1 1 2 3 2 2 4 5 6 7 3 7 0 5\n2 1 1 1 4 5 6\n'"$(
    sed 's/./& /g;w/dev/stderr' <<< ${RANDOM}${RANDOM}${RANDOM}$'\n'${RANDOM}${RANDOM})"
2 4 4 7 7 2 9 8 8 4 6 0 1 8
1 0 3 9 3 7 9
[2,1][][3,2,2,4,5,6,7][][0][]
[2,1][1,4,5,6]
[2,4][7][][9,8][4,6,0,1,8]
[1,0,3,9][7][]

Nota: The two first lines $Data::... are there only for nicer presentation and third line @a=@b=@e=(); is there for making the tool working on multiple lines.

R, 76
y=scan();r=split(y,cumsum(ave(y,y,FUN=seq)==2));c(r[1],lapply(r[-1],"[",-1))

Output for the example: A list of five elements, including three empty vectors. (numeric(0)).
$`0`
[1] 2 1

$`1`
numeric(0)

$`2`
[1] 3 2 2 4 5 6 7

$`3`
numeric(0)

$`4`
[1] 0

$`5`
numeric(0)

By the way: The code generates a warning message that can be ignored.

awk 29
a[$1]++==1{print"-";next}1

This takes a bit of liberty with the input and output formats. Input "array" is vertical, one number per line. Output is also vertical, one number per line, with dashes separating arrays.
Input:
2
1
1
2
3
2
2
4
5
6
7
3
7
0
5

Output:
2
1
–
–
3
2
2
4
5
6
7
–
–
0
–

Scala, 122111
Take character collection, print in form of [21][][3224567][][0][], 122111:
def s(a:Any*)=print((("[","")/:a){case((b,c),d)=>if(b.indexOf(d)==c.indexOf(d))(b+d,c)else(b+"][",c+d)}._1+"]")

...or take a character collection and return nested lists, 135129:
def s(a:Char*)=(("",List(List[Any]()))/:a){case((b,c),d)=>b+d->(if(b.count(d==)==1)List()::c else(c.head:+d)::c.tail)}._2.reverse

I'm sure there are some savings I could get, I have not looked too hard.

Java: 563 bytes
note this uses Java 8, pre-JDK8 would be a few bytes longer due to the foreach.
import java.util.*;public class a{static String c(String[]b){List<String>d=new ArrayList<>(Arrays.asList(b));Set<String>e=new HashSet<>();Set<String>f=new HashSet<>();for(int i=0;i<Integer.MAX_VALUE;i++){String g;try{g=d.get(i);}catch(IndexOutOfBoundsException ex){break;}
if(e.contains(g)&&!f.contains(g)){d.remove(i);d.add(i,"]");d.add(i+1,"[");f.add(g);i++;}else{e.add(g);}}
d.add(0,"[[");d.add(d.size(),"]]");StringBuilder sb=new StringBuilder();d.forEach(sb::append);return sb.toString();}
public static void main(String[]args){System.out.println(c(args));}}

where else can I use lambda?
looping till array's length is not correct because the list keeps expanding as you add more "]" and "[".

incrementing the length each time is just as lengthy as catching the exception, also I don't think it's possible in Java to change CEILING in (for i = 0; i < CEILING; i++).

Really ?

hmm didn't know that, thanks for pointing out.

What about converting Integer.MAX_VALUE to 2147483647 ? It's the same value with less bytes. Also, IndexOutOfBoundsException can be shortened to Exception

source: Stack Exchange

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

sort: votes


text:
3x3 Connected Components
The Challenge
Consider the 3x3 king grid, as shown in the following ASCII graphic:
A--B--C
|\/|\/|
|/\|/\|
D--E--F
|\/|\/|
|/\|/\|
G--H--I

You are given as input a length-9 list of integers that represent a labeling of the nodes. For example, the input [0,1,1,2,1,0,5,5,1] represents the following labeling:
0--1--1
|\/|\/|
|/\|/\|
2--1--0
|\/|\/|
|/\|/\|
5--5--1

Your output is the set of integers in the input that form connected sets of nodes. More explicitly, the output should contain an integer n from the input if and only if the set of nodes with label n is connected. In this example, an acceptable output would be [1,2,5], since the two 0s are not connected. The lowest byte count wins.
Detailed rules

You can choose a fixed ordering for the nodes in your input list, and you should state this in your answer. In the order EFBDHCAGI, the above labeling would be given as [1,0,1,2,5,1,0,5,1].
You can write either a full program or a function. In the latter case, the output can be a set of integers if your language supports those.
The output list may contain duplicates, but its length must not exceed 9.
Standard loopholes are disallowed.

Test cases
These have single-digit numbers aligned to the grid; adjust them to your chosen order.
011
210 => 1 2 5
551

010
202 => 0 2
221

110
123 => 0 2 3
221

111
111 => 1
111

111
141 => 1 4
111

J, 54 bytes
#~3 :'0<*/,+/ .*/^:8~y#|:y#,/,"1/({0&,:)3 3$#:13'"1@e.

A function taking a list in the order ABCDEFGHI.

Given an adjacency matrix A of a graph of order n, the graph is connected if and only if all the entries of (A + I)n are nonzero, where I is the n×n identity matrix.
We start with the (fixed) adjacency-plus-identity matrix of the 3×3 king grid (in the order ABCDEFGHI,) namely:
1 1 0 1 1 0 0 0 0
1 1 1 1 1 1 0 0 0
0 1 1 0 1 1 0 0 0
1 1 0 1 1 0 1 1 0
1 1 1 1 1 1 1 1 1
0 1 1 0 1 1 0 1 1
0 0 0 1 1 0 1 1 0
0 0 0 1 1 1 1 1 1
0 0 0 0 1 1 0 1 1

.
For each label l, we select the rows and columns corresponding to the nodes of label l.
This gives us the adjacency-plus-identity matrix of the subgraph of l-labeled nodes.
We then use this matrix to test if the subgraph is connected, as described above.
We construct the above matrix by noting that if we let
    0 0 0
Z = 0 0 0
    0 0 0

and
    1 1 0
O = 1 1 1
    0 1 1

, then the matrix can be seen as the 3×3 block matrix
O O Z
O O O
Z O O

, which has the same pattern as O!
O is produced by repeating the pattern 1 1 0 1 in a 3×3 block.

This is an amazing solution! On hindsight, adjacency matrices are probably the shortest way to do this, especially with a language like J.

CJam, 56 67 bytes
q~4/~\@{a1$2<-\(+}%)_)-{_(+{\(a@-\}}A?%+:+[$_(d+1$)c\+@]zLf|2f>:+|`

Order: CIGABFHDE.
Example input:
[1 1 5 0 1 0 5 2 1]

Output:
[1 2 5]

It firstly removes numbers in the corners which are the same as connected numbers on the sides. Then it removes numbers on the sides which are the same as the numbers on the next sides. Finally it removes all numbers occurred two or more times and add the center number.

CJam, 90 bytes
This is based on a iterative flood fill explained here and can be golfed a lot!
q~:Q{:IQ3/S*Sca5*+:T;G,G*{:AT=1$={[WXZ5 4_~_)_)]Af+Tf=AT='#a+&,g{TA'#t:T;}*}*}%;aT\/,3<},p

Requires the input in order of ABCDEFGH like:
[0 1 1 2 1 0 5 5 1]

and output is the connected nodes:
[1 1 2 1 5 5 1]

Brief Explanation

First, I iterate over the input array for each label.
In each iteration, I perform floodfill to figure out disconnected nodes.
If the number of disconnected nodes is greater than 1, then that label is disconnected.

1 because a label can have just 1 occurrence in the input array too.

Then I simply filter out disconnected labels and print the array.

Full explanation to follow
Try it online here

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


text:
Magic box problem
You have an input array of size m*n. Each cell in the array is populated with either P or T. The only operation you can do on the array is flip columns. When you flip a column, the letters in all the cells of that column switch (P becomes T and viceversa). If you have 'x' number of rows with same letter (e.g. PPPP) then you get a point. Design an algorithm that takes in the array and returns a solution (which columns to flip)  such that the resulting array has maximum number of points possible.
Note: In case there are multiple solutions that yield the highest score, choose the one with lowest number of flips. Example:
Input Array:
PPTPP
PPTPP
PPTTP
PPPTT
PPPTT

Output:
3

Explanation:
A solution that yields the highest points: Flip column no. 3
Then the original array would be:
PPPPP // 1 point
PPPPP // 1 point
PPPTP
PPTTT
PPTTT

//Total: 2 points

Note that one could also flip columns 4 and 5 to get a score of two, but that needs an additional flip.
You may use any convenient input format to represent the two dimensional array, and you may also any two distinct, but fixed, values to represent P and T.
This is code golf, so the shortest answer (in bytes) wins.

Welcome to PPCG. This is a great challenge, but it needs a winning criterion to be on topic.

Can I control the input format? Can I say P is False and T is True? If not, what is the input format?

Sure, the input format does not matter. Say you have a two directional array of chars or ints or booleans or whatever type you choose.

You need a winning criterion to decide which of the valid answers is the best. Assuming a valid answer has to give the maximum points for the input grid (BTW you should state this), it should be possible to bruteforce a 32 column grid in reasonable time. Therefore I suggest you make i a codegolf (shortest code wins)

Added the criterion. How is it now?

I don't have time to do an edit myself, but some suggestions for improvement: 1. Edit the question to say that input can use any two distinct values, don't leave it in the comments. 2. This isn't a [tag:programming-puzzle]. It may be a [tag:puzzle-solver]. Read the tag description before adding that tag. 3. It would be a better test case if it didn't have the same value as both the number of the column to flip and the number of rows achieved.

I've worked in Peter's first suggestion. Feel free to change the wording if you don't like it.

Do I get 2 points if one row all Ts and one row is all Ps?

@MartinBüttner, yes you get two points in that case.

"Any convenient input format," you say. Can I ask for each row as an integer, where the binary representation of that integer has a 0 for P and a 1 for T? That would seem a very convenient format for this challenge. ;)

APL, 37
{x/1+⍳⍴x←y[↑⍋(+/∘.≠⍨2⊥⍉y),¨+/y←⍵⍪~⍵]}

Example:
{x/1+⍳⍴x←y[↑⍋(+/∘.≠⍨2⊥⍉y),¨+/y←⍵⍪~⍵]} 5 5⍴0 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 1 1

Tested here.

Pyth, 28
f@eo+/QN/Qm!dN_osZ^U2lhQTUhQ

Takes input in the form of a nested list, e.g.
[[0,0,1,0,0],[0,0,1,0,0],[0,0,1,1,0],[0,0,0,1,1],[0,0,0,1,1]]

Gives output 0-indexed, e.g.
[2]

^U2lhQ: Generates all possible lists of 0s and 1s of the right length.
_osZ: Orders these lists from most 1s to least.
+/QN/Qm!dN: Counts how many times each list (N) and its inverse, 0s and 1s swapped (m!dN) occur in the input. The former corresponds to a series of flips leaving all zeros, the latter to leaving all ones.
eo: Orders the list by the above key, and takes its last element, which will be the result with the most matching columns, and among them the one with the least ones.
f@ ... TUhQ: Converts this list of 1s and 0s to a list of indices to be flipped.
For 1-indexing, change the d to a k, then put mhd at the beginning.

Mathematica - 76
{
{P, P, T, P, P},
{P, P, T, P, P},
{P, P, T, T, P},
{P, P, P, T, T},
{P, P, P, T, T}
}/.{P -> 1, T -> 0};
First@MaximalBy[
  Subsets@Range@Length[%],
  MapAt[1-#&,%,{All,#}]~Count~{1..}&
]

Unless specified otherwise snippets aren't valid submissions. You'll need to write either a function or a full program taking input.

Python 2, 234
from itertools import *
A=input()
n=len(A[0])
R=range(n)
S=(0,)
for p in[q for i in R[:-1] for q in combinations(R,i)]:
    s=[sum([(l[q]+(q in p))%2 for q in R])for l in A]
    m=s.count(n)+s.count(0)
    if m>S[0]:S=(m,p)
print S[1]

Input is a list of lists:
[[0,0,1,0,0],[0,0,1,0,0],[0,0,1,1,0],[0,0,0,1,1],[0,0,0,1,1]]

Output is a tuple of flips using python indexing from 0:
(2,)

If the output must be indexed from 1, then the code is 272 characters with 0 denoting no flips:
print 0 if len(S[1])==0 else [p+1 for p in S[1]]

CJam, 37
q~_{:!}%+:T{T1$a-,\0-+}$0={U):U*}%0-`

Input format:
[[0 0 1 0 0] [0 0 1 0 0] [0 0 1 1 0] [0 0 0 1 1] [0 0 0 1 1]]

Haskell, 98
g s=snd$maximum[((sum[1|o<-s,o==r||o==map(1-)r],-sum r),[i|(i,1)<-zip[1..]r])|r<-s++map(map(1-))s]

input format is a list of list of ints. you can use a string version for testing:
gg = g . map (map (\c -> case c of 'T' -> 0 ; _ -> 1) ) . lines

oh no the spaces! it hurts!
this works by iterating over the rows and calculating the number of points we will get if we flipped the columns in a way that this row gains us a point.
first thing to notice is that flipping the row to either all True or all False doesn't matter, because the grids will be exactly the inverse of each other and thus will have the exact same score.
the way we calculate the count when a given row gains a point is so: we iterate over the rows again, and sum the points each row gives us, using the fact that they do exactly when the rows are either identical or the exact inverse.
for example, if the row we are flipping is TPPTP and the current row we are iterating over is PTTPT or TPPTP then the row gains us a point, but when it's any other row, it doesn't gain us any points.

@MartinBüttner Yes, I will fix it shortly (hopefully)

CJam, 53 51 bytes
l~z:X,,La\{1$f++}/{,}${X\{_X=:!t}/z{_&,(},,}$0=:)S*

This reads a two-dimensional array of 0s and 1s from STDIN. E.g. the example in the question would be
[[0 0 1 0 0] [0 0 1 0 0] [0 0 1 1 0] [0 0 0 1 1] [0 0 0 1 1]]

Test it here.
This first gets all possible subsets of columns, in order of increasing length, then performs the flips for each subsets and sorts them by how many rows still have both 0s and 1s in them. Finally, we just return the first such subset. This relies on the sorting being stable, such that the initial order of increasing length takes care of the tie-breaker.


text:
Area under a curve
Write a program that when given five integers as input, outputs the value given by the following integral:

Input is five integers (in any reasonable format) in the order a b c d e where each number corresponds to the variables in the image above.
No built in integral functions allowed.
Output must be a base ten float, precise to +/- 1e-3.

Least number of bytes wins.

Why would you want to use a built-in integral function? It's just printing out an arithmetic expression.

@feersum A built-in integral function might give an unfair advantage

Hard to believe an integral function is unfairly advantageous compared to finding the difference of ax^3/3+bx^2/2+cx at two points.

@feersum Well, it's there as a rule just in case :)

Why all the downvotes?

Apparently many people agree that Input: x,y Output: 3x + 5y is too boring to be good question.

@feersum Mm.. I'll keep that in mind next time. :)

I'm just near the Naruto hat if you didn't upvote...

@user23013 I have

CJam, 27 bytes
q~W%2/~~[2*\~3*\6*0]fb:-6d/

Example input:
[1 2 3 4 8]

Output:
209.33333333333334

CJam, 46 43 bytes
l~\:D-A3#:K*),])\f{\dK/D+\~\Z$*+@_*@*+K/}:+

The arguments are read via STDIN like
1 2 3 4 7

and the output is printed to STDOUT like
135.04650050000018

You can increase the precision by changing the 3 in A3#:K to a higher number. The higher the number, the longer the program will take to finish.
Try it online here

R, 71 bytes
If the input is a vector x <- c(a, b, c, d, e) then you can compute the integral directly as per @feersum's comment.
e=x[5];d=x[4];x[1]*e^3/3+x[2]*e^2/2+x[3]*e-x[1]*d^3/3-x[2]*d^2/2-x[3]*d

JavaScript, 52 bytes
(a,b,c,d,e)=>a*e^3/3+b*e^2/2+c*e-a*d^3/3-b*d^2/2-c*d

Calculates the indefinite integral at e and d, then subtract.