Crie um programa Parrot


15

Dada uma entrada, produza essa entrada seguida por uma nova linha sem parar.

A entrada será uma sequência que consiste apenas em caracteres ASCII imprimíveis ( 0x20-0x7E) e novas linhas ( 0x0A).

Se a entrada tiver comprimento 0, imprima novas linhas de forma interminável.

Isso é e o menor número de bytes em cada idioma vence!




@VoteToClose eu sabia Eu respondi isto antes ..
L3viathan

Microsoft, 1 Steve Ballmer - desenvolvedores, desenvolvedores, desenvolvedores, ...
sergiol

Respostas:


13

Bater , 8 bytes

yes "$1"

Experimente online!


caramba, 10 minutos atrasado! mas isso não imprime novas linhas como novas linhas.
phil294

desculpe, eu não quis dizer as yesnovas linhas, mas qualquer nova linha que possa estar contida na entrada é impressa como \n. depende de como você lê a pergunta: D
phil294 5/17/17

@Blauhirn Oh, eu não entendi bem essa parte: /. Você precisa chamar isso ./script $'Hello\n World'para incluir novas linhas reais. No TIO, você pode simplesmente adicionar uma nova linha ao argumento da linha de comando
ovs

1
As cotações são necessárias? yes $1funciona bem para mim
DrnglVrgs

2
@DrnglVrgs isso não funciona para mim para uma entrada vazia
ovs

9

Por que você não está fazendo [I,?
precisa saber é o seguinte

@FrodCube: Porque, infelizmente, isso não funciona com entradas vazias :(
Emigna

@FrodCube: Na verdade, a questão afirma entrada de comprimento 0 e entrada não vazia para que eu possa diminuir esse :)
Emigna

1
@FrodCube: Sim, na verdade é um recurso bastante novo no 05AB1E. Tenho certeza de que Ohm também o conseguirá.
Emigna

10
[=também funciona e é um rosto sorridente; o sorriso é o único benefício lol.
Urna Mágica do Polvo


5

Ohm , 3 bytes

∞┼,

Experimente online!

Ele não funciona com uma entrada vazia porque Ohm é ruim no manuseio de entrada em comparação com outros idiomas, mas você pode inserir "".

Explicação

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

Isso parece legal ... Você poderia explicar: D
Beta Decay

@BetaDecay done!
FrodCube

1
Para sua informação, a Ohm v2 (espero que em breve esteja disponível) terá um tratamento de entrada muito melhor do que antes!
Nick Clifford

@NickClifford cool! Estou ansioso por isso! Eu gosto do seu idioma
FrodCube 5/05

1
Oooo ... Ohm é como 05AB1E com comandos diferentes ?! Fervorosamente começa a ler páginas GitHub
Magia Octopus Urna

5

sed, 5

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

Rótulos sem nome é um "recurso" não documentado no sed que funciona com a versão 4.2.2, mas pode não funcionar em versões futuras.





4

V, 2 bytes

òÙ

You can't try this online for obvious reasons.

ò    'Recursively
 Ù   'Duplicate the current line downwards

TIO actually runs for 60 seconds then terminates and prints the STDOUT up until the termination point truncated to the first 128KiB.
Magic Octopus Urn

1
In V because the output it inside of an nvim session, and isn't printed to STDOUT until it finishes, TIO kills the session and sees nothing on STDOUT. I didn't know about what you said, but unfortunately it doesn't fix V
nmjcman101

1
Ahhhh... That's unfortunate, I forgot the properties of V, I've only used it once unsuccessfully.
Magic Octopus Urn

3

Ruby, 18 17 12 + 2 = 14 bytes

Run with the -n flag.

loop{$><<$_}

Edit: Thanks for @sethrin for the -n flag!


Use the -n flag and skip the gets.
canhascodez

@sethrin Nice one! I did not know about this flag!
Peter Lenkefi

3

AutoHotkey, 20 Bytes

OP did not specify how the output should happen, said only it has to happen endlessly with a newline after it. AHK was not tailored for cmd interaction. So the output happens repeatedly in a ToolTip at mouse position:

tooltip

loop
tooltip,%1%`n`n

I like AHK's loop feature. loop repeats the next block forever, loop, 10 would repeat it 10 times. Sometimes I miss this feature in other languages like Python.

The escape character in AutoHotkey is ` (so there are no problems with backslashes in Windows paths). For some reason, a trailing newline is ignored so it is needed twice. (trayTip might not have this "bug" but I cannot test it because running with wine)

old answer:

loop
msgbox,%1%

I just realized that OP probably wont like this solution, the output happens with user-interaction and includes no newlines. I'll look for another way.


1
Well, you've got my upvote for a creative solution
Skidsdev

3

LibreLogo, 33 bytes

Code:

x=input " repeat [ label x bk 9 ]

Explanation:

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

Result:

enter image description here


2

Python 2, 25 bytes

s=input()
while 1:print s

Try it online!

Input is expected to be a Python literal (quotes for a string, square bracket or parentheses with comma-separated items for a list/tuple, etc.)

Python 3 would be +1 byte because print is a function, but also could do raw input without the 4-byte penalty for raw_input() in Python 2.




2

Haskell, 14 bytes

cycle.(++"\n")

Try it online!

Append a newline to the input and make list of infinite copies of it.

Alternative version, also 14 bytes:

unlines.repeat

The alternative version is quite elegant :)
Conor O'Brien

2

Braingolf, 14 12 bytes

#
V[R!&@v1+]

Try it online!

-2 bytes thanks to totallyhuman

Explanation

#\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 bytes

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

Basically a recursive function that outputs the string before calling herself again. Its my second post on codegolf so please be nice :p


2

Cubix, 6 bytes

AN/qvo

Test it here

  A
N / q v
  o
  • N/A Push Newline(10) and input onto the stack
  • v redirect into the loop
  • o/q loop that outputs a character and pushes it to the bottom of the stack continuously

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

1

SAS, 32 bytes

%macro t(s);%put&s;%t(&s);%mend;
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.