Autobots, roll out
3 direct replies — Read more / Contribute
|
by drpaz
on Aug 06, 2015 at 16:05
|
|
|
Been a while since I posted anything new, had some fun with this. This uses xterm-256 but tested well with putty and comes out fine on cygwin as well.
#!/usr/bin/perl -w
use strict;
my
@d;
my$__ #
= ':'; my #
$___ =18 ;for( 'a'
..'d' ){ push #
@d,$_ .$__. $___;$___
++;}$___ +=5;for('e'..'i'){push
@d,$_.$__ .$___ ;$___+=6;}$___='';
for(1..3) { $___.=$_}push@d,'j'.$__.$___
;$___=''; for( 1..9){$___.=$_ unless(($_-1)%4
); }push@d,'k'.$__.$___;$___=''; for('a'..
'am'){$___.=$_;}push@d,'l'.$__. length($___
);$___=length($___)+36;push @d,'m' .
$__.$___;$___*=2;$___-=16;push @d,'n' .
$__.$___;$___+=36;for('o'.. 's'){push
@d,$_.$__.$___;$___+=7;}push @d,'W'.
$__ .$___;my@__;$___=''; while(
<DATA>){chomp;s/\s//g; $___.=$_;
}push@d,split/\//, $___;my$m;
foreach(@d){if( m/^(\w):(.*)$/
){$m->{$1}="\033". '[48;5;'.
$2."m \033[0m";} else{
s/S/ /g;my$_oO_;
while((s/^(\d+)(.)//))
{$_oO_ .=$2
x$1}$_oO_ .=$_;$_=
$_oO_;$_.= #########
reverse$_; s/(\w)/$m->{$1}/g;
print;print "\n";}}####
__DATA__
22S18 a/18S22b/16S24c
/14a2S21d3S/ 14b2S13e11S/14c
3S17f6S/1S13d 3S17g6S/1S13e3S2
1h2S/1S6f3S5f5 S20i/2S5g5S6g6S1
6j/2S7h5S7h5S1 4k/2S9i5S8i5S11W/3
S4j2S5j4S10j4S8 W/3S4k4S5k4S9k6S5W/
3S4W6S5W5S6W9S2W /3S6W6S5W5S4W3S2W6S/
4S7W6S5W5S3W2S4W4S /4S9W7S4W3S3W3S5W2S/
4S 12W6S8W3S6W1S/6S 12W7S6W2S7W/8S13W6S4
W3S6W/3S3W6S1W10l5S2 l1W3S1W5l/3S1W2l 2W
5S2W16l1W2S1W5l/3S2 W3l2W5S3W13l1W3S
1W4l/4S1W5m2W6S14W3S 1W4m/4S1W7m2W21S1W
4m/4S1W8m1W21S1W4m/ 5S1W7n1W21S1W4n/6S1W
6n1W16S3W3S1W3n/6S1 W7n4W10S2W2n1W3S1W3n/
6S1W11o4W3S3W4o1W3S1W 3o/6S1W14o1W2S1W7o1W3
S1W3o/6S1W14o1W2S1W7o1 W3S1W3o/6S1W14p1W2S1W7
p1W3S1W3p/7S1W13p1W2S1W 7p1W3S1W3p/7S1W13p1W2
S1W7p1W3S1W3p/7S1W13q1W2S 1W7q1W3S4W/7S1W13q1W2
S1W7q1W7S/7S1W13q1W2S1W7q 8W/7S2W12q1W2S1W15q/9
S1W11r1W2S1W15r/10S1W10r 1W2S1W8r7W/11S1W9r1W2
S1W7r1W7S/12S4W5s1W2S1W5s2W 2S6W/16S2W3s1W2S1W4s1
W3S1W6q/18S4W2S1W4s1W2S1W7r /24S5W2S1W8s/24S5W2S9W
/26S2W3S9W/
|
How not to do prime factorization
2 direct replies — Read more / Contribute
|
by thisisdada
on Jun 30, 2015 at 10:05
|
|
|
$"x=$%="@ARGV";$~=$;='( +)';while($%>>$:++){if($"=~/$~$/^$"=~/$;$/){$
|=$?=$:>2||die"prime\n";eval"print length(\$$?)".($:>++$?&&"/length(\$
$?).'*'")while$:>$?;die$/}$;=$~;$~=~s~.*~^($&\\1+)~;$~=~s;\d+;1+$&;eg}
The best thing I can say about this code is that it works. It will take a number via argv give you the prime factorization of that number... eventually. It's not very efficient. At all. I had a lot of fun writing it, but it's really bad at what it does. To give you an idea of how erratic it is, here are some benchmarks:
While it can distinguish primes at a reasonable rate, it takes a really long time to factor composite numbers. Particularly composite numbers made up of several small primes. Powers of 2 are the worst-case scenario.
for$b(-25..25){for$a(-50..29){$x=$a/21;$y=$b/15;print$b?chr:chr^chr
ord(substr'<6C}'.1x29 .'[FDEq2?@E96Cqa6C=q924',$a)-49;$_=30;($y,$x)
=(2*$x*$y+$b/15,$x*$x-$y*$y+$a/21)while$x*$x+$y*$y<9&$_++<95}$_=10}
|
Is it possible to shorten this code?
2 direct replies — Read more / Contribute
|
by uacnix
on Jun 16, 2015 at 13:18
|
|
|
Hello dearest Monks,
i'm looking for the wisdom of shorthening my code:
use LWP::Simple;
@a = <>;
getprint("http://LeWebsite.com?a=".($a[0])."&b=".($a[2]));
As You have noticed, i'm not interested in the second line, but it is required that the program takes 3 lines of input:
-a digit
-some bollox that You can skip in the program execution, but it will have to bypass/workaround/skip this line
-some more or less random characters, that have to be passed as argument.
I'm just a peasant in PERL, but I heard it's the best language to write shortest code, so i'm trying my luck with It. Thank You in advance guys.
Update:
-I've checked the codes, and I've been able to use only the choroba's first code and at this place I'm really sorry that I didn't mention the STDIN input and chomp.
I found a workaround for chomp- I do it "serverside", my script on the site checks for newline symbols and replaces them
Anyway, thanks to You, dear Monks, my code is 14 chars shorter, and that's great progress, thank You!
|
Optimized Mandelbrot set generator
1 direct reply — Read more / Contribute
|
by thisisdada
on Jun 14, 2015 at 18:30
|
|
|
I wrote a Mandelbrot set generator. It works on Windows ActivePerl 5.20.2 x64, but I haven't tried it on *nix. It outputs a smoothed, anti-aliased fractal image to 24-bit .bmp file. For optimizations, it takes advantage of symmetry; it skips the cardoid, the main bulb, and the line across y=0; and it checks for cycles when the iteration count gets high. On my computer (2.40GHz i5-2430M), it takes about 10 minutes to generate a 1500x1000 image.
The code's designed to look like the set, of course. It takes user input to determine the size of the image and the outfile, i.e.:
C:\Users\Kevin>mandelgen.pl 1200 mandel.bmp
Generating fractal with dimensions 1200 by 800...
[==================================================]
Saving fractal to mandel.bmp... Done!
If the given pixel width isn't divisible by 12, the program subtracts until it is.
for$b(-25..25){for$a(-50..29){$x=$a/21;$y=$b/15;print$b?chr:chr^chr
ord(substr'<6C}'.1x29 .'[FDEq2?@E96Cqa6C=q924',$a)-49;$_=30;($y,$x)
=(2*$x*$y+$b/15,$x*$x-$y*$y+$a/21)while$x*$x+$y*$y<9&$_++<95}$_=10}
|
Convoluted Echo
2 direct replies — Read more / Contribute
|
by KurtSchwind
on May 22, 2015 at 14:19
|
|
|
So let's say you are on a *nix machine and you need an application that echos what you type. And let's further say that you want to use perl, python, ruby and shell to do it. I bring you convoluted echo. A perl script the writes and executes a python script that's and executes a ruby script which writes and executes a shell script to echo your command line arguments.
Happy Memorial Day
#!/usr/bin/perl
my $echo = q{};
open my $py, '>', 'ce.py' or die "Cannot open ce.py: $!\n";
$py->print("#!/usr/bin/python\n\n");
$py->print("import os\n\n");
$py->print("fo = open(\"ce.rb\",\"w\")\n\n");
$py->print("fo.write(\"#!/usr/bin/ruby\\n\")\n");
$py->print("fo.write(\"out_file = File.new(\\\"ce.sh\\\", \\\"w\\\
+")\\n\")\n");
$py->print(q{fo.write("out_file.puts(\"#!/bin/sh\\n\\necho $*\\n\\
+")\n")});
$py->print("\n");
$py->print(q{fo.write("out_file.close\n\n")});
$py->print("\n");
$py->print("\n");
foreach my $a (@ARGV) {
$echo .= " ".$a;
# $py->print( " $a ");
}
$py->print(q{fo.write("system(\"/bin/sh ce.sh });
$py->print(" $echo ");
$py->print(q{\")\n")});
$py->print("\nfo.close()\n");
$py->print("os.system(\"/usr/bin/ruby ce.rb\")\n");
close $py;
system("/usr/bin/python ce.py");
--
“For the Present is the point at which time touches eternity.” - CS Lewis
|
Polybius JAPH
1 direct reply — Read more / Contribute
|
by teamster_jr
on Apr 29, 2015 at 11:36
|
|
|
$_ =q#( $.=" 20 2c4a 506 175" )=~s {[ \W] ?([ \w] )\s ?(\w ) }{ $
|= 1 ; "0x$ 1$2 ".( 5 - (++$ b)? " ," :".. " ) }xeg ;$ l=~ s {
\s}{ ; ""}exg;@t=split //, "\44_ =q\43$_\43; s/\134\156//xg; eval
".($"x2)."\43TSR'15";map{ $ a[$c /5] [$c++%5] =chr } eval $ .; do {$s
+= 1; my $ z; if ($t [$s ] eq $"){($ d++% 2 ?$x: $ y )=$ s- $e;$e=
$s+ 1;if( !($ d-2) ){$ d=0; push @j,$ a[$ x ][$ y] } } }while@j-25;
print join $ /, unpack ("( A69)*" , join"" ,@ t ), join "",$ /, (m
ap{( "\43", @$_,$ /) }@ a),"\n\43 ",@j,$/;#; s/\n//xg; eval #TSR'15
Polybius
|
JAPH does the splits
1 direct reply — Read more / Contribute
|
by Schmunzie
on Apr 12, 2015 at 19:14
|
|
|
My first JAPH for years and years. I'm not sure if this is platform-independent. I hope it is.
@z=split(//,BGu6pCozwKzR);@y=qw(zlz hqa zuo reg rqz fpx 72 26 25 53 25
+ 06);while(@z){@a=split(shift@z,crypt(shift@y,pop@y));@g=split(pop@z,
+$a[1]);print $g[0]}
|
This One's a Sieve
3 direct replies — Read more / Contribute
|
by Schmunzie
on Mar 31, 2015 at 11:17
|
|
|
hdb recently pointed out that I had misremembered how the Sieve of Eratosthenes works so now I'm having another go. Not all that obfu'd but moderately golfed.
$m=250;for(2..$m){for($a=$_*2;$a<=$m;$a+=$_){$c[$a]++}print"$_,"x!$c[$_]}
|
What Perl Will Tell
No replies — Read more | Post response
|
by martin
on Mar 20, 2015 at 00:05
|
|
|
This one may be somewhat system-dependent but worked with quite different flavours of Perl. I expect it will be difficult to predict without actually using a perl binary.
Have fun!
eval'[]->Jk',$^X=~m;(?:.*[\\/])?([^\W\d]+);;$==ord('?'^':'),$,=q**
,*_=[map+chr,$[..$=<<$=],*_={map{;$_,++$=}grep/(?=\W)[$"-~]/,@_},*
_=sub{map{join$,,@_[@_{split$,,$_}]}+$,."->]'","!?;'(&}","(! .\\}"
},*_=[_(split$,,$@),"\u$1"],*_=\"@_[$[,!!!$[,-!$[,$#_^!$[],",print
|
Are old obfus gone forever?
5 direct replies — Read more / Contribute
|
by Schmunzie
on Mar 19, 2015 at 20:39
|
|
|
|
|
|