<?xml version="1.0" encoding="windows-1252"?>
<node id="785052" title="When One Golfer Speculates On What Another Is Doing..." created="2009-07-31 23:07:22" updated="2009-07-31 23:07:22">
<type id="120">
perlmeditation</type>
<author id="176576">
eyepopslikeamosquito</author>
<data>
<field name="doctext">
&lt;P&gt;
&lt;blockquote&gt;

&lt;P&gt;
&lt;I&gt;
I can get down to 300 bytes without using compression schemes or code packing
in to an eval (perl). I think the 176 was using a string compression of the code.
&lt;/I&gt;
&lt;/P&gt;

&lt;P align="right"&gt;
&lt;small&gt;
-- &lt;a href="http://codegolf.com/boards/conversation/view/112"&gt;"SplinterFL" comments&lt;/a&gt; on the &lt;a href="http://codegolf.com/99-bottles-of-beer"&gt;codegolf 99 bottles of beer game&lt;/a&gt;
&lt;/small&gt;
&lt;/P&gt;

&lt;P&gt;
&lt;I&gt;
What I can't fathom is how someone could possibly
solve this problem in 134 characters in PHP, the way eyepopslikeamosquito did.
That is insane my friend.
Probably ran a Perl solution through PHP's shell command functions.
&lt;/I&gt;
&lt;/P&gt;

&lt;P align="right"&gt;
&lt;small&gt;
-- &lt;a href="http://blachan.com/blog/code-golf-saving-time/"&gt;Abdulla Arif comments&lt;/a&gt; on the &lt;a href="http://codegolf.com/saving-time"&gt;codegolf savingtime game&lt;/a&gt;
&lt;/small&gt;
&lt;/P&gt;

&lt;P&gt;
&lt;I&gt;
Don't assume. It makes an "ass" out of "u" and "me".
&lt;/I&gt;
&lt;/P&gt;

&lt;P align="right"&gt;
&lt;small&gt;
-- David Brent in &lt;a href="http://www.imdb.com/title/tt0290978/quotes"&gt;The Office&lt;/a&gt;
&lt;/small&gt;
&lt;/P&gt;

&lt;/blockquote&gt;
&lt;/P&gt;

&lt;P&gt;
Though I can't comment on the 176 char bottles of beer solution that "SplinterFL"
was referring to,
please note that my 168 char solution uses just a humble sub
and a lowly print statement inside a simple for loop.
No need for any "string compression of the code".
&lt;/P&gt;

&lt;P&gt;
As for my 134 character PHP saving time solution, I'm happy to reveal that
it does not "run a Perl solution through PHP's shell command functions".
It's just plain old PHP code.
No dirty tricks.
Just the usual blood, toil, tears and sweat.
&lt;/P&gt;

&lt;P&gt;
Why on Earth do beginning golfers indulge in such unfounded speculations?
I don't know but a possible answer can be found by
remembering one of [id://720219|Beth]'s many insightful responses
where she [id://775947|perceptively noted] that:
&lt;blockquote&gt;
&lt;I&gt;
In the late 1990's Justin Kruger and David Dunning did a series
of studies demonstrating that the less skillful had a tendency
to overrate their abilities and fail to recognize expertise in others.
&lt;/I&gt;
&lt;/blockquote&gt;
&lt;/P&gt;

&lt;P&gt;
Anyway, after reading Abdulla's 234 char PHP solution
to the codegolf
&lt;a href="http://codegolf.com/saving-time"&gt;Saving Time&lt;/a&gt;
challenge, namely:
&lt;CODE&gt;
&lt;?fscanf(STDIN,'%d:%d',$h,$m);$s=array_combine(str_split('0b1a29384756'),array_fill(0,12,'o'));$s[$h=dechex($h&gt;11?$h-12:$h)]='h';$s[$m=dechex($m&gt;59?0:$m/5)]=$h==$m?'x':'m';vprintf("%9s
%5s%8s

 %s%14s

%s%16s

 %s%14s

%5s%8s
%9s",$s)
?&gt;
&lt;/CODE&gt;
I refined his interesting approach
into a (shortened) 132 stroke Perl solution as follows:
&lt;CODE&gt;
&lt;&gt;=~/:/;@y=(o)x12;$y[$`%12]=h;$y[$'/5]=~y/oh/mx/;
printf'%9s
%5s%8s

 %s%14s

%s%16s

 %s%14s

%5s%8s
%9s',map{$y[$_],$y[11-$_]}0..5
&lt;/CODE&gt;
&lt;/P&gt;

&lt;readmore&gt;

&lt;P&gt;
To clarify precisely what problem this code is solving, and to make it easier to test
possible solutions, I've written a test program as follows:
&lt;CODE&gt;
# test.pl
use strict;
use warnings;
my $testprog = shift or die "usage: $0 program-file\n";
my $datafile = 'tt.txt';
my $cmd = "perl $testprog &lt;$datafile";
sub build_file {
    my $contents = shift;
    open(my $fh, '&gt;', $datafile) or die "open '$datafile': $!";
    print $fh "$contents\n";
    close($fh);
}
print "Testing $testprog, size=", -s $testprog, " bytes.\n";
my @testdata = (
  [ '00:00', &lt;&lt;'EXPECTED' ],
        x
    o       o

 o             o

o               o

 o             o

    o       o
        o
EXPECTED
  [ '23:59', &lt;&lt;'EXPECTED' ],
        o
    x       o

 o             o

o               o

 o             o

    o       o
        o
EXPECTED
  [ '21:35', &lt;&lt;'EXPECTED' ],
        o
    o       o

 o             o

h               o

 o             o

    m       o
        o
EXPECTED
  [ '04:59', &lt;&lt;'EXPECTED' ],
        o
    m       o

 o             o

o               o

 o             h

    o       o
        o
EXPECTED
  [ '12:00', &lt;&lt;'EXPECTED' ],
        x
    o       o

 o             o

o               o

 o             o

    o       o
        o
EXPECTED
  [ '03:03', &lt;&lt;'EXPECTED' ],
        m
    o       o

 o             o

o               h

 o             o

    o       o
        o
EXPECTED
  [ '21:08', &lt;&lt;'EXPECTED' ],
        o
    o       m

 o             o

h               o

 o             o

    o       o
        o
EXPECTED
  [ '23:05', &lt;&lt;'EXPECTED' ],
        o
    h       m

 o             o

o               o

 o             o

    o       o
        o
EXPECTED
  [ '16:24', &lt;&lt;'EXPECTED' ],
        o
    o       o

 o             o

o               o

 o             x

    o       o
        o
EXPECTED
  [ '13:06', &lt;&lt;'EXPECTED' ],
        o
    o       x

 o             o

o               o

 o             o

    o       o
        o
EXPECTED
  [ '18:00', &lt;&lt;'EXPECTED' ],
        m
    o       o

 o             o

o               o

 o             o

    o       o
        h
EXPECTED
  [ '22:26', &lt;&lt;'EXPECTED' ],
        o
    o       o

 h             o

o               o

 o             o

    o       m
        o
EXPECTED
  [ '20:10', &lt;&lt;'EXPECTED' ],
        o
    o       o

 o             m

o               o

 h             o

    o       o
        o
EXPECTED
);
for my $r (@testdata) {
    print $r-&gt;[0], "\n";
    build_file($r-&gt;[0]);
    my $got = `$cmd`;
    chomp($got);chomp($got);chomp($got);$got.="\n";
    $got eq $r-&gt;[1] or die "expected:\n$r-&gt;[1]got:\n$got";
}
print "successful\n";
&lt;/CODE&gt;
&lt;/P&gt;

&lt;P&gt;
You can test possible solutions by running:
&lt;CODE&gt;
perl test.pl mysolution.pl
&lt;/CODE&gt;
&lt;/P&gt;

&lt;P&gt;
Note that the 132 stroke Perl solution given above is just a random example solution
to give you a working solution to this problem.
Better approaches are available.
&lt;/P&gt;

&lt;P&gt;
Please feel free to golf this code.
Or speculate on the general approach I took to get down to 101 strokes.
If you do happen to speculate correctly, I'd be happy to congratulate you
and confirm a correct speculation.
I'm writing this node for fun and to see if the above two wildly-off-the-mark speculations
are really representative ... or if most golfers can speculate rather
better than that. :-)
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;References&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
Update: After this node was written, I described most
of the interesting solutions I'm aware of for both
the Saving Time and 99 Bottles of Beer golf games at:
 &lt;ul&gt;
  &lt;li&gt; [id://811919] (Saving Time: Perl)
  &lt;li&gt; [id://814900] (Saving Time: Python, Ruby, PHP)
  &lt;li&gt; [id://962854] (More Saving Time: Perl)
  &lt;li&gt; [id://903641] (99 Bottles of Beer: Perl, Python, Ruby)
 &lt;/ul&gt;
&lt;/P&gt;

&lt;/readmore&gt;
</field>
</data>
</node>
