From: Yanick Champoux
On 12-12-25 02:04 AM, Andrew Savige wrote:
> Continuing the thread from Jan 2007 after more than five years,
> the famous "Hospelian Arabic to Roman Transform" aka HART, as
> played by Ton in the Fonality Christmas golf challenge, has been
> shortened by one stroke by primo.
Holy schmolee. I now have this mental image of primo looking at his
monitor, dust gathering in the deep frown above his staring eyes, as the
five years trickle by, until the moment he went 'ah AH!', and shaved
that byte off the prior solution...
Well done,
`/anick
From: Andrew Savige
> This series is now complete with the addition of two bonus episodes:
>
> * http://www.perlmonks.org/?node_id=811919 (Part V)
> * http://www.perlmonks.org/?node_id=814900 (Part VI)
One more: http://www.perlmonks.org/?node_id=903641
Cheers
/-\
From: John W. Krahn
Eric Waguespack wrote:
> this was an attempt to make a password generator that creates the same
> ASCII password every time, given an arbitrary string. (basically 1
> password per website)
>
> this is what i have so far:
>
> echo masterpassword gmail.com | perl -MDigest::SHA -ne '$h = $_; for
> (1..10) { $h=Digest::SHA::sha512_hex("$h") }; $_=$h; while (/(..)/g) {
> $x=$1; $x = int((hex $x) / 2); if( $x ~~ [33..126] ) {print chr($x)};
> END {print "\n";};}' | cut -b1-10
echo masterpassword gmail.com | perl -MDigest::SHA=sha512_hex
-lpe'{$_=sha512_hex($_);++$x<10&&redo}s!(..)!$_=chr
hex($1)/2;y|\41-\177||?$_:""!eg;s/(.)(?=.*?\1)//sg;$_=substr$_,0,10'
John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity. -- Damian Conway
From: Jasvir Nagra
Sure. It wasn't clear what the value of that was other than slowing things
down (which may of course be of value).
On Fri, Oct 9, 2009 at 4:05 PM, Eric Waguespack <ewaguespack@gmail.com>wrote:
> the perl has a loop that rehashes the string 10 times
>
> On Fri, Oct 9, 2009 at 6:02 PM, Jasvir Nagra <jas@nagras.com> wrote:
> > If you have a command line sha1:
> > echo masterpassword gmail.com | sha1sum | perl -alnF'/(..)/' -e
> > '@a=map{$_=chr(hex($_)/2);tr/!-~//cd;$_}@F;print@a'
> > --
> > Jasvir Nagra
> > http://www.cs.auckland.ac.nz/~jas
> >
> >
> > On Fri, Oct 9, 2009 at 2:58 PM, Eric Waguespack <ewaguespack@gmail.com>
> > wrote:
> >>
> >> this was an attempt to make a password generator that creates the same
> >> ASCII password every time, given an arbitrary string. (basically 1
> >> password per website)
> >>
> >> this is what i have so far:
> >>
> >> echo masterpassword gmail.com | perl -MDigest::SHA -ne '$h = $_; for
> >> (1..10) { $h=Digest::SHA::sha512_hex("$h") }; $_=$h; while (/(..)/g) {
> >> $x=$1; $x = int((hex $x) / 2); if( $x ~~ [33..126] ) {print chr($x)};
> >> END {print "\n";};}' | cut -b1-10
> >>
> >> I also want to incorporate this, it removes duplicate characters
> >> (irrespective of location), but my current code doesn't let me just
> >> slip it in.
> >>
> >> $s =~ s[(.)(?=.*?\1)][]g;
> >
> >
>
From: Eric Waguespack
the perl has a loop that rehashes the string 10 times
On Fri, Oct 9, 2009 at 6:02 PM, Jasvir Nagra <jas@nagras.com> wrote:
> If you have a command line sha1:
> echo masterpassword gmail.com | sha1sum | perl -alnF'/(..)/' -e
> '@a=map{$_=chr(hex($_)/2);tr/!-~//cd;$_}@F;print@a'
> --
> Jasvir Nagra
> http://www.cs.auckland.ac.nz/~jas
>
>
> On Fri, Oct 9, 2009 at 2:58 PM, Eric Waguespack <ewaguespack@gmail.com>
> wrote:
>>
>> this was an attempt to make a password generator that creates the same
>> ASCII password every time, given an arbitrary string. (basically 1
>> password per website)
>>
>> this is what i have so far:
>>
>> echo masterpassword gmail.com | perl -MDigest::SHA -ne '$h = $_; for
>> (1..10) { $h=Digest::SHA::sha512_hex("$h") }; $_=$h; while (/(..)/g) {
>> $x=$1; $x = int((hex $x) / 2); if( $x ~~ [33..126] ) {print chr($x)};
>> END {print "\n";};}' | cut -b1-10
>>
>> I also want to incorporate this, it removes duplicate characters
>> (irrespective of location), but my current code doesn't let me just
>> slip it in.
>>
>> $s =~ s[(.)(?=.*?\1)][]g;
>
>
From: Jasvir Nagra
If you have a command line sha1:
echo masterpassword gmail.com | sha1sum | perl -alnF'/(..)/' -e
'@a=map{$_=chr(hex($_)/2);tr/!-~//cd;$_}@F;print@a'
--
Jasvir Nagra
http://www.cs.auckland.ac.nz/~jas
On Fri, Oct 9, 2009 at 2:58 PM, Eric Waguespack <ewaguespack@gmail.com>wrote:
> this was an attempt to make a password generator that creates the same
> ASCII password every time, given an arbitrary string. (basically 1
> password per website)
>
> this is what i have so far:
>
> echo masterpassword gmail.com | perl -MDigest::SHA -ne '$h = $_; for
> (1..10) { $h=Digest::SHA::sha512_hex("$h") }; $_=$h; while (/(..)/g) {
> $x=$1; $x = int((hex $x) / 2); if( $x ~~ [33..126] ) {print chr($x)};
> END {print "\n";};}' | cut -b1-10
>
> I also want to incorporate this, it removes duplicate characters
> (irrespective of location), but my current code doesn't let me just
> slip it in.
>
> $s =~ s[(.)(?=.*?\1)][]g;
>
From: Eric Waguespack
this was an attempt to make a password generator that creates the same
ASCII password every time, given an arbitrary string. (basically 1
password per website)
this is what i have so far:
echo masterpassword gmail.com | perl -MDigest::SHA -ne '$h = $_; for
(1..10) { $h=Digest::SHA::sha512_hex("$h") }; $_=$h; while (/(..)/g) {
$x=$1; $x = int((hex $x) / 2); if( $x ~~ [33..126] ) {print chr($x)};
END {print "\n";};}' | cut -b1-10
I also want to incorporate this, it removes duplicate characters
(irrespective of location), but my current code doesn't let me just
slip it in.
$s =~ s[(.)(?=.*?\1)][]g;
From: yanick
On Wed, Jun 24, 2009 at 06:59:41PM +0200, Eirik Berg Hanssen wrote:
> yanick@babyl.dyndns.org writes:
> > I'm probably overlooking something silly, but
> >
> > perl -O0 -pe's/.{65535,}//'
> >
> > ?
>
> Newlines.
Arrgh. I knew I was forgetting something. Darn, foiled again!
Joy,
`/anick
--
From: Daniel Tiefnig
Phil Carmody wrote:
> I needed to remove blank-line-separated chunks of code from a text
> file if those chunks contained any lines which were 'too long'.
[...]
> If you think how little it does, it's got to be one-linerable, no?
Should do the trick:
perl -00 -ne'/.{65535}/||print'
lg,
daniel
From: Daniel Tiefnig
Phil Carmody wrote:
> I needed to remove blank-line-separated chunks of code from a text
> file if those chunks contained any lines which were 'too long'.
[...]
> If you think how little it does, it's got to be one-linerable, no?
Here's one that does split on lines with whitespace too, but is much
less elegant than my first one:
perl -0777 -F'(?<=\n)\s*(?=\n)' -ane'/.{65535}/||print for@F'
Maybe one can save one or the other stroke with a smarter solution of
the newline issue...
lg,
daniel
From: Daniel Tiefnig
Eirik Berg Hanssen wrote:
>> I'm probably overlooking something silly, but
>>
>> perl -O0 -pe's/.{65535,}//'
>
> Newlines.
Besides that I'm getting "Can't do {n,m} with n > m in regex" for values
greater than 2^15 - 1 here.
br,
daniel
From: Eirik Berg Hanssen
yanick@babyl.dyndns.org writes:
> On Wed, Jun 24, 2009 at 04:26:05PM +0100, Jasper wrote:
>> 2009/6/24 Daniel Tiefnig <dantie@gmx.at>:
>> >
>> > ?perl -00 -ne'/.{65535}/||print'
>> >
>>
>> of course becomes
>>
>> perl -00 -pe'$_ x=!/.{65535}/'
>
> I'm probably overlooking something silly, but
>
> perl -O0 -pe's/.{65535,}//'
>
> ?
Newlines.
Eirik
--
Perl programmers do it more than one way
From: yanick
On Wed, Jun 24, 2009 at 04:26:05PM +0100, Jasper wrote:
> 2009/6/24 Daniel Tiefnig <dantie@gmx.at>:
> >
> > ?perl -00 -ne'/.{65535}/||print'
> >
>
> of course becomes
>
> perl -00 -pe'$_ x=!/.{65535}/'
I'm probably overlooking something silly, but
perl -O0 -pe's/.{65535,}//'
?
Joy,
`/anick
From: Daniel Tiefnig
Phil Carmody wrote:
> I needed to remove blank-line-separated chunks of code from a text
> file if those chunks contained any lines which were 'too long'.
[...]
> If you think how little it does, it's got to be one-linerable, no?
Duh, wrong e-mail address, sorry if solutions show up twice now after a
while...
Should do the trick if paragraphs are separated by *empty* lines:
perl -00 -ne'/.{65535}/||print'
Here's one that does split on lines with whitespace too, but is much
less elegant than my first one:
perl -0777 -F'(?<=\n)\s*(?=\n)' -ane'/.{65535}/||print for@F'
Maybe one can save one or the other stroke with a smarter solution of
the newline issue...
lg,
daniel
From: Phil Carmody
I needed to remove blank-line-separated chunks of code from a text file if those chunks contained any lines which were 'too long'. So in glorious hyper-verbose mode, I did the following:
#!/usr/bin/perl -wT
my $MAXLEN=65535;
my @chunk=();
my $maxlen=0;
while(<>)
{
if(m/\S/)
{
if(length($_)>$maxlen) { $maxlen=length($_); }
push(@chunk, $_) if($maxlen<$MAXLEN);
}
else
{
if($maxlen<$MAXLEN and @chunk)
{
print(@chunk, $_);
}
@chunk = ();
$maxlen = 0;
}
}
If you think how little it does, it's got to be one-linerable, no?
The 65535 is a bit arbitrary. Feel free to use anything between 1e5 and that.
Phil
From: Yanick Champoux
Andrew Savige wrote:
> For nostalgia buffs, Eugene, Ton, Mtv, ... even `/anick all get
> a mention. :-)
Aaah... Nostalgia indeed. Those were the good ol' days...
And talking of remembering those days of yore... For those who were
there, do you remember how Stephen Turner discovered 'www.googlism.com',
way back in 2002? And how /\ndrew tried my name on it, and saw that I
was described by a rather boring 'Yanick Champoux is currently m'? And
how he decided to take matters in his own hands and, ahhh..., spiffy up
things?
Well, to this very day, social network crawlers all over the Net are
prone to list me as a professor of psycho-sexual research at a great
European University.
Perl Golf... Yes, you may leave the green. But the green, it stays
forever with you. :-)
Joy,
`/anick
From: Jasper
Thanks for wasting my Sunday! And it's sunny! Son of a ...
--
Jasper
From: robert wilson
Phil Carmody wrote:
> We need dollar-free golf!
>
> In order to answer the question "what ratio of words in the SOWPODS wordlist share no letters in common with the word mackerel?", I quickly threw this together:
>
> perl -ne '$c[m/[mackrel]/]++;}print($c[1]/$.,$/);{' < sowpods
>
> However, there were complaints that it had too many dollar signs.
>
> What's the shortest equivalent script which uses no dollar signs at all?
>
> Phil
perl -le 'print+(grep{/[mackrel]/}@w=<>)/@w' < sowpods
?
now, if you actually want the answer to the question "what ratio of
words in the SOWPODS wordlist share _no_ letters in common with the word
mackerel?", you'd need to add a "!", like this:
perl -le 'print+(grep{!/[mackrel]/}@w=<>)/@w' < sowpods
From: Jasper
2009/4/26 Phil Carmody <thefatphil@yahoo.co.uk>:
>
> --- On Sun, 4/26/09, robert wilson <hotaru@safe-mail.net> wrote:
>> Phil Carmody wrote:
>> > We need dollar-free golf!
>> >
>> > In order to answer the question "what ratio of words
>> in the SOWPODS wordlist share no letters in common with the
>> word mackerel?", I quickly threw this together:
>> >
>> > perl -ne '$c[m/[mackrel]/]++;}print($c[1]/$.,$/);{' < sowpods
>> >
>> > However, there were complaints that it had too many dollar signs.
>> >
>> > What's the shortest equivalent script which uses no dollar signs at all?
>> >
>
>> perl -le 'print+(grep{/[mackrel]/}@w=<>)/@w' < sowpods
>
> Wow!!!
>
> It's obvious in retrospect. It's clear my original was horrifically wasteful, and can at least be shortened to this at the cost of one dollar:
> perl -le 'print+(grep{/[mackrel]/}<>)/$.' < sowpods
Shorter, with still one dollar. (actually, only shorter because you
have grep{} instead of grep with a comma, so the same)
perl -alp0e '$_=(grep/[mackrel]/,@F)/@F' < sowpods
Without the dollar, it's a bit longer, of course.
perl -aln0e 'print+(grep/[mackrel]/,@F)/@F' < sowpods
But that is the best I can do..
--
Jasper
(I'll send the tested one to the list, Phil)
From: Phil Carmody
--- On Sun, 4/26/09, robert wilson <hotaru@safe-mail.net> wrote:
> Phil Carmody wrote:
> > We need dollar-free golf!
> >
> > In order to answer the question "what ratio of words
> in the SOWPODS wordlist share no letters in common with the
> word mackerel?", I quickly threw this together:
> >
> > perl -ne '$c[m/[mackrel]/]++;}print($c[1]/$.,$/);{' < sowpods
> >
> > However, there were complaints that it had too many dollar signs.
> >
> > What's the shortest equivalent script which uses no dollar signs at all?
> >
> perl -le 'print+(grep{/[mackrel]/}@w=<>)/@w' < sowpods
Wow!!!
It's obvious in retrospect. It's clear my original was horrifically wasteful, and can at least be shortened to this at the cost of one dollar:
perl -le 'print+(grep{/[mackrel]/}<>)/$.' < sowpods
Phil
From: Phil Carmody
We need dollar-free golf!
In order to answer the question "what ratio of words in the SOWPODS wordlist share no letters in common with the word mackerel?", I quickly threw this together:
perl -ne '$c[m/[mackrel]/]++;}print($c[1]/$.,$/);{' < sowpods
However, there were complaints that it had too many dollar signs.
What's the shortest equivalent script which uses no dollar signs at all?
Phil
--
() ASCII ribbon campaign () Hopeless ribbon campaign
/\ against HTML mail /\ against gratuitous bloodshed
[stolen with permission from Daniel B. Cristofani]
From: Jasper
Hi, y'all,
Can anyone beat 55 on this? I don't know if we ever did it as a
challenge. Should I search for it in the book?
--
Jasper
From: Daniel Tiefnig
Zhu Shanshan wrote:
> As you said, when I substituted "s/\r\n$//" with "chomp", it did
> work. After looking up the explanation of "chomp" in perldoc, I found
> "chomp", which I always used to remove the newline previous, removes
> any trailing string that corresponds to the current value of "$/".
Hej,
JFTR, you may also want to have a look at "perldoc perlport". The first
issue discussed is "Newlines".
lg,
daniel
From: Zhu Shanshan
Thanks.
As you said, when I substituted "s/\r\n$//" with "chomp", it did work. After
looking up the explanation of "chomp" in perldoc, I found "chomp", which I
always used to remove the newline previous, removes any trailing string that
corresponds to the current value of "$/". And this time, it removed "\n" for
me. I'm really puzzled by this phenomena, because I always work with
"chomp". I guessed the problem came from the new SFTP software used
recently. Then I compared it with WinSCP using the same script. Bingo!
WinSCP has deleted "\r" for me and that's why I could luckily work,
previous.
Anyway, thank you again!
-----邮件原件-----
发件人: Ronald J Kimball [mailto:rjk-perl-golf@tamias.net]
发送时间: 2008年6月12日 12:28
收件人: Zhu Shanshan
抄送: Perl Golf
主题: Re: A challenge to explain the strange results (under linux)
I would bet that your color.txt file has Windows line endings on all
platforms. If you do this:
perl test.pl color.txt | less
you may find that you're getting output after all.
Make sure color.txt has Unix line endings on the Linux machines. Here's
one way to fix it:
perl -pi -e 'tr/\r//d' color.txt
Ronald
From: Ronald J Kimball
I would bet that your color.txt file has Windows line endings on all
platforms. If you do this:
perl test.pl color.txt | less
you may find that you're getting output after all.
Make sure color.txt has Unix line endings on the Linux machines. Here's
one way to fix it:
perl -pi -e 'tr/\r//d' color.txt
Ronald
From: Zhu Shanshan
I used perl "v5.8.5 built for i386-linux-thread-multi".
My data:
##################### File:color.txt
chartreuse
deeppink
goldenrod
lightblue
dodgerblue
darkgoldenrod
My scripts:
##################### File: test.pl
use strict;
use warnings;
open IN,"color.txt" or die;
while (<IN>){
chomp;
print "$_";
}
close IN;
Results under linux platform(Nothing):
"Linux compome 2.6.12-1.1381_FC3smp #1 SMP Fri Oct 21 04:03:26 EDT 2005 i686
i686 i386 GNU/Linux" RedHat
"Linux biome 2.6.9-55.ELsmp #1 SMP Fri Apr 20 16:36:54 EDT 2007 x86_64
x86_64 x86_64 GNU/Linux" RedHat
"Linux hanlab 2.6.16.46-0.12-smp #1 SMP Thu May 17 14:00:09 UTC 2007 i686
i686 i386 GNU/Linux" OpenSUSE
##################### command: perl test.pl
Results under Microsoft Windows XP (in my expectation):
##################### command: d:\soft\bin\perl.exe test.pl
Chartreusedeeppinkgoldenrodlightbluedodgerbluedarkgoldenrod
It's not really a Perl challenge. But can anyone give me some help or
suggestions?
Thanks in advance
Shanshan Zhu
From: Jasper
2008/5/30 Randal L. Schwartz <merlyn@stonehenge.com>:
>>>>>> "Jasper" == Jasper <jaspermccrea@gmail.com> writes:
>
> Jasper> Well, that was a big assumption, then.
>
> Keep in mind, "obvious" to you is very unlikely "obvious" to everyone else,
> since we all run in different circles.
I only found out about it because the guy next to me was doing them.
They do seem to be somewhat under the radar.
The third one opened yesterday. It wasn't really worthwhile writing a
program to solve it.
The robots one is still the only one I'd consider golfable. If one
allows the answers to be in non-integer format, the answer can be
pretty small - I have it around 48 with command line arguments. About
70 with the integer format required by google, and that's using
Math::BigInt.
Have a nice weekend..
--
Jasper
From: merlyn
>>>>> "Jasper" == Jasper <jaspermccrea@gmail.com> writes:
Jasper> Well, that was a big assumption, then.
Keep in mind, "obvious" to you is very unlikely "obvious" to everyone else,
since we all run in different circles.
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
From: Bram
On Tue, 27 May 2008 13:27:54 +0200, Jasper <jaspermccrea@gmail.com> wrote:
> Has anyone been golfing the google challenges?
What challenges?
>
> I've got the robot one to around 74 characters (not including the 'use
> Math::BigInt' :))
>
> The other one didn't seem all that interesting in comparison..
>
> ~~~tumbleweed~~~