84
\$\begingroup\$

One of the most common standard tasks (especially when showcasing esoteric programming languages) is to implement a "cat program": read all of STDIN and print it to STDOUT. While this is named after the Unix shell utility cat it is of course much less powerful than the real thing, which is normally used to print (and concatenate) several files read from disc.

Task

You should write a full program which reads the contents of the standard input stream and writes them verbatim to the standard output stream. If and only if your language does not support standard input and/or output streams (as understood in most languages), you may instead take these terms to mean their closest equivalent in your language (e.g. JavaScript's prompt and alert). These are the only admissible forms of I/O, as any other interface would largely change the nature of the task and make answers much less comparable.

The output should contain exactly the input and nothing else. The only exception to this rule is constant output of your language's interpreter that cannot be suppressed, such as a greeting, ANSI color codes or indentation. This also applies to trailing newlines. If the input does not contain a trailing newline, the output shouldn't include one either! (The only exception being if your language absolutely always prints a trailing newline after execution.)

Output to the standard error stream is ignored, so long as the standard output stream contains the expected output. In particular, this means your program can terminate with an error upon hitting the end of the stream (EOF), provided that doesn't pollute the standard output stream. If you do this, I encourage you to add an error-free version to your answer as well (for reference).

As this is intended as a challenge within each language and not between languages, there are a few language specific rules:

  • If it is at all possible in your language to distinguish null bytes in the standard input stream from the EOF, your program must support null bytes like any other bytes (that is, they have to be written to the standard output stream as well).
  • If it is at all possible in your language to support an arbitrary infinite input stream (i.e. if you can start printing bytes to the output before you hit EOF in the input), your program has to work correctly in this case. As an example yes | tr -d \\n | ./my_cat should print an infinite stream of ys. It is up to you how often you print and flush the standard output stream, but it must be guaranteed to happen after a finite amount of time, regardless of the stream (this means, in particular, that you cannot wait for a specific character like a linefeed before printing).

Please add a note to your answer about the exact behaviour regarding null-bytes, infinite streams, and extraneous output.

Additional rules

  • This is not about finding the language with the shortest solution for this (there are some where the empty program does the trick) - this is about finding the shortest solution in every language. Therefore, no answer will be marked as accepted.

  • Submissions in most languages will be scored in bytes in an appropriate preexisting encoding, usually (but not necessarily) UTF-8.

    Some languages, like Folders, are a bit tricky to score. If in doubt, please ask on Meta.

  • Feel free to use a language (or language version) even if it's newer than this challenge. Languages specifically written to submit a 0-byte answer to this challenge are fair game but not particularly interesting.

    Note that there must be an interpreter so the submission can be tested. It is allowed (and even encouraged) to write this interpreter yourself for a previously unimplemented language.

    Also note that languages do have to fulfil our usual criteria for programming languages.

  • If your language of choice is a trivial variant of another (potentially more popular) language which already has an answer (think BASIC or SQL dialects, Unix shells or trivial Brainfuck derivatives like Headsecks or Unary), consider adding a note to the existing answer that the same or a very similar solution is also the shortest in the other language.

  • Unless they have been overruled earlier, all standard rules apply, including the http://meta.codegolf.stackexchange.com/q/1061.

As a side note, please don't downvote boring (but valid) answers in languages where there is not much to golf; these are still useful to this question as it tries to compile a catalogue as complete as possible. However, do primarily upvote answers in languages where the author actually had to put effort into golfing the code.

Catalogue

The Stack Snippet at the bottom of this post generates the catalogue from the answers a) as a list of shortest solution per language and b) as an overall leaderboard.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

## Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

## Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

## Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the snippet:

## [><>](http://esolangs.org/wiki/Fish), 121 bytes

<style>body { text-align: left !important} #answer-list { padding: 10px; width: 290px; float: left; } #language-list { padding: 10px; width: 290px; float: left; } table thead { font-weight: bold; } table td { padding: 5px; }</style><script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="language-list"> <h2>Shortest Solution by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr> </thead> <tbody id="languages"> </tbody> </table> </div> <div id="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr> </thead> <tbody id="answers"> </tbody> </table> </div> <table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr> </tbody> </table><script>var QUESTION_ID = 62230; var ANSWER_FILTER = "!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe"; var COMMENT_FILTER = "!)Q2B_A2kjfAiU78X(md6BoYk"; var OVERRIDE_USER = 8478; var answers = [], answers_hash, answer_ids, answer_page = 1, more_answers = true, comment_page; function answersUrl(index) { return "//api.stackexchange.com/2.2/questions/" + QUESTION_ID + "/answers?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + ANSWER_FILTER; } function commentUrl(index, answers) { return "//api.stackexchange.com/2.2/answers/" + answers.join(';') + "/comments?page=" + index + "&pagesize=100&order=desc&sort=creation&site=codegolf&filter=" + COMMENT_FILTER; } function getAnswers() { jQuery.ajax({ url: answersUrl(answer_page++), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { answers.push.apply(answers, data.items); answers_hash = []; answer_ids = []; data.items.forEach(function(a) { a.comments = []; var id = +a.share_link.match(/\d+/); answer_ids.push(id); answers_hash[id] = a; }); if (!data.has_more) more_answers = false; comment_page = 1; getComments(); } }); } function getComments() { jQuery.ajax({ url: commentUrl(comment_page++, answer_ids), method: "get", dataType: "jsonp", crossDomain: true, success: function (data) { data.items.forEach(function(c) { if (c.owner.user_id === OVERRIDE_USER) answers_hash[c.post_id].comments.push(c); }); if (data.has_more) getComments(); else if (more_answers) getAnswers(); else process(); } }); } getAnswers(); var SCORE_REG = /<h\d>\s*([^\n,<]*(?:<(?:[^\n>]*>[^\n<]*<\/[^\n>]*>)[^\n,<]*)*),.*?(\d+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/; var OVERRIDE_REG = /^Override\s*header:\s*/i; function getAuthorName(a) { return a.owner.display_name; } function process() { var valid = []; answers.forEach(function(a) { var body = a.body; a.comments.forEach(function(c) { if(OVERRIDE_REG.test(c.body)) body = '<h1>' + c.body.replace(OVERRIDE_REG, '') + '</h1>'; }); var match = body.match(SCORE_REG); if (match) valid.push({ user: getAuthorName(a), size: +match[2], language: match[1], link: a.share_link, }); else console.log(body); }); valid.sort(function (a, b) { var aB = a.size, bB = b.size; return aB - bB }); var languages = {}; var place = 1; var lastSize = null; var lastPlace = 1; valid.forEach(function (a) { if (a.size != lastSize) lastPlace = place; lastSize = a.size; ++place; var answer = jQuery("#answer-template").html(); answer = answer.replace("{{PLACE}}", lastPlace + ".") .replace("{{NAME}}", a.user) .replace("{{LANGUAGE}}", a.language) .replace("{{SIZE}}", a.size) .replace("{{LINK}}", a.link); answer = jQuery(answer); jQuery("#answers").append(answer); var lang = a.language; lang = jQuery('<a>'+lang+'</a>').text(); languages[lang] = languages[lang] || {lang: a.language, lang_raw: lang.toLowerCase(42), user: a.user, size: a.size, link: a.link}; }); var langs = []; for (var lang in languages) if (languages.hasOwnProperty(lang)) langs.push(languages[lang]); langs.sort(function (a, b) { if (a.lang_raw > b.lang_raw) return 1; if (a.lang_raw < b.lang_raw) return -1; return 0; }); for (var i = 0; i < langs.length; ++i) { var language = jQuery("#language-template").html(); var lang = langs[i]; language = language.replace("{{LANGUAGE}}", lang.lang) .replace("{{NAME}}", lang.user) .replace("{{SIZE}}", lang.size) .replace("{{LINK}}", lang.link); language = jQuery(language); jQuery("#languages").append(language); } }</script>

\$\endgroup\$
  • 52
    \$\begingroup\$ Bash, 3 bytes: cat \$\endgroup\$ – TheDoctor Oct 31 '15 at 19:02
  • 3
    \$\begingroup\$ @TheDoctor I guess this would fall into the "don't use a builtin which does exactly what is needed" rule. \$\endgroup\$ – Paŭlo Ebermann Oct 31 '15 at 19:46
  • 5
    \$\begingroup\$ @PaŭloEbermann There is no such rule, and the corresponding standard loophole is no longer accepted. (In fact, there is already a sh answer using cat which also contains a shorter solution using dd.) \$\endgroup\$ – Martin Ender Oct 31 '15 at 20:25
  • 1
    \$\begingroup\$ If only it used standard methods of input and output: ///, 0 bytes. \$\endgroup\$ – Comrade SparklePony Mar 31 '17 at 19:33
  • 1
    \$\begingroup\$ @SparklePony Except, you'd have to escape slashes and backslashes. \$\endgroup\$ – Martin Ender Mar 31 '17 at 20:35

263 Answers 263

3
\$\begingroup\$

05AB1E, 4 2 bytes (not working)

Try it online!

Golfed from 4 to 2 bytes thanks to @daHugLenny!

Explanation

|       Takes input as array separated by breaks
 »      Join input array by newline
        Implicitly print
\$\endgroup\$
3
\$\begingroup\$

Retina, 3 1 byte



That's a single linefeed.

Try it online!

The empty Retina program would count the number of matches of the empty regex in the input, so it can't compete with rs and sed here. There are several ways to implement a cat program, the shortest being a Replace stage that doesn't actually replace anything.

Retina cannot handle infinite streams (as it waits for EOF before starting any processing).

\$\endgroup\$
3
\$\begingroup\$

Pyramid Scheme, 199 116 bytes

Saved 83 bytes thanks to Khuldraeseth na'Barya! Clever idea to use the "nameless" variable, an empty triangle.

   ^
  /d\
 / o \
^-----^
-    ^-^
    ^-/ \
   ^-/out\
  / \-----^
 /set\    -
^-----^
-    /l\
    /ine\
    -----

Try it online!


Old version (functionally equivalent)

      ^
     / \
    /do \
   ^-----^
  /A\   / \
  ---  /   \
      /     \
     /       \
    ^---------^
   / \       / \
  /set\     /out\
 ^-----^   ^-----
/A\   /l\ /A\
---  /ine\---
     -----

Try it online!

Explanation

This might look like this in a scheme/lisp-like language:

(do (pair (set A read-line) (print A)) A)

Or, in a C-like language:

do {
    A = gets();
    puts(A);
} while(A);
\$\endgroup\$
  • \$\begingroup\$ 125 bytes \$\endgroup\$ – Khuldraeseth na'Barya Jul 25 at 18:24
  • \$\begingroup\$ 116 \$\endgroup\$ – Khuldraeseth na'Barya Jul 25 at 18:26
  • \$\begingroup\$ @Khuldraesethna'Barya Fascinating structure... Thanks! \$\endgroup\$ – Conor O'Brien Jul 26 at 0:35
  • \$\begingroup\$ Can you add some documentation for this language? I would like to try it out \$\endgroup\$ – Jo King Jul 26 at 6:23
  • 1
    \$\begingroup\$ @JoKing Sure thing! I'm going off to bed rn, I'll add it to my todo list and I'll ping you once I'm done. \$\endgroup\$ – Conor O'Brien Jul 26 at 6:24
3
\$\begingroup\$

Keg, 0 8 bytes

{?(,)\
,

Supports multi-line input now. Halts in an error, which is allowed by default

Try it Online!

\$\endgroup\$
  • \$\begingroup\$ fixed (padding) \$\endgroup\$ – EdgyNerd Aug 24 at 14:26
2
\$\begingroup\$

C--, 171 bytes

target byteorder little;import getchar,putchar;export main;foreign"C"main(){t:bits32 v;v=foreign "C" getchar();if(v!=-1){foreign"C"putchar(v);goto t;}foreign"C"return(0);}

Considering C-- is essentially a "portable assembler", I shouldn't be surprised that this was huge.

\$\endgroup\$
2
\$\begingroup\$

Befunge-98, 4 bytes

#@~,

The program counter starts moving to the right in the top-left corner of the program. # causes it to jump over @, landing on ~. This reads a character, or reflects the PC on EOF. If EOF is reached, this will cause it to run into @, which ends the program. Otherwise, it continues to ,, which prints the character that was read, and loops back to # thanks to Lahey-space.

\$\endgroup\$
  • \$\begingroup\$ Is the reflect-on-EOF behavior in the spec? I didn't know about it before. (Then again, I coded mostly in Befunge-93.) \$\endgroup\$ – El'endia Starman Oct 30 '15 at 16:52
  • \$\begingroup\$ Yeah: In the case of an end-of-file or other file error condition, the & and ~ both act like r. \$\endgroup\$ – Lynn Oct 30 '15 at 16:53
  • \$\begingroup\$ Huh, interesting. The lack of this behavior in Befunge-93 added five bytes! Doubled the program length! \$\endgroup\$ – El'endia Starman Oct 30 '15 at 16:54
2
\$\begingroup\$

Python 3, 50 bytes

import sys
while 1:print(sys.stdin.read(1),end='')

See comment in my python 2 answer about newlines.

OR 29 bytes

while 1:print(input())

Waits explicitly for newlines before printing. (This means that it won't print anything after a newline before the next)

\$\endgroup\$
  • 1
    \$\begingroup\$ Adds trailing newline. \$\endgroup\$ – feersum Oct 30 '15 at 16:42
  • \$\begingroup\$ Can't you do print(end=sys.stdin.read(1))? \$\endgroup\$ – Erik the Outgolfer Sep 27 '16 at 17:52
  • \$\begingroup\$ I've found a shorter one using os.read/write and fd numbers, it is 42 bytes. tio.run/##K6gsycjPM/7/… \$\endgroup\$ – Rick Rongen Dec 28 '18 at 18:23
  • \$\begingroup\$ Feel free to post it yourself and take the credit for it^^ \$\endgroup\$ – Blue Dec 28 '18 at 18:32
2
\$\begingroup\$

Pyth, 28 bytes

V$__import__('sys').stdin$pN

Not as short as @Mauris's Pyth answer, but it handles infinite input.

\$\endgroup\$
2
\$\begingroup\$

Erlang, 108 Bytes

Uses escript to run. Making the code a one-liner seems to cause an EOF error from the interpreter.

#!/usr/bin/env escript
main(_)->f(a).
f(eof)->ok;f([C])->f(io:format("~c",[C]));f(_)->f(io:get_chars('',1)).
\$\endgroup\$
2
\$\begingroup\$

lua for windows, 38 bytes

Needs lua for windows

while true do io.write(io.read()) end

how it works

It prints the input from the terminal

\$\endgroup\$
2
\$\begingroup\$

Julia, 45 bytes

while !eof(STDIN) print(read(STDIN,Char))end

Ungolfed + explanation:

while !eof(STDIN)             # While EOF has not been encountered from STDIN
    r = read(STDIN, Char)     # Read a single character from STDIN
    print(r)                  # Print it to STDOUT with no trailing anything
end

This supports an infinite input stream and null bytes and has no extraneous output.

Thanks to Dennis and Martin Büttner for their help on this!

\$\endgroup\$
2
\$\begingroup\$

D, 94 bytes

import std.stdio,std.algorithm;void main(){stdin.byChunk(1).copy(stdout.lockingTextWriter());}

I'm no D expert at all, so there might be a better way to do this.

\$\endgroup\$
  • \$\begingroup\$ I don't think you need the parens after stdout.lockingTextWriter. \$\endgroup\$ – Zacharý Nov 26 '16 at 17:53
2
\$\begingroup\$

QBasic, 15 bytes

?INPUT$(1);
RUN

QBasic doesn't have any concept of input or output streams (except maybe where files are concerned). The above program instead takes any character you enter and echoes it to the screen, which I think fits the spirit of the challenge. RUN restarts the program from scratch, thus continuing to read and echo forever (there's no EOF for keyboard input, and I don't think it's even possible to enter a null byte).

Here's a 34-byte version that quits when you press escape. The should be replaced with a literal Esc character, ASCII 27. This can be entered in the QBasic editor by holding the Alt key while typing the character code; it shows up as a .

9?x$;
x$=INPUT$(1)
IF"…"<>x$THEN 9
\$\endgroup\$
2
\$\begingroup\$

PHP, 20 bytes

<? fpassthru(STDIN);

Kind of surprised there isn't one for PHP yet...

\$\endgroup\$
  • \$\begingroup\$ I bet you can get rid of the space. \$\endgroup\$ – Lynn Oct 31 '15 at 12:09
  • 1
    \$\begingroup\$ Run it with -r and you can get rid of the opening tag altogether. echo -e "Hello\nWorld" | php -r 'fpassthru(STDIN);' 17 bytes \$\endgroup\$ – aross Mar 18 '16 at 10:51
2
\$\begingroup\$

Emmental, 20 bytes

;#44#46#35#57#63#9!<tab>

The program ends with a tab character. This beats the example on the wiki page by redefining and invoking the tab character (ASCII 9) instead of the asterisk (ASCII 42). The spec doesn't really mention what , does at EOF, but the reference implementation uses getChar, which raises an IOError when the file ends. (The , is "quoted" as #44 in the above program.)

\$\endgroup\$
2
\$\begingroup\$

ngn APL, 7 bytes

{∇⍞←⍞}1

ngn APL only supports linewise input and has no actual looping constructs, so this recursive function is as good as it gets. It prints null bytes, but only if they do not occur on the last line.

How it works

{    }   Define a function.
  ⍞←⍞    Read and print a line.
 ∇       Call the function again.
      1  Call the function with dummy input.

exits automatically on EOF.

\$\endgroup\$
  • \$\begingroup\$ There is the looping construct . It's just not so procedural. \$\endgroup\$ – jimmy23013 Nov 1 '15 at 23:51
  • \$\begingroup\$ I haven't been able to get working for this task. Anyway, -⍣≡1 leaks memory, so the result would probably be the same. \$\endgroup\$ – Dennis Nov 2 '15 at 4:44
2
\$\begingroup\$

Java, 120 bytes

The other Java solution is shorter than mine but, it uses Apache libraries to get the job done. I think it's worthwhile to put forward a java solution that relies solely on the java standard libraries.

This code works for infinite input and for input that contains null bytes.

class C{public static void main(String[]a)throws Exception{byte[]b={0};while(System.in.read(b)>=0)System.out.write(b);}}

Ungolfed

import java.io.IOException;

public class Cat {
  public static void main(String[] args) throws IOException {
    byte[] input=new byte[1];
    while(System.in.read(input)>=0){
      System.out.write(input);
    }
  }
}
\$\endgroup\$
  • \$\begingroup\$ You don't need public in the class declaration. You can just throw Exception instead of IOException and not have to import anything in the Ungolfed version. \$\endgroup\$ – Addison Crump Nov 2 '15 at 11:35
  • \$\begingroup\$ Using the stderr rule, you could abuse an enum: enum C{C;System z;{try{byte[]b={0};while(z.in.read(b)>=0)z.out.write(b);}catch(Exception e){}}} \$\endgroup\$ – ninjalj Nov 2 '15 at 20:16
  • \$\begingroup\$ @ninjalj I can't figure out how to get the compiled class to execute the code block without loading the class from some other program. Is there anyway to execute it from the command line? \$\endgroup\$ – ankh-morpork Nov 2 '15 at 21:09
  • \$\begingroup\$ @dohaqatar7: java -classpath <wherever> C should work. \$\endgroup\$ – ninjalj Nov 2 '15 at 21:16
2
\$\begingroup\$

Groovy, 39 bytes

System.in.eachByte{System.out.write it}

Since I wrote a proof-of-concept to confirm that Groovy can handle infinite stream, might as well post it as an answer.

Usage:

groovy <script_name>
\$\endgroup\$
2
\$\begingroup\$

Emotinomicon, 29 bytes

⏪⏫🆙⏬😅➕⁉️⏩

Most of the program is just checking for EOF.

\$\endgroup\$
2
\$\begingroup\$

LabVIEW, 3 LabVIEW Primitives

Pretty obvious what it does I would say.

\$\endgroup\$
2
\$\begingroup\$

PlatyPar, 0 bytes

 

Try it online

At the beginning of the program, input is implicitly pushed to the stack. At the end of the program, the stack is implicitly printed.

\$\endgroup\$
2
\$\begingroup\$

Emotinomicon, 5 chars / 15 bytes

⏫⏪⏬⏫⏩

Press "cancel" to exit the loop. Try it here!

⏫   ⏪   ⏬   ⏫   ⏩   explanation
⏫                   take one character as input, push it to the stack
    ⏪               open loop
        ⏬           pops and outputs top of stack as character
            ⏫       take one character as input, push it to the stack
                ⏩   close loop
\$\endgroup\$
  • \$\begingroup\$ Would ⏪⏫⏬⏩ work? \$\endgroup\$ – Pavel Nov 18 '16 at 20:54
  • \$\begingroup\$ @Pavel no it would not, since the stack would be falsey being empty and thus the loop would end. \$\endgroup\$ – Conor O'Brien Nov 18 '16 at 20:56
2
\$\begingroup\$

NTFJ, 4 bytes

(*~^

An online interpreter can be found here.

NTFJ is an esoteric programming language, made by user @ConorO'Brien, intended to be a Turing tarpit. It is stack-based, and pushes bits to the stack, which can be later coalesced to an 8-bit number. The bytes of the input are pushed to the stack before the program is run, with the first byte on top. This particular program is fairly simple:

(      If top of stack is not 0:
 *      Pop byte, output as a character.
  ~     Push 0.
   ^    Pop bit/byte and jump to the instruction at the corresponding index.
        This moves us back to the beginning of the program, which is thus looped until the stack is empty.
\$\endgroup\$
  • \$\begingroup\$ Try chopping off the last paren, it should still work. \$\endgroup\$ – Conor O'Brien Mar 2 '16 at 19:42
  • \$\begingroup\$ @CᴏɴᴏʀO'Bʀɪᴇɴ Thanks, it does indeed! \$\endgroup\$ – ETHproductions Mar 15 '16 at 20:04
  • \$\begingroup\$ +1 for the emote: *~^ \$\endgroup\$ – user48538 Mar 16 '16 at 8:08
2
\$\begingroup\$

Gogh, 0 bytes

 

This is functional in a Gogh program with input.


Usage

$ ./gogh <standard-flags> <code-or-path> <input>

In this case:

$ ./gogh o "" <input>
\$\endgroup\$
2
\$\begingroup\$

0815, 10 bytes

(interpreter, don't let the pirate icon scare you)

}: :!~$^: 

Note that there is a trailing space at the end. This one survives trimmers:

}:0:!~$^:0

They work the same.

Explanation

0815 has three memory registers: X, Y and Z. X is write-able, Z is read-able. Y cannot be directly accessed, but only with rotations. At start, X is 0x0, Y is 0x0 and Z is 0x0. 0815 only supports hexadecimal numbers. Labels point to a specific part in the code: the character after their definition. Here are the symbols used here:

  • } : :: } defines a label, : starts its parameter (the label), is the label, and : closes the parameter, thus creating the label at this point (char 5).
  • !: ! gets a byte from STDIN and stores it in X.
  • ~ $: ~ is needed to rotate left, so that X is Y, Y is Z and Z is X. Then, $ is used to print the character in Z to the screen.
  • ^ : : ^ jumps to the label specified if Z is not 0x0. Note that closing is not required on this step, as this is the end of the program. This allows an un-copiable null byte to be printed.
\$\endgroup\$
2
\$\begingroup\$

Seed, 7 Bytes

2 20093

Seed is a language which generates Befunge-93 with a length and a random seed. 2 is the length and 20093 is the random seed.

\$\endgroup\$
  • \$\begingroup\$ And the byte count is...? \$\endgroup\$ – user48538 Jul 16 '16 at 6:46
2
\$\begingroup\$

Gaot++, 113 bytes

bleeeet bleeeeeet bleeeeeeeeeeeet bleeeet b bleeeeeeeeeeeeet bleeeet b bleeeeeeet bleeeet bleeeeeeeeeet bleeeeeet

In Compressed Gaot++ it's 25 bytes:

4e6e12e4eb13e4eb7e4e10e6e

Cannot terminate on the offline interpreter, EOF is not recognized by the language :(

Online interpreter for both normal and compressed versions.

\$\endgroup\$
  • \$\begingroup\$ Shall I create a verbal representation of this? \$\endgroup\$ – tuskiomi Nov 18 '16 at 21:17
  • 1
    \$\begingroup\$ @tuskiomi What do you mean? Those are surely screaming gaots! \$\endgroup\$ – Erik the Outgolfer Nov 18 '16 at 21:47
2
\$\begingroup\$

D, 65 71 68 bytes

import std.c.stdio;void main(){for(int c;c=~getchar,c;)putchar(~c);}

The original version couldn't handle infinitely long lines, but we should still do better than the existing D solution's 94 bytes, so here's the D version of Dennis' C solution.

std.c.stdio is deprecated in favor of core.stdc.stdio, as is this use of the comma operator, but both are still legal as of the current version.

Edit 2: Saved 3 bytes thanks to Zachary's suggestions

\$\endgroup\$
  • \$\begingroup\$ Um, I don't think you need the parens after getchar. \$\endgroup\$ – Zacharý Nov 26 '16 at 17:08
  • \$\begingroup\$ You can save a byte by changing the int c;while(...) to for(int c;...;). \$\endgroup\$ – Zacharý Nov 26 '16 at 17:17
  • \$\begingroup\$ @ZacharyT Good call on both counts. Down to 68 bytes. \$\endgroup\$ – Ray Nov 28 '16 at 21:43
2
\$\begingroup\$

Casio FX-7000G, 3 bytes

Due to the low amount of storage, the calculator's programming mode used a tokenized language to save space. This makes it somewhat competitive for code-golf...

Program:

?→X

Explanation:

?       # Take input from user
 →X     # Store in variable X
        # Implicit: Print last value

Note that although this is 5 UTF-8 bytes, the calculator uses its own encoding to store this in 3.

\$\endgroup\$
2
\$\begingroup\$

NewbieFuck, 4 bytes

[.,]

I guess this is non-competing I'm not aware of any working interpreter, but I found the spec online (esolangs.org).

If I understand correctly, this is the same as Brainfuck, but [ ... ] is actually do-while loop (always executes the first time).

So, although the Brainfuck answer needs to take input before entering the loop, ,[.,], this language can omit the first input and use [.,]

Note: as end of input is signified by 0 in brainfuck, this cannot handle null bytes. It will also prepend a null byte to the output.

\$\endgroup\$
  • \$\begingroup\$ Why not do [,.] so that it doesn't prepend a null byte? \$\endgroup\$ – caird coinheringaahing Sep 3 '17 at 14:49
  • 1
    \$\begingroup\$ Then it would append the Null EOF byte at the end, which just shifts the problem to the other end. \$\endgroup\$ – sundar - Reinstate Monica Jul 8 '18 at 17:44

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