| Bytes | Lang | Time | Link |
|---|---|---|---|
| nan | Raku Perl 6 rakudo | 250415T213131Z | xrs |
| nan | Tcl | 250409T204211Z | sergiol |
| 102 | Go | 230202T231501Z | bigyihsu |
| 009 | Trilangle f | 230414T132124Z | Bbrk24 |
| 025 | Python | 230414T122148Z | The Empt |
| 025 | Python 3 | 230413T212445Z | Hunaphu |
| nan | Fig | 230207T151102Z | Seggan |
| nan | GolfScript | 230207T135122Z | emirps |
| nan | 230204T180024Z | The Thon | |
| nan | Nim | 220606T145918Z | Qaziquza |
| 014 | Zsh | 220605T204733Z | GammaFun |
| 014 | Nooklang | 220422T131215Z | oeuf |
| 037 | Javascript | 211116T174301Z | spidunno |
| 031 | JavaScript | 211118T152106Z | CreaZyp1 |
| 022 | Zsh + POSIX utilities | 211111T223030Z | Gilles & |
| 8210 | Vyxal | 211117T091802Z | SjoerdPe |
| 8680 | JavaScript Node.js | 211110T162915Z | sech1p |
| 029 | Zsh | 211111T013530Z | roblogic |
| nan | Pxem | 210322T133257Z | user1004 |
| nan | brainfuck | 210309T173759Z | Christia |
| 3710 | BRASCA | 210309T080504Z | SjoerdPe |
| 008 | 05AB1E | 210308T235254Z | Makonede |
| 9101 | Raku raku n 910 = 1 bytes | 200404T030809Z | Sebastia |
| nan | C gcc | 200404T022711Z | S.S. Ann |
| nan | Kotlin | 200403T054619Z | snail_ |
| 1109 | Husk | 200401T100044Z | user9206 |
| 1109 | W s | 191223T115758Z | user8505 |
| 008 | Ahead | 190920T044235Z | snail_ |
| nan | Mumps M | 191223T185550Z | zmerch |
| nan | Python 3 | 191223T163830Z | Andrew P |
| nan | Microscript | 150530T193222Z | SuperJed |
| 000 | Perl 5 1010 = | 190920T220912Z | rpGYNay0 |
| 025 | Python 3 | 190920T130457Z | gadzooks |
| 8102 | MathGolf | 190920T125336Z | maxb |
| 5105 | ><> | 180415T121423Z | Jo King |
| 039 | Tcl | 180415T120825Z | sergiol |
| nan | Chip | 170606T181945Z | Phlarx |
| 008 | TIBASIC | 170303T010127Z | Hactar |
| 006 | ><> | 170302T124638Z | PidgeyUs |
| nan | AHK | 170302T131441Z | Engineer |
| 023 | OIL | 170302T114126Z | L3viatha |
| nan | R | 170302T090035Z | rturnbul |
| nan | Python 3 | 170302T081601Z | sagiksp |
| 051 | R | 170302T044445Z | BLT |
| 7103 | Jelly | 170302T042544Z | walpen |
| 5105 | APL Dyalog APL | 170301T102443Z | Adá |
| nan | Ohm | 170301T094406Z | Linnea G |
| nan | PHP | 170301T024848Z | Titus |
| 161 | CGCC | 170228T224458Z | user6333 |
| nan | Vitsy | 170212T162349Z | Addison |
| 016 | QC 26 26 10 = | 170211T204250Z | user6333 |
| nan | SmileBASIC | 170211T194235Z | 12Me21 |
| 032 | C | 141218T163419Z | nutki |
| nan | 150804T180559Z | Charlie | |
| nan | 141217T164027Z | coredump | |
| 005 | Fission | 150530T230750Z | Martin E |
| nan | 141224T165838Z | xenia | |
| 004 | Pyth | 141218T162819Z | swstephe |
| 031 | Perl | 141221T132446Z | xebtl |
| 5363 | Node.js | 141221T051906Z | chris-l |
| 035 | C | 141221T025707Z | BenjiWie |
| 042 | C | 141220T192923Z | bacchusb |
| 038 | AWK | 141217T172931Z | LeFauve |
| 167 | Lazy K | 141220T155203Z | jimmy230 |
| 013 | Commodore 64 Basic | 141217T230938Z | Mark |
| 247 | CFML | 141219T211559Z | Matt Gut |
| 076 | C# | 141217T142113Z | ProgramF |
| nan | dc | 141218T151919Z | user344 |
| 012 | dc | 141219T045451Z | Digital |
| 014 | JAGL V1.0 20 10 = 10 With Bonus | 141218T054509Z | globby |
| nan | linux Bash | 141218T131754Z | Olivier |
| 040 | Pascal | 141219T133139Z | manatwor |
| 028 | Fortran | 141219T131802Z | xebtl |
| 018 | Perl | 141217T162042Z | core1024 |
| 026 | Perl | 141217T135059Z | Nitz |
| nan | Ruby | 141217T184219Z | alexande |
| 178 | Java | 141217T235810Z | Ypnypn |
| nan | Lua | 141217T200826Z | Digpoe |
| 027 | Python 3 | 141217T135702Z | pgy |
| nan | Java | 141218T162438Z | TheNumbe |
| 037 | C89 | 141218T143934Z | rubenvb |
| 024 | Windows Batch | 141218T123641Z | Jean-Fra |
| nan | 141218T103508Z | Matt Win | |
| 019 | Linux Bash | 141218T041918Z | Johnny |
| nan | C | 141218T001027Z | LordAro |
| 052 | Rust | 141218T005317Z | Matt Win |
| 029 | Haskell | 141218T001836Z | Taneb |
| nan | Linux Bash | 141217T172619Z | Orace |
| nan | PowerShell | 141217T165032Z | Joey |
| nan | CJam | 141217T134059Z | Martin E |
| 014 | Marbelous | 141217T153305Z | overacto |
| 038 | Brainfuck | 141217T143518Z | undergro |
| nan | Apparently this isn't totally portable. My sys.version is 2.7.9 default | 141217T144834Z | undergro |
| 018 | Ruby | 141217T143516Z | ProgramF |
Raku (Perl 6) (rakudo), 18 bytes - 10 bonus = 8 pts
loop {say ~@*ARGS}
Doesn't display properly on ATO or TIO. For one more byte it will:
say ~@*ARGS while 1
Go, 92 102 bytes
package main;import(."os";."fmt");func main(){s:=string('x'+1);if len(Args)>1{s=Args[1]};{Println(s)}}
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)}}
+10 bytes for removing "y" and newlines.
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 stacko: 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.
Python, 25 Bytes
while 1:print(chr(~-122))
Never knew you could do bitwise operations on non-binary numbers!
Fig, \$2\log_{256}(96)\approx\$ 1.646 - 10 \$\approx\$ -8.354 bytes
(,
Prints the input forever. Simple.
GolfScript, 15 10-10=0 bytes
{.puts.}do
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.
Thunno, \$ 11 \log_{256}(96) \approx \$ 9.05 - 10 \$ \approx \$ -0.95 bytes
[z011D*C~ZK
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
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
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
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])
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 returnsInfinityin javascript""+convertsInfinityinto a string[7]access the 8th character of"Infinity"(y)
To terminate the process do Ctrl+C (SIGINT)
Zsh + POSIX utilities, 22 bytes
f()(tr 01 x-z<<<1;f);f
Thanks to pxeger for the shorter way to print y.
Pure zsh, 24 bytes
f()(<<<$SPROMPT[29];f);f
Bonus: mandatory phrase from stdin — 21 - 10 bytes
read a;f()(<<<$a;f);f
Vyxal, -8 bytes (2-10 bytes)
Not the most original method, but it's short.
{,
Explanation
{ - While non-zero
, - Print implicit input
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])
-6 bytes thanks to me
Zsh, 29 bytes
for ((;;))<<<${(#)$((11*11))}
tio example (times out)
Not cheating like the bash answer...
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
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!
brainfuck, 60-10=50 bytes
+>>,[[>,]>+<]++++++++++>-[<[<+<++++++++++++>>-]]<[[<]>[.>]<]
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'
BRASCA, -3 bytes (7-10)
l,[:mo]
Explanation
<implicit input>
l - Push 10 (\n)
, - Reverse stack
[ ] - While non-zero:
:mo - Duplicate, move the duplicate to bottom, output top of stack
Raku (raku -n) 9-10 = -1 bytes
.say;redo
Idea for redo from @booshlinux (I would have done: loop{.say})
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 :)
∞
Explanation
Implicit argument
∞ Build an infinite list repeating forever
Implicit join by newlines
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'
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).
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)")
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).
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.
MathGolf, 8 bytes -10 = -2
╜É'x)Äo∟
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.
><>, 5 bytes - 10 = -5
a{:o!
Takes input via the -s flag and repeats it forever until the program is interrupted.
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'.
TI-BASIC, 8 bytes
While not(getKey:Disp Str0:End
><>, 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.
AHK, 38 bytes - 10 = 28
c=%1%
Loop,3
FileAppend,% c Chr(9+1),*
- I may have misunderstood, but I think the
9+1is allowed. If not, I'll delete this. - If
Loopis used without brackets{}, it is assumed that only the next line is part of the loop. - If
Loopis used without a count, it will repeat until it encounters aBreak. - Per the help file, if an asterisk is passed as the filename into
FileAppend, it outputs tostdout. %1%is the first passed argument.- If I could use the input variable
%1%directly, that would have been nice. It gets funny with theChrfunction following it, though, and would have ended up being more bites.
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
R, 27-10 = 17 bytes
x=scan(,'');repeat print(x)
Repeats stdin over and over and over. No y or \n in the code.
Python 3, 40 bytes - 10 = 30
i=input()
while 1:print(i or chr(11**2))
Stops with SIGINT (Ctrl+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.
Jelly, 7 - 10 = -3 bytes
ØyṪ³ȯṄß
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"
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.
⎕ STDOUT with trailing newlines,
← gets
⍣ repeatedly until
≢ it differs from
⍞ STDIN
i.e. never, but uninterruptible by pausing the thread.
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
■}
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)
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);
}
}
}
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.
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)
SmileBASIC, 19 bytes - 10 = 9
INPUT C$@L?C$GOTO@L
C, 32 bytes
Requires little endian machine and compilation with -O2 (to avoid stack overflow).
a=11*11;main(){main(puts(&a));}
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
Common Lisp : (30-10) = 20
(format t"~@{~a~%~:*~}"(read))
(read)from input stream- print to output stream:
(format t ... ) - iterate over all
formatarguments (only one here) :~@{ ... ~} inside the loop, for each argument:
- print argument
~Afollowed by a newline~% - rewind current element to the previous one
~:*(infinite loop)
- print argument
You can break the loop with Ctrl+C, which signals an error with restart options (continue/abort).
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...
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
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'
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}
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.
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. :)
C 42
main(){while(1){putchar(11*11);puts("");}}
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.
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
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
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#, 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.
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.
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.
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
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]
Pascal: 40 characters
begin while 1=1do Writeln(Succ('x'))end.
Outputs “y”, stops on SIGINT.
Fortran, 28
do1;1 print'(A1)',11**2;end
Compile with gfortran -ffree-form.
Perl: 18 bytes - 10 = 8
The string is from STDIN.
$_=<>;{print;redo}
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}
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}
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.
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).
Python 3, 27 bytes
Works with at least CPython and Jython.
while 1:print(str(help)[1])
SIGINT stops it.
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});}}
C89, 31 37 chars
main(){for(;;)printf("%c\n",'z'-1);}
Built on the idea of @LordAro, without filename requirements.
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
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.
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
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
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"))}}
Haskell, 29 bytes
main=putStrLn[succ 'x']>>main
I believe this is stopped by both SIGINT and SIGPIPE.
Linux Bash, 33-10 = 23
read a; while :; do echo $a; done
Can be killed with SIGINT by pressing Ctrl+C.
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}
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.
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.
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
++++++++++[>,]<<[[<]>>[[.>]<[<]>]]>[>++++++++++++>+<<-]>+[.>.<]
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).
Ruby, 30 23 18 bytes
loop{puts ?x.succ}
Can be killed with SIGINT by pressing Ctrl+C.
Thanks to manatwork for sharing improvements!