Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by Corion (Patriarch) on Oct 03, 2003 at 13:52 UTC
|
perl -e "print 'I will not throw paper airplanes in class.'x500"
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
| [reply] [d/l] [select] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by broquaint (Abbot) on Oct 03, 2003 at 13:54 UTC
|
print "I will not throw paper airplanes in class." x 500;
print map 'I will not throw paper airplanes in class', 1 .. 500;
$_="I will not throw paper airplanes in class\n";
print while $i++ < 500;
sub f { print and f($_[0] + 1) if $_[0] < 500 } f();
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by zby (Vicar) on Oct 03, 2003 at 13:56 UTC
|
With really minimal changes the original one would do:
#include <stdio.h>
#int main(void)
{
# int count;
for($count=1;$count<=500;$count++){
printf("I will not throw paper airplanes in class.");
}
return 0;
}
| [reply] [d/l] |
|
#!/usr/bin/perl
use strict;
use warnings;
use Inline 'C';
no_throw();
__END__
__C__
int no_throw() {
int count;
for(count=1;count<=500;count++){
printf("I will not throw paper airplanes in class.\n");
}
return 0;
}
Update: Oh, whilst putting this together I had problems (Autoload errors) using int main(void) {...}, please /msg me if you know why.
Update 2: broquaint++ for answering my question above. Inline::C's main() messes with Perl's own main(). I assumed that there was some trickery in the background to prevent that sort of thing.
If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.
| [reply] [d/l] [select] |
|
Oops, missed this one....
#include <stdio.h>
#int main(void)
{
# int count;
for($count=1;$count<=500;$count++){
printf("I will not throw paper airplanes in class.");
}
# Can't return outside a subroutine
# return 0;
}
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by dragonchild (Archbishop) on Oct 03, 2003 at 13:47 UTC
|
{
print "I will not throw paper airplanes in class.\n";
die "Now, where did I put that paper airplane ...\n" if ++$i == 50
+0;
redo
}
------ We are the carpenters and bricklayers of the Information Age. The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6 Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by BazB (Priest) on Oct 03, 2003 at 13:42 UTC
|
perl -le 'for(0..499){print "I will not throw paper airplanes in class
+."}'
If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
That way everyone learns.
| [reply] [d/l] |
|
| [reply] [d/l] |
|
perl -le 'for(0..499){print "I will not throw paper airplanes in class
+."}'
-5:
perl -le'print"I will not throw paper airplanes in class."for 0..499'
Liz | [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by ChrisS (Monk) on Oct 03, 2003 at 15:31 UTC
|
#05: REM This is awful! You have been warned.
_10: $i = 1;
_20: if ($i == 500) { goto _60; }
_30: print "I will not throw paper airplanes in class.";
_40: $i = $i + 1;
_50: goto _20;
_60: exit;
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by tilly (Archbishop) on Oct 03, 2003 at 17:34 UTC
|
My guess is that the shortest way from the *nix command line is not Perl though.
yes 'I will not throw paper airplanes in class.'|head -500
The quotes can be dropped if you have no files in the current directory named I, will, not, ...
Idea stolen from here.
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by jmcnamara (Monsignor) on Oct 03, 2003 at 15:06 UTC
|
perl -le '($=-=10)*=10;print"I will !throw paper airplanes in class."w
+hile$=--'
--
John.
| [reply] [d/l] |
(Obfu) Airplanes in class
by dragonchild (Archbishop) on Oct 03, 2003 at 14:59 UTC
|
#!/usr/bin/perl -l
@_=((105)x2,(110)x1,(104)x1,
(97)x4);s/(..)/chr($1+$_[$i])
/eg,$i++for@$=qw(I 14000303 000106 1200100715
1500150417 000817151100130418
0813 0211001818 );print"@$."
Update: I forgot to print it out 500 times. *blush*
#!/usr/bin/perl -l
@_=((105)x2,(110)x1,(104)x1,
(97)x4);s/(..)/chr($1+$_[$i])/eg,$i
++for@$=qw(I 14000303 000106 1200100715 1500150417
000817151100130418 0813 0211001818
);print"@$.$/"x(($=-=10)*10)
------ We are the carpenters and bricklayers of the Information Age. The idea is a little like C++ templates, except not quite so brain-meltingly complicated. -- TheDamian, Exegesis 6 Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
| [reply] [d/l] [select] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by mirod (Canon) on Oct 03, 2003 at 15:47 UTC
|
Just for the sheer pleasure of getting the Deep recursion on subroutine "main::pr" at -e line 1. message:
perl -lwe 'pr(500); sub pr { if( my $times= shift) { print "I will not throw paper airplanes in class."; pr( -- times) }}'
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by katgirl (Hermit) on Oct 03, 2003 at 14:29 UTC
|
for(1..500){
push(@lines, "I will not throw paper aeroplanes in class.");
}
print join("\n",@lines);
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by BrowserUk (Patriarch) on Oct 03, 2003 at 16:04 UTC
|
Save in a file called 'I will not throw paper airplanes in class.pl' and run. (Will need adaption under *nix!.
#! perl -l
($ENV{XX}+=1e-3)<$]&&print$0=~/\\([^\\]+?).pl$/;exec+qq[perl "$0"]
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by Aristotle (Chancellor) on Oct 03, 2003 at 15:48 UTC
|
($_ = sub {
print "I will not throw paper airplanes in class.\n";
$_->( shift() - 1 or return );
})->(500);
Update: s/5/500/;
Makeshifts last the longest.
| [reply] [d/l] |
|
| [reply] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by Yendor (Pilgrim) on Oct 03, 2003 at 14:42 UTC
|
perl -le 'for(1..5){for(1..2){for(1..5){for(1..2){for(1..5){@a=("I","w
+ill","not","throw","paper","airplanes","in","class");$b="";foreach$a(
+@a){
$b.=$a." ";}chop($b);$b.=".";print("$b");}}}}}'
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by mirod (Canon) on Oct 03, 2003 at 16:42 UTC
|
Oh, and I nearly forgot the ob. version using an XML-based language, interpreted of course using XML::Twig:
#!/usr/bin/perl -w
use strict;
use XML::Twig;
eval script2perl( XML::Twig->new->parse( \*DATA));
sub script2perl
{ my $t= shift;
foreach my $for ($t->findnodes( '//for'))
{ if( my $range= $for->att( 'range'))
{ $for->prefix( "for ($range) {\n")
->suffix( "\n}\n")
->erase;
}
}
foreach my $print ($t->findnodes( '//print'))
{ $print->prefix( q{ print "})
->suffix( q{";})
->erase;
}
return $t->root->text
}
__DATA__
<script>
<for range="1..500">
<print>I will not throw paper airplanes in class.\n</print>
</for>
</script>
| [reply] [d/l] |
|
Un-obfuscated version ;-)
#!/usr/bin/perl -w
use strict;
use XML::Twig;
sub script2perl {
my ($t) = @_;
for ($t->findnodes('//for')) {
my $range = $_->att('range') or next;
$_->prefix("for ($range) {\n");
$_->suffix("\n}\n");
$_->erase;
}
for ($t->findnodes('//print')) {
$_->prefix(' print "');
$_->suffix('";');
$_->erase;
}
return $t->root->text;
}
eval script2perl XML::Twig->new->parse(\*DATA);
I found your code hard to read. Not only the way you put curlies, but also that whitespace in your parens and around your =s is unbalanced. Is this your usual style or was it really a try to obfuscate?
Please note: I'm not attacking, just very curious.
Update: reading XML::Twig's documentation and source already gave me the answer: this is indeed your usual style. Wow.
Juerd
# { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by krisahoch (Deacon) on Oct 03, 2003 at 21:16 UTC
|
Awww, what the hey.....TIMTOWTDI right?
use strict;
use Inline Java => << 'END_OF_JAVA';
public class FoxTrot{
private int start = 1;
private int times = 0;
/** Print the thing */
public void DoPunishment(){
for(start = 0; start != this.getNumberOfTimes(); start++){
System.out.println("I will not throw paper airplanes in class.")
+;
}
};
/** Return the number of times the thing will be printed */
public int getNumberOfTimes(){ return times; }
/** Set the number of times to print the thing */
public int setNumberOfTimes(int number)
{
times = number;
return this.getNumberOfTimes();
}
}
END_OF_JAVA
my $Fox = new FoxTrot;
print $Fox->setNumberOfTimes('500');
print $Fox->DoPunishment();
;)
Update: Just made it a little easier to read
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by benn (Vicar) on Oct 04, 2003 at 00:18 UTC
|
The wooden spoon award...
print "I will not throw paper airplanes in class."; #1
print "I will not throw paper airplanes in class."; #2
print "I will not throw paper airplanes in class."; #3
print "I will not throw paper airplanes in class."; #4
.
.
.
print "I will not throw paper airplanes in class."; #498
print "I will not throw paper airplanes in class."; #499
print "I will not throw paper airplanes in class."; #500
:) Ben. | [reply] [d/l] |
|
That's unmaintainable. Use a heredoc.
print <<"EOT";
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
.
.
.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
EOT
<tongue-in-cheek />
Makeshifts last the longest.
| [reply] [d/l] |
|
What do you call that, Tantric Golf?
| [reply] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class (using __DATA__)
by grinder (Bishop) on Oct 03, 2003 at 22:17 UTC
|
my $times = shift || 500;
my $line = <DATA>;
while( $times-- ) {
print "$line\n";
}
__DATA__
I will not throw paper hairplanes in class.
update: hmm, just looked at the comic. A true C coder would of course write:
for( count = 0; count < 500; count++ )
Seeing something start from 1 in C looks really odd :o) | [reply] [d/l] [select] |
|
Whoa, too much code, not enough DATA...
print <DATA>;
__DATA__
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
.
.
.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
I will not throw paper airplanes in class.
| [reply] |
|
print <DATA>x500;
__DATA__
I will not throw paper airplanes in class.
Makeshifts last the longest.
| [reply] [d/l] |
|
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by Roger (Parson) on Oct 04, 2003 at 11:22 UTC
|
Hehehe... very interesting. Below are my attempts -
Method 1 - Unnecessarily complicated
print qq{@{[qw/I will not throw paper airplanes in class./]}\n} for 1.
+.500;
Method 2 - The C look alike
for ($i=0;$i<500;$i++) {
printf("I will not throw paper airplanes in class.\n");
}
Method 3 - Embedded text
my $line = <DATA>;
map { print $line } 1..500;
__DATA__
I will not throw paper airplanes in class.
Method 4 - Simple obfuscation
$line="\n.ssalc ni senalpria repap worht ton lliw I";
print join'',reverse split//,$line for 1..500;
Method 5 - Another obfuscation
%x=qw/airplanes 5 class. 7 I
0 in 6 not 2 paper 4 throw 3
will 1/; print qq{@{[map {$_
->[0]} sort{$a->[1]<=>$b->[1
]}map{[$_, $x{$_}]}keys %x]}
} for 1..length 'x' x 2 x 5
x 5 x 5 x 2; $a;$b;$c;$d;$e;
Method 6 - Back to BASIC, my own embedded mini BASIC interpreter!
while(<DATA>){chomp,m/^(\d+)\s+(.*)/,$p[$1]=$2}{
redo if ($p[++$pc] eq undef);
if($p[$pc]=~/^(?:\s)*FOR\s+(\w+)(?:\s)*=(?:\s)*(\d+)(?:\s)*TO(?:\s)*
+(\d+)/x){
$var{$1} = [$pc, $2, $3];
}elsif ($p[$pc] =~ /^(?:\s)*PRINT\s+'(.*)'/x){
print "$1\n";
}elsif ($p[$pc] =~ /^(?:\s)*NEXT\s+(\w+)/x){
die "variable $1 not defined!" if !$var{$1};
$var{$1}->[1]++;
$pc = $var{$1}->[0] if $var{$1}->[1] <= $var{$1}->[2];
}elsif ($p[$pc] =~ /^(?:\s)*END/x){
exit(0);
}
redo;
}
__DATA__
1 REM ****** BASIC PROGRAM *******
2 REM *** Print Text 500 times ***
3
10 FOR I = 1 TO 500
20 PRINT 'I will not throw paper airplanes in class.'
30 NEXT I
31
32 REM ****** I CAN DO NESTED LOOP TOO ******
33
40 FOR I = 1 TO 2
50 FOR J = 1 TO 5
60 FOR K = 1 TO 5
70 FOR L = 1 TO 10
80 PRINT 'I will not throw paper airplanes in class.'
90 NEXT L
100 NEXT K
110 NEXT J
120 NEXT I
130 END
| [reply] [d/l] [select] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by tsee (Curate) on Oct 04, 2003 at 16:44 UTC
|
I bet this is goint to be the weirdest entry unless somebody comes up with a Brainf*ck implementation.
use Acme::Chef;
print Acme::Chef->compile(join '', <DATA>)->execute();
__DATA__
Roasted black board with grinded chalk.
Ingredients.
73 students
32 teachers
119 chairs
105 tables
108 pieces of chalk
108 black boards
32 hectolitres of coffee
110 paper planes
111 pencils
116 sheets of paper
32 pieces of bread
116 minutes of spare time
104 nuts
114 olives
111 computers
119 g chocolate
32 kg flour
112 g salt
97 bottles of whisky
112 ski masks
101 perl hackers
114 ways to write code
32 characters
97 sheep
105 litres of vinegar
114 brt of oil
112 beds
108 golf clubs
97 beginners
110 benchmarks
101 monks
115 mails
32 trojans
105 worms
110 security bulletins
32 microsoft spokespeople
99 aol cds
108 start menus
97 shells
115 cshs
115 kshs
46 bashes
32 kg stuff
500 bottles of vodka
Method.
Put stuff into mixing bowl. Put bashes into mixing bowl.
Put kshs into mixing bowl. Put cshs into mixing bowl. Put shells
into mixing bowl. Put start menus into mixing bowl. Put aol cds
into mixing bowl. Put microsoft spokespeople into mixing bowl. Put
security bulletins into mixing bowl. Put worms into mixing bowl.
Put trojans into mixing bowl. Put mails into mixing bowl. Put monks
into mixing bowl. Put benchmarks into mixing bowl. Put beginners
into mixing bowl. Put golf clubs into mixing bowl. Put beds into
mixing bowl. Put brt of oil into mixing bowl. Put litres of vinegar
into mixing bowl. Put sheep into mixing bowl. Put characters into
mixing bowl. Put ways to write code into mixing bowl. Put perl
hackers into mixing bowl. Put ski masks into mixing bowl. Put
bottles of whisky into mixing bowl. Put salt into mixing bowl. Put
flour into mixing bowl. Put chocolate into mixing bowl. Put
computers into mixing bowl. Put olives into mixing bowl. Put nuts
into mixing bowl. Put minutes of spare time into mixing bowl. Put
pieces of bread into mixing bowl. Put sheets of paper into mixing
bowl. Put pencils into mixing bowl. Put paper planes into mixing
bowl. Put hectolitres of coffee into mixing bowl. Put black boards
into mixing bowl. Put pieces of chalk into mixing bowl. Put tables
into mixing bowl. Put chairs into mixing bowl. Put teachers into
mixing bowl. Put students into mixing bowl.Liquify contents of the
mixing bowl. Waste the bottles of vodka. Pour contents of the mixing
bowl into the baking dish. Drink the bottles of vodka until wasted.
Serves 1.
| [reply] [d/l] |
|
We need Unlambda and/or SPL interpreters in Perl, then you'd see weird.. :)
Makeshifts last the longest.
| [reply] |
|
Both these languages have the saving grace that they
don't require the programmer to think in trinary
(base 3).
When we get Inline::Malbolge, then you'll see weird.
update: Upon further inspection,
I recant my former position on Unlambda and agree
that it is indeed quite weird after all. I had
not fully understood the implications of the
combinators before.
SPL, OTOH, is just lame
and verbose; any resemblance to Shakespearean plays
is so superficial as to be irrelevant. The language
is semantically so similar to a typical
normally-paradigmed language
that it is not even necessary to read the manual to get
a general idea how it works; looking at the examples is
adequate. Language like "You are equal to the sum
of yourself and several apparently randomly selected
words" is neither Shakespearean nor terribly original,
but the meaning is pretty obvious.
I also still maintain that the trinary nature of
Malbolge makes it weird. You need a warped and
twisted mind just to be *able* to think in trinary,
much less to come up with the idea of forcing the
programmer to do so. It should be noted, it's not
just a regular language converted mathematically
from base 16 (or whatever) to 3 for obfuscatory
purposes, like the way a JAPH might convert between
base 256 (ASCII) and 16 (hex) by using unpack.
No, Malbolge is designed as trinary
from the ground up. That's weird.
$;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}}
split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
| [reply] [d/l] |
|
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by Anonymous Monk on Oct 03, 2003 at 14:39 UTC
|
Or how about
perl -le 'print"I will not throw paper airplanes in class.\n"x500;
Mark
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by ambrus (Abbot) on Oct 04, 2003 at 20:13 UTC
|
Unlike the child, I'll print the text with newlines. I have two solutions.
The first is tail recursion.
perl -e'sub p{print"I will not throw paper airplanes in the class\n";+
++$x<500&&&p};p'
The second is not really perl. My shell is compiled with readline, so I can type in 500 a's simply by pressing \e500a. So, just type perl -e'$_="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
+aaaaaaaaaaaaaaaaaaaaaaaaaaaa";s/a/I will not throw paper airplanes in
+ class\n/g;print'
Knuth has written a lot about solving this problem in TeX in The TeXbook, chapter 20.
| [reply] [d/l] [select] |
Re: (Obfu) Airplanes in class
by Aristotle (Chancellor) on Oct 04, 2003 at 17:14 UTC
|
use strict;
$::PUNISHMENT = 'q[print"I will not throw paper airplanes in class.\n"
+;]';
$::PUNISHMENT =~ s{.*}{q(q[{local$_=).$&.q(.qq[{chop}$/=).$_.q(];{eval
+&&redo}}])}e for qw(CHALK ONTO BLACK BOARD);
s!!$::PUNISHMENT!eee;
Credit for the core idea to Abigail.
Makeshifts last the longest.
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by thor (Priest) on Oct 05, 2003 at 05:33 UTC
|
I'll swing with a vi(m) solution:
500iI will not throw paper airplanes in class.<RETURN><ESC>
Where <RETURN> and <ESC> are the return and escape keys on your keyboard, respectively. :-)
thor
| [reply] [d/l] [select] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by Beechbone (Friar) on Oct 07, 2003 at 20:10 UTC
|
map
{ print "I will not throw paper airplanes in class.\n" }
( print "I will not throw paper airplanes in class.\n" )
x499
And now try to explain this to someone who doesn't know any Perl... <veg>
| [reply] [d/l] [select] |
Golfing at the chalkboard?
by atcroft (Abbot) on Oct 03, 2003 at 19:27 UTC
|
A friend of mine earlier forwarded me this panel from the FoxTrot cartoon strip. I can recall considering something like that in a similar situation back when, but decided that (since it is text) it could be done better in perl.
My best guess (which I have attempted to conceal, for those who want to try it themselves) is below, at 70 chars total, but I am by no means a golfing pro-how can it be done better?
perl -e 'print "I will not throw paper airplanes in class.\n" x 500'
|
|
Update: Juerd beat me to posting regarding this, but I'd still like to see it golfed....
| [reply] [d/l] |
Re: (TIMTOWTDI / Golf / Obfu) Airplanes in class
by stephann (Initiate) on Oct 06, 2003 at 13:18 UTC
|
perl -e 'my $s = "I will not throw paper airplanes in class"; for (my
+$i=0;$i<9;$i++) { $s =~ s/^(.*)$/"$1\n$1"/seg;} my @a = split(/\n/,$s
+); for (my $i=0;$i<11;$i++) { pop @a}; print join("\n",@a)'
| [reply] [d/l] |