创建一个鹦鹉程序


15

给定输入,输出该输入,然后不断地换行。

输入将是仅由可打印的ASCII字符(0x20-0x7E)和换行符(0x0A)组成的字符串。

如果输入长度为0,则不断输出换行符。

这是因此每种语言中最少的字节会获胜!


是的一半是91行
manatwork


@VoteToClose我知道我以前..回答了这个
L3viathan

微软,史蒂夫·鲍尔默Steve Ballmer)1

Answers:


13

Bash,8个字节

yes "$1"

在线尝试!


该死的,迟到十分钟!但这不会将换行符打印为换行符。
phil294

抱歉,我不是指- yes换行符,而是输入中可能包含的任何换行符都打印为\n。取决于您如何阅读问题:D
phil294

@Blauhirn哦,我误会了这一部分:/。您需要称其为./script $'Hello\n World'包括真正的换行符。在TIO上,您可以在命令行参数中添加换行符
ovs

1
是否需要报价?yes $1对我来说效果很好
DrnglVrgs

2
@DrnglVrgs对于空输入,这对我不起作用
ovs

9

05AB1E,2个字节

[,

在线尝试!


你为什么不这样做[I,
FrodCube

@FrodCube:不幸的是,这不适用于空输入:(
Emigna

@FrodCube:实际上,该问题指出了长度为0的输入,而不是空输入,因此我可以减少它:)
Emigna

1
@FrodCube:是的,实际上这是05AB1E中的一个相当新的功能。我敢肯定,欧姆最终也会成功。
Emigna

10
[=也有效,是一张笑脸;微笑是唯一的好处。
Magic Octopus Urn


5

欧姆,3个字节

∞┼,

在线尝试!

它不适用于空输入,因为与其他语言相比,欧姆在输入处理方面很糟糕,但是您可以输入“”。

说明

∞     Infinite loop next code (until ";" or end of line)
 ┼    Get first input
  ,   Println

这看起来很酷...您能否解释一下:D
Beta Decay

@BetaDecay完成了!
FrodCube

1
仅供参考,Ohm v2(希望很快就会上市)将具有比以前更好的输入处理!
尼克·克利福德

@NickClifford酷!我很期待!我喜欢你的语言
FrodCube

1
噢...欧姆像05AB1E带有不同的命令吗?狂热地开始阅读GitHub页面
Magic Octopus Urn

5

sed,5岁

:      # label (unnamed) 
p      # print the pattern space
b      # branch back to the label

未命名标签是sed中未记录的“功能”,可用于4.2.2版,但在以后的版本中可能无法使用。





4

V,2个字节

òÙ

出于明显的原因,您不能在线尝试此操作。

ò    'Recursively
 Ù   'Duplicate the current line downwards

TIO实际上会运行60秒钟,然后终止并向上打印STDOUT,直到终止点被截断为第一个128KiB。
Magic Octopus Urn

1
V因为直到它完成它输出的nvim会议的内部,而不是打印到stdout,TIO杀死会话时,看到一个STDOUT什么。我不知道您说什么,但很遗憾,它不能解决V
nmjcman101

1
啊...不幸的是,我忘记了V的属性,我仅成功使用了一次。
Magic Octopus Urn


3

自动热键,20字节

OP没有具体说明如何输出应该发生,仅表示,已与后一个换行符无休止地发生。AHK不是为cmd交互量身定制的。因此,输出ToolTip在鼠标位置的a 处重复发生:

tooltip

loop
tooltip,%1%`n`n

我喜欢AHK的loop功能。loop永远重复下一个块,loop, 10将重复10次。有时我会错过其他语言(例如Python)的此功能。

AutoHotkey中的转义字符是`(因此Windows路径中的反斜杠没有问题)。由于某种原因,尾随的换行符将被忽略,因此需要两次。(trayTip可能没有这个“ bug”,但是我无法测试它,因为使用wine运行)

旧答案:

loop
msgbox,%1%

我只是意识到OP可能不会喜欢这种解决方案,输出是通过用户交互进行的,并且不包含换行符。我会寻找另一种方式。


1
好吧,您
赞成

3

LibreLogo,33个字节

码:

x=input " repeat [ label x bk 9 ]

说明:

x = input "               ; Input Stored in x as String
repeat [                  ; Endless Loop
    label x               ; Print x in Current Position
    bk 9                  ; Move Back 9 pt
]

结果:

enter image description here


2

Python 2,25个字节

s=input()
while 1:print s

在线尝试!

输入应该是Python文字(字符串,方括号或带逗号分隔的列表/元组等的括号等)。

Python 3将是+1字节,因为它print是一个函数,但也可以进行原始输入,而不会给raw_input()Python 2 带来4字节的损失。





2

Braingolf14 12字节

#
V[R!&@v1+]

在线尝试!

-2个字节,由于完全人性化

说明

#\nV[R!&@v1+]  Implicit input of string as charcodes
#\n            Push charcode of newline
   V           Create stack2
    [R...v1+]  While loop, runs endlessly
      !&@      Print entire stack1 as chars without popping

2

C,24个字节

f(char*s){puts(s),f(s);}

基本上是一个递归函数,可在再次调用自己之前输出字符串。这是我在codegolf上的第二篇文章,所以请保持友善:p


2

Cubix,6个字节

AN/qvo

在这里测试

  A
N / q v
  o
  • N/A 按换行符(10)并输入到堆栈中
  • v 重定向到循环
  • o/q 输出一个字符并将其连续推入堆栈底部的循环

I was going to remove the EOI (-1) indicator from the stack, but it doesn't appear to affect the output any, so have left it saving bytes.


1

Japt, 5 bytes

OpU;ß

Try it online!

Explanation

OpU;     output the input with a newline
    ß    run the code again with the same input


1

MATL, 4 bytes

`GDT

Try it Online

Explanation

`     % Do...while loop
  G   % Grab input
  D   % Display it on a new line
  T   % Literal TRUE to create an infinite loop

1

C, 26 bytes

f(char*s){for(;;)puts(s);}

A function, f, that takes a C-style string as a parameter, s. The body of the function loops repeatedly, passing the string to the library function puts, which outputs the string to the standard output (stdout) along with a trailing new-line.

Pretty simple stuff. The only hack here is taking advantage of default-int for the return value and then not actually returning a value. That doesn't matter in this case, though, since the function never returns (it just keeps printing forever)!

Try it online!


f(char*s){puts(s);f(s);} saves a few
nmjcman101


1

Java 8, 34 bytes

s->{for(;;System.out.println(s));}

Surprised there wasn't a Java answer yet.

Try it here. (Wait 60 second for it to time-out.)


you don't need to wait for it to timeout, it'll reach the max output buffer of 128kb much faster than that :P
Skidsdev

@Mayube Perhaps, but it's still running Real time: 60.008 s according to the Debug-section before it outputs the result (and gives two warnings 60-sec limit exceeded and 128kb exceeded).
Kevin Cruijssen

1
TIO also caches the results, so once it's been run and hit the timelimit, the output is cached and will simply be served to others who run it without actually re-compiling and running the code
Skidsdev

@Mayube True. I didn't knew this also applied to others. Thought it was a local cache. In that case you can ignore the "(Wait 60 second for it to time-out.)" in my answer. :) But if you check on the "disable output cache" setting you'll see it takes ~ 60 seconds.
Kevin Cruijssen

1

Pyth, 2 bytes

#

Unfortunately I can't remove Q :(

You need to run from command-line like this, so that this is competing:

python3 pyth.py -c "#
"

The interpreter has been fixed too.


1

><>, 16 bytes

i:0(?v
:o71.>~a{

Try it online!

As mentioned in the comments below my first attempt may have misunderstood the question so the newer 16 byte solution has been made, I have left the original below so people may see.

><>, 13 bytes

<ov!?+1:i
oa<

Try it online!


I think there's been a bracketing problem: this code returns "that input followed by (a newline endlessly)", while most of the other answers give "(that input followed by a newline) endlessly"…
Not a tree

@Notatree, Thanks for mentioning this, I have updated my answer to respect your comment :)
Teal pelican

Nice, my best try was 17 bytes!
Not a tree

@Notatree, I changed the check in the first line from 1+?!v to 0)?v which saved a byte, what was your solution, would be nice to see more ><> answers :) - I also believe with some nifty mirrors you may be able to remove the jump instructions too but haven't figured it out yet.
Teal pelican

1
@Notatree, you were really close to the 16 bytes as well, change your second line to a\~ then move your last line around 1 to o>{: and you would have made it. the jump is just to cut out on extra mirrors across lines but yours works just as well :)
Teal pelican


1

Perl 5, 27 bytes

while(1){print"$ARGV[0]\n"}

Try it online!


input will always be given, it just might be an empty string, so you should be able to do while(1){print"$ARGV[0]\n"}
Skidsdev

@Mayube - thx, updated answer.
tale852150

Also welcome to ppcg! I fixed the formatting on your answer for you, in the future I totally recommend using Try it online (linked in the edited answer) as it not only makes testing way easier, but can give you a fully formatted ppcg answer to post
Skidsdev

@Mayube - thx, glad to be here...
tale852150

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.