56
\$\begingroup\$

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

92 Answers 92

1
\$\begingroup\$

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)

\$\endgroup\$
1
\$\begingroup\$

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
\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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

(,

Try it online!

Prints the input forever. Simple.

\$\endgroup\$
4
  • \$\begingroup\$ Should this be -8 bytes? \$\endgroup\$
    – mousetail
    Feb 8, 2023 at 14:04
  • \$\begingroup\$ oops :P thanks ineedmorechars \$\endgroup\$
    – Seggan
    Feb 8, 2023 at 17:20
  • \$\begingroup\$ What??? a negative amount of bytes??? \$\endgroup\$ Apr 14, 2023 at 11:22
  • \$\begingroup\$ oh challenge specs \$\endgroup\$ Apr 14, 2023 at 11:22
1
\$\begingroup\$

Python, 25 Bytes

while 1:print(chr(~-122))

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

\$\endgroup\$
1
  • 2
    \$\begingroup\$ ...what's a non-binary number? Like a float(?), but you're not even using a float \$\endgroup\$
    – Jo King
    Apr 16, 2023 at 4:13
1
\$\begingroup\$

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.

\$\endgroup\$
1
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ this has an "y" in it, as far as I can tell... \$\endgroup\$ Oct 20, 2023 at 10:28
0
\$\begingroup\$

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});}}
\$\endgroup\$
0
\$\begingroup\$

Pascal: 40 characters

begin while 1=1do Writeln(Succ('x'))end.

Outputs “y”, stops on SIGINT.

\$\endgroup\$
0
\$\begingroup\$

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 
\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

C 42

main(){while(1){putchar(11*11);puts("");}}
\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
0
0
\$\begingroup\$

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)

\$\endgroup\$
0
\$\begingroup\$

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"

\$\endgroup\$
0
\$\begingroup\$

Python 3, 40 bytes - 10 = 30

i=input()
while 1:print(i or chr(11**2))

Stops with SIGINT (Ctrl+C)

\$\endgroup\$
0
\$\begingroup\$

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
\$\endgroup\$
0
\$\begingroup\$

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.
\$\endgroup\$
0
\$\begingroup\$

TI-BASIC, 8 bytes

While not(getKey:Disp Str0:End
\$\endgroup\$
0
\$\begingroup\$

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'.

\$\endgroup\$
0
\$\begingroup\$

Tcl, 39 bytes

while 1 {puts [format %c [expr 11*11]]}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

><>, 5 bytes - 10 = -5

a{:o!

Try it online!

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

\$\endgroup\$
2
  • \$\begingroup\$ To qualify for the bonus, I think this should print y if no input is given. \$\endgroup\$
    – user41805
    Apr 15, 2018 at 12:42
  • \$\begingroup\$ @Cowsquack Nope, it's optional \$\endgroup\$
    – Jo King
    Apr 15, 2018 at 13:13
0
\$\begingroup\$

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.

\$\endgroup\$
3
  • \$\begingroup\$ You don't need to print y if there's no input \$\endgroup\$
    – Jo King
    Sep 20, 2019 at 22:12
  • \$\begingroup\$ 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. \$\endgroup\$ Oct 8, 2019 at 12:10
  • \$\begingroup\$ @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. \$\endgroup\$
    – maxb
    Oct 10, 2019 at 10:35
0
\$\begingroup\$

Python 3, 25 bytes

while 1:print(chr(11*11))

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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

\$\endgroup\$
0
\$\begingroup\$

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)")
\$\endgroup\$
6
  • \$\begingroup\$ 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. \$\endgroup\$
    – Wheat Wizard
    Dec 23, 2019 at 16:57
  • \$\begingroup\$ Does it satisfy constraint about closing program? \$\endgroup\$
    – Qwertiy
    Dec 23, 2019 at 16:59
  • \$\begingroup\$ @WheatWizard, python doesn't support semicolons. \$\endgroup\$
    – Qwertiy
    Dec 23, 2019 at 17:00
  • \$\begingroup\$ Oh right. So I'm not even allowed newlines in my source. Got it! :laugh: \$\endgroup\$ Dec 23, 2019 at 17:08
  • \$\begingroup\$ Best I can get with the bonus is 27, and I need the walrus to do that: x,*_=iter(lambda:print(z),z:=input()) \$\endgroup\$ Dec 23, 2019 at 18:10
0
\$\begingroup\$

Kotlin, 23 - 10 = 13 bytes

{while(1>0)println(it)}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

C (gcc), 30 - 10 = 20 bytes

f(a){for(gets(&a);puts(&a););}

Try it online!

\$\endgroup\$
0
\$\begingroup\$

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!

\$\endgroup\$
0
\$\begingroup\$

Zsh, 29 bytes

for ((;;))<<<${(#)$((11*11))}

tio example (times out)

Not cheating like the bash answer...

\$\endgroup\$
1
  • 1
    \$\begingroup\$ 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) \$\endgroup\$ Nov 11, 2021 at 22:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.