# 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)

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.
• "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"? Dec 17, 2014 at 14:28
• On a related note, GNU true.c is 80 lines long. Dec 17, 2014 at 22:32
• @DennisWilliamson On a similarly related note, false.c is 2 lines long.... ;_; Dec 18, 2014 at 2:30
• the coreutils yes takes an optional argument on the command line, not stdin. Dec 18, 2014 at 20:05
• @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. Dec 20, 2014 at 16:57

# 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. Dec 18, 2014 at 2:27

# 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. Dec 17, 2014 at 14:42
• Yeah, I noticed after that you reused the 10, sorry :P Dec 17, 2014 at 14:47
• Instead of 10*12+1, why not 11*11? I think that could save you a char. Dec 17, 2014 at 14:52
• @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. Dec 17, 2014 at 14:54
• @undergroundmonorail Ah, I see. Dec 17, 2014 at 14:55

# 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:printhelp[1]. Dec 17, 2014 at 14:04
• Haha, nice. I completely forgot that there "used to" be a backtick operator in python :)
– pgy
Dec 17, 2014 at 16:30
• You could use chr(11**2) to save a few characters as well Dec 19, 2014 at 22:33
• @RamchandraApte You're not allowed to use 121. Dec 21, 2014 at 6:24
• Why does this output y's?
– user9207
Mar 29, 2020 at 10:54

# Pyth, 109 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. Dec 18, 2014 at 16:48
• Switched from "^11 2" to "^hT2" to save a character. Dec 18, 2014 at 17:13
• 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. Dec 20, 2014 at 8:03
• 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. Dec 21, 2014 at 3:31

# 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#, 8178 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. Dec 17, 2014 at 15:56
• @toothbrush I have tried that, but that doesn't work in C#. Dec 17, 2014 at 15:57
• for(;;) should work. Dec 17, 2014 at 16:07
• For some reason, this code still has a y in it. Please examine System. Dec 18, 2014 at 16:04
• @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. Dec 18, 2014 at 16:39

## 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. Dec 18, 2014 at 4:30
• 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 Dec 18, 2014 at 22:58
• @corsiKa Good point. Dec 19, 2014 at 3:51

# 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. Dec 17, 2014 at 22:19 • @vurp0 yes does not take input from STDIN after all :) Dec 18, 2014 at 23:55 • It doesn't, but the code golf question here specified that if it doesn't receive input, it should repeatedly print y\n. Dec 19, 2014 at 0:00 • @vurp0 Where? Any program that reads from a stream will hang without input. Dec 19, 2014 at 0:02 • @vurp0 See the OP's comment on the question. Dec 19, 2014 at 12:32 # Ruby, 3023 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 Dec 17, 2014 at 14:39 • @manatwork Thanks! Updated. Dec 17, 2014 at 14:41 # 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. Dec 17, 2014 at 14:00
• oh wait, i didn't see the "you can't use \"y\"" part of the question. nevermind this is bad Dec 17, 2014 at 14:01
• Right you are. Fixed it
– Nitz
Dec 17, 2014 at 14:23

## C, 64555345 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 # 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. Dec 18, 2014 at 16:14 • Or sed q for line. Dec 18, 2014 at 16:15 # 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? Dec 19, 2014 at 12:37 • I knew about P but didn't know it can do more than one character at a time. Dec 23, 2014 at 13:52 ## 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. Dec 17, 2014 at 17:35
• My bad, I should not have tried it after à day of work. Dec 17, 2014 at 17:43
• How about read a;for((;;));{ echo $a;} Dec 19, 2014 at 22:16 # 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. Dec 18, 2014 at 0:58 • @MartinBüttner Fair enough. Oddly enough, it would seem that rust isn't the best language for code golf >:P Dec 18, 2014 at 1:00 • You can add one to x in a fashion, but it's still not short: (b'x' + 1) as char Dec 20, 2014 at 16:13 ## 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). ## 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. Dec 19, 2014 at 9:12 • @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". – Mark Dec 19, 2014 at 10:58 • Very good, but you could save one byte by replacing "Goto 1" by "Run" : "1?cH(89):rU" Dec 20, 2014 at 12:07 • @LeFauve, Thanks. I've also applied it to the ASCII-emitting version. – Mark Dec 20, 2014 at 12:29 # 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... # 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' Dec 21, 2014 at 23:55 # 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}  # 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 Dec 19, 2014 at 16:16 ## 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. ## 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. Dec 21, 2014 at 23:10
• 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. Dec 21, 2014 at 23:12
• @chris-l fixed the type, thanks. I also removed the claim regarding the bonus, but I will leave my answer as it is :-P Dec 22, 2014 at 9:09
• 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. Dec 22, 2014 at 20:31

# C, 32 bytes

Requires little endian machine and compilation with -O2 (to avoid stack overflow).

a=11*11;main(){main(puts(&a));}


### 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, 5857 56 bytes

for(n=''+Function()};;)process.stdout.write(n[13]+n[19])

• Welcome to code golf, and nice answer! Nov 16, 2021 at 17:53
• @RedwolfPrograms Thanks! Nov 16, 2021 at 18:16
• Your second answer uses y in crypto! Apr 21 at 21:01
• @Matthew Jensen Indeed it does! Apr 21 at 23:47

## 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!) Dec 19, 2014 at 20:26

## 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. Aug 4, 2015 at 18:28
• @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. Aug 4, 2015 at 19:28
• 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. Aug 5, 2015 at 6:26

# 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. Mar 1, 2017 at 15:15
• @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...
~W-1z'N~
`