Test

I was bored for a few minutes yesterday and here's some of the results.

In Fortran:
<font class="small">Code:</font><hr /><pre>
INTEGER x, y
DO 100 y = 1, 9
DO 200 x = 1, 4999
PRINT*, 'you guys are cheaters'
200 CONTINUE
PRINT*, 'the end'
PRINT*, 'Fortran rocks'
100 CONTINUE
STOP
END
</pre><hr />

In C (old school):
<font class="small">Code:</font><hr /><pre>
#include &lt;stdio.h&gt;

main()
{
int x, y;
for(y=1; y&lt;10; y++) {
for(x=1; x&lt;5000; x++) {
puts("you guys are cheaters");
}
puts("the end\nC rocks");
}
}
</pre><hr />

In C++ (newer school):
<font class="small">Code:</font><hr /><pre>
#include &lt;iostream&gt;

main()
{
for(int y=1; y&lt;10; y++) {
for(int x=1; x&lt;5000; x++) {
std::cout &lt;&lt; "you guys are cheaters\n";
}
std::cout &lt;&lt; "the end\nC++ rocks\n";
}
}
</pre><hr />

In a modern interpreted language (Python):
<font class="small">Code:</font><hr /><pre>
for y in range(1, 10):
for x in range(1, 5000):
print 'you guys are cheaters'
print 'the end\nPython rocks'
</pre><hr />
or if you enjoy the I can do that in one line game:
<font class="small">Code:</font><hr /><pre>
print ('you guys are cheaters\n'*4999 + 'the end\nPython really rocks\n')*9,
</pre><hr />

Cary
 
kudos

Here's the way I'd likely do that one on any given day:
<font class="small">Code:</font><hr /><pre>#!/bin/bash

y=1
while [ $y -lt 10 ]; do
y=$(($y + 1))
x=1
while [ $x -lt 5000 ]; do
echo you guys are cheaters
x=$(($x + 1))
done
echo the end
echo bash rocks
done
</pre><hr />
Well, not exactly. For something like that I'd likely throw it away as one line at the prompt.
 
Naw, we'z jus' sheep followin' y'r lead.
<font class="small">Code:</font><hr /><pre>
#!/bin/zsh
for ((y=1; $y&lt;10; y++)) do
for ((x=1; $x&lt;5000; x++)) do
echo "you guys are cheaters"
done
echo "the end\nzsh rocks"
done
</pre><hr />
 
Hey Cary,

That zsh looks pretty cool. I see I'd installed it, but have never gotten around to playing with it. I'll have to give it some face time. I like bash cuz of its baseline commonality with the everywhere-sh-iness but with nice interactive enhancements.

The python one-liner gets my vote for the particular task, though.
 

New threads New posts

Back
Top Bottom