50
\$\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).
\$\endgroup\$
  • 13
    \$\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 '14 at 14:28
  • 13
    \$\begingroup\$ On a related note, GNU true.c is 80 lines long. \$\endgroup\$ – Paused until further notice. Dec 17 '14 at 22:32
  • 6
    \$\begingroup\$ @DennisWilliamson On a similarly related note, false.c is 2 lines long.... ;_; \$\endgroup\$ – LordAro Dec 18 '14 at 2:30
  • 6
    \$\begingroup\$ the coreutils yes takes an optional argument on the command line, not stdin. \$\endgroup\$ – Brian Minton Dec 18 '14 at 20:05
  • 7
    \$\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\$ – marcus erronius Dec 20 '14 at 16:57

67 Answers 67

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\$
  • \$\begingroup\$ To qualify for the bonus, I think this should print y if no input is given. \$\endgroup\$ – Kritixi Lithos Apr 15 '18 at 12:42
  • \$\begingroup\$ @Cowsquack Nope, it's optional \$\endgroup\$ – Jo King Apr 15 '18 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\$
  • \$\begingroup\$ You don't need to print y if there's no input \$\endgroup\$ – Jo King Sep 20 '19 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\$ – Kevin Cruijssen Oct 8 '19 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 '19 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\$

W s, 9-10 = -1 bytes

ib12 1C|E

Explanation

Flag: s % We have to read from STDIN :(
i   E   % Foreach from 1 to infinity:
 b      % Take the value of the second operand
        % (the first operand is the infinity-count value)
        % AND print this value with a newline
  12 1| % Just uses a space to do the constant-avoiding job.

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'
\$\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\$
  • \$\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\$ – Post Rock Garf Hunter Dec 23 '19 at 16:57
  • \$\begingroup\$ Does it satisfy constraint about closing program? \$\endgroup\$ – Qwertiy Dec 23 '19 at 16:59
  • \$\begingroup\$ @WheatWizard, python doesn't support semicolons. \$\endgroup\$ – Qwertiy Dec 23 '19 at 17:00
  • \$\begingroup\$ Oh right. So I'm not even allowed newlines in my source. Got it! :laugh: \$\endgroup\$ – Andrew Parker Dec 23 '19 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\$ – Andrew Parker Dec 23 '19 at 18:10
0
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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