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

92 Answers 92

1 2 3
4
0
\$\begingroup\$

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

Nim, 37 - 10 = 27 bytes

var x=readLine stdin;while 1>0:echo x

Attempt This Online!

\$\endgroup\$
1 2 3
4

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.