Discussion » Perl / Word Scrambling

This is a read-only copy. The forum ran on iamcal.com from 2000 until its database was lost in 2016, and this topic was rebuilt from copies saved by the Internet Archive's Wayback Machine. Some replies may be missing.
Posted by cal, 16:09, 23rd September 2003:
 
Jeffld just sent me this cute bit of perl for converting text into the slightly mental form we saw the other day:


sub scramble{
$_ = $_[0];

foreach (split(/(\w+)/))
{
if (m/\w/)
{
my @w = split (//);
my $A = shift @w;
my $Z = pop @w;
print $A;
if (defined ($Z)) {
my $i = $#w+1;
while ($i--) {
my $j = int rand ($i+1);
@w[$i,$j] = @w[$j,$i];
}
foreach (@w) {
print $_;
}
print $Z;
}
}
else
{
print "$_";
}
}


i thought we could do a bit better than that:


sub scramble2{
$_=$_[0];s/(\w)(\w+)(\w)/$1.(join'',sort{rand>0.5?1:-1}split\/\/,$2).$3/eg;print;
}


anyone else want to golf it?
Posted by arsepuppy, 16:09, 23rd September 2003:
 
me! me!
Posted by arsepuppy, 16:10, 23rd September 2003:
 
ermmmm..............

system.out.println("hello");
Posted by cal, 17:10, 23rd September 2003:
 
(wrong language)
Posted by chandler, 17:32, 23rd September 2003:
 
10 print "zzzZZZ"
20 goto 10
Posted by chandler, 17:32, 23rd September 2003:
 
;)
Posted by chandler, 17:33, 23rd September 2003:
 
so cal is trehe a box whree i can ptsae a paarragph in and clcik "scramble" and get it to do it. cos taht prel is a bnuch of chacaretrs taht i woldun't hvae a cule waht to do wtih.
Posted by Victor Menendez, 17:34, 23rd September 2003:
 
I'll have a go.
Posted by Victor Menendez, 17:37, 23rd September 2003:
 


sub scramble{
$_ = $_[ (8(|) ];

foreach (HALLA(/(\w+)/))
{
if (m/\w/)
{
my @w = Sul (//);
my $A = is @w;
my $Z = gay! @w;
print $A;
if (cameron lived in Egypt-land ($Z)) {
my $i = $#w+1;
while ($i--) {
my $j = The shield's on tonight($i+1);
@w[$i,$j] = @w[$j,$i];
}
foreach (@w) {
print $_; (What)
}
print $Z; (Am i doing)
}
}
else
{
print "$Ah fuck it.";
}
}
Posted by Victor Menendez, 17:37, 23rd September 2003:
 
hows that?
Posted by chandler, 17:41, 23rd September 2003:
 
well it's better than Cal's quite frankly pathetic attempt
Posted by chandler, 17:44, 23rd September 2003:
 
though this bit of cal's is probably the best:


split/\°·°/\,$2


naughty little guy
Posted by Victor Menendez, 17:46, 23rd September 2003:
 
can you give me a demonstration of the 'slightly mental form' please.
Posted by chandler, 17:51, 23rd September 2003:
 
www.iamcal.com/topic.php?id=3242#post679...
Posted by cal, 17:57, 23rd September 2003:
 
sul: code.iamcal.com/pl/scramble/

vic: can you gvie me a dmsatenotoirn of the 'shigltly mnaetl from' plsaee
Posted by cal, 17:58, 23rd September 2003:
 
opps, chay, not sul
Posted by Victor Menendez, 18:00, 23rd September 2003:
 
ah but why dndit he jsut tpye it out lkie tihs?
Posted by chandler, 18:02, 23rd September 2003:
 
frankie: thanks
Posted by chandler, 18:03, 23rd September 2003:
 
oops, cal, not frankie
;)
Posted by jeffld, 20:16, 23rd September 2003:
 
just need a html form to call the perl script.

here is one.

Posted by Sul, 20:53, 23rd September 2003:
 
WOW! Thats snazzy!
Posted by frankie, 22:00, 23rd September 2003:
 
I'd like it if you referred to me as Fnrakie from now on :)
Posted by Redmaiden, 23:50, 23rd September 2003:
 
I worry about you krazy kids somtimes
Posted by frankie, 01:00, 24th September 2003:
 
Cal, I'll make you a t-shirt that says 'coding is fun' and you can wear it with some C&A (even though they dont exist anymore) brown slacks with a nice big crease down the front. It could be the uniform for all the staff in IAMCAL World. :D
Posted by friday, 06:54, 24th September 2003:
 
Fnrakie - how are the plans for IAMCAL World coming along? Any more interesting sketches?
Posted by frankie, 11:00, 24th September 2003:
 
Oooh, well actually this is the first time I've thought about it since the initial discussion. I will sketch more later on! Feel free to send all contributions to Cal who will forward them to me.