2
1
The mission is to implement a cat
-like program (copy all STDIN to STDOUT).
Rules:
- You may only use standard libraries
- Indentation must be either two spaces or a single tab (in languages which require indentation)
- Scripts must use shebangs
- The result of
cat anything.txt | ./yourprogram | diff anything.txt -
should be nothing and should not be an infinite loop
Go
example (84 bytes)
package main
import (
"os"
"io"
)
func main() {
io.Copy(os.Stdout,os.Stdin)
}
C++
example (78 bytes)
#include<iostream>
using namespace std;
int main() {
cout << cin.rdbuf();
}
Ruby
example (44 bytes)
#!/usr/bin/env ruby
$stdout << $stdin.read
Shortest code (by bytes) wins.
1Sheesh why all the downvotes? – Conor O'Brien – 2015-10-28T04:58:04.280
Two space indentation isn't valid in Python. – seequ – 2014-06-15T12:34:34.067
55This indentation thing is nonsense – edc65 – 2014-06-15T12:49:01.183
1@edc65 Especially because it often isn't needed. – seequ – 2014-06-15T12:50:34.813
3@ProgramFOX Stoning the Rosetta. – seequ – 2014-06-15T12:53:48.960
2
@TheRare I'm not sure where you heard that, but any indentation is perfectly valid in Python. Different levels don't even need to have the same indentation. https://docs.python.org/3/reference/lexical_analysis.html#indentation
– Plutor – 2014-06-15T13:40:03.617@Plutor Guess I've ran to some weird bugs then. – seequ – 2014-06-15T13:55:13.303
Even if there were a valid winning criterion, this seems a rather boring challenge. – Kyle Kanos – 2014-06-15T14:15:29.787
14The indentation rule doesn't make sense, the shebang one makes even less, because shebangs can be platform-specific, especially in the case of Python. – nyuszika7h – 2014-06-15T14:50:14.273
9until end of June 2914… Woaah… – Qeole – 2014-06-15T18:03:37.263
7Also, person with most implementation? What? – nyuszika7h – 2014-06-15T18:50:36.333
2what exactly prevents me from using
cat
in Bash, or all the 0 character programs in other languages? – None – 2014-06-15T19:40:27.2371typo indeed XD 2014 – Kokizzu – 2014-06-15T22:47:19.887
1@TheRare With regards to Python indentation, it must be consistent within a block. So, each level must be self consistent, but it doesn't have to care about the other levels. If you aren't consistent within a block, then it will complain. – daviewales – 2014-06-18T09:11:22.480
1Why are there so many downvotes? – None – 2014-06-20T20:00:24.157
@professorfish: Because of the rules, I assume. Rule 2 is nonsense, rule 1 only makes sense for certain languages and counting the bytes of the shebang is a very weird form of scoring. So far, pretty much all answers seem to have ignored rule 3. – Dennis – 2014-06-20T20:05:38.697
@Dennis would it be legitimate to just edit it to make it clearer? – None – 2014-06-20T20:11:37.877
1@professorfish: The rules aren't unclear, they're just very, very strange. I don't think we should actually change the rules of a contest. – Dennis – 2014-06-20T20:14:54.290
to bee correct with the size in my opinion also the size of the used interpreter must be added otherwise it is useless to compare the code snippets. also it should be cleared what happens if the code must be compiled to us (e.g java, c) what counts the size of the source code or the size of the binary ? – konqui – 2014-06-25T20:59:36.963
4what about this python solution?
for s in' /\___/\|( o o )|/ * \|\__\_/__/meow| / \| / ___ \| \/___\/'.split('|'):print s
– Willem – 2014-07-04T15:50:09.6771@professorfish, why are there so many upvotes? – Peter Taylor – 2014-08-05T16:43:43.893
this isn't even cat-like as much as it is echo-like. – Jordon Biondo – 2014-08-05T18:46:24.867
Using
cat
with only one argument to just print out the file is easily the most frequent use case, but people apparently forget thatcat
stands for "concatenate" - most solutions here don't do that. – orion – 2014-08-05T19:01:27.173@orion: that's because OP ignored it too: "copy all stdin to stdout". Handling arguments is harder. – Yann Vernier – 2014-09-11T11:12:02.383