Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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.

-- "SplinterFL" comments on the codegolf 99 bottles of beer game

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.

-- Abdulla Arif comments on the codegolf savingtime game

Don't assume. It makes an "ass" out of "u" and "me".

-- David Brent in The Office

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".

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.

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 Beth's many insightful responses where she perceptively noted that:

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.

Anyway, after reading Abdulla's 234 char PHP solution to the codegolf Saving Time challenge, namely:

<?fscanf(STDIN,'%d:%d',$h,$m);$s=array_combine(str_split('0b1a29384756 +'),array_fill(0,12,'o'));$s[$h=dechex($h>11?$h-12:$h)]='h';$s[$m=dech +ex($m>59?0:$m/5)]=$h==$m?'x':'m';vprintf("%9s %5s%8s %s%14s %s%16s %s%14s %5s%8s %9s",$s) ?>
I refined his interesting approach into a (shortened) 132 stroke Perl solution as follows:
<>=~/:/;@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

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:

# use strict; use warnings; my $testprog = shift or die "usage: $0 program-file\n"; my $datafile = 'tt.txt'; my $cmd = "perl $testprog <$datafile"; sub build_file { my $contents = shift; open(my $fh, '>', $datafile) or die "open '$datafile': $!"; print $fh "$contents\n"; close($fh); } print "Testing $testprog, size=", -s $testprog, " bytes.\n"; my @testdata = ( [ '00:00', <<'EXPECTED' ], x o o o o o o o o o o o EXPECTED [ '23:59', <<'EXPECTED' ], o x o o o o o o o o o o EXPECTED [ '21:35', <<'EXPECTED' ], o o o o o h o o o m o o EXPECTED [ '04:59', <<'EXPECTED' ], o m o o o o o o h o o o EXPECTED [ '12:00', <<'EXPECTED' ], x o o o o o o o o o o o EXPECTED [ '03:03', <<'EXPECTED' ], m o o o o o h o o o o o EXPECTED [ '21:08', <<'EXPECTED' ], o o m o o h o o o o o o EXPECTED [ '23:05', <<'EXPECTED' ], o h m o o o o o o o o o EXPECTED [ '16:24', <<'EXPECTED' ], o o o o o o o o x o o o EXPECTED [ '13:06', <<'EXPECTED' ], o o x o o o o o o o o o EXPECTED [ '18:00', <<'EXPECTED' ], m o o o o o o o o o o h EXPECTED [ '22:26', <<'EXPECTED' ], o o o h o o o o o o m o EXPECTED [ '20:10', <<'EXPECTED' ], o o o o m o o h o o o o EXPECTED ); for my $r (@testdata) { print $r->[0], "\n"; build_file($r->[0]); my $got = `$cmd`; chomp($got);chomp($got);chomp($got);$got.="\n"; $got eq $r->[1] or die "expected:\n$r->[1]got:\n$got"; } print "successful\n";

You can test possible solutions by running:


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.

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. :-)


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:

In reply to When One Golfer Speculates On What Another Is Doing... by eyepopslikeamosquito

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (2)
    As of 2018-02-25 04:29 GMT
    Find Nodes?
      Voting Booth?
      When it is dark outside I am happiest to see ...

      Results (312 votes). Check out past polls.