<?xml version="1.0" encoding="windows-1252"?>
<node id="962854" title="Spending Time on Saving Time [golf]" created="2012-04-01 03:14:53" updated="2012-04-01 03:14:53">
<type id="120">
perlmeditation</type>
<author id="176576">
eyepopslikeamosquito</author>
<data>
<field name="doctext">
&lt;P&gt;
While goofing off the other day, idly browsing the classic
[id://811919|Saving Time golf game], I realized some important
analysis was missing.
I'd been obsessed with magic formulae back then
and hadn't properly investigated a lookup table approach.
&lt;/P&gt;

&lt;P&gt;
In most golf games you see,
there is an ongoing battle between two competing approaches,
namely a formula (often magic) and a lookup table
(usually a string).
Sometimes a [id://768354|hybrid approach] wins.
&lt;/P&gt;

&lt;P&gt;
In this node, I'll focus on the lookup table approach.
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;The Problem&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
To refresh your memory, the program in this game must draw an
analogue clock face using the 24 hour digital time provided on stdin.
The format of the input time is HH:MM followed by a single newline.
&lt;/P&gt;

&lt;P&gt;
An input time of 21:35, for example, is displayed as:
&lt;CODE&gt;
        o
    o       o

 o             o

h               o

 o             o

    m       o
        o
&lt;/CODE&gt;
If the hour and minute happen to fall on the same mark, they must be drawn with an 'x'.
For example, 01:06 is rendered as:
&lt;CODE&gt;
        o
    o       x

 o             o

o               o

 o             o

    o       o
        o
&lt;/CODE&gt;
&lt;/P&gt;

&lt;P&gt;
To more precisely clarify the required behavior of a passing entry, see the
test program provided [id://785052|here].
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Printing the Clock Face on the Fly&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
In this node, I'll focus on printing the clock face on the fly.
Though a two-dimensional array seems to produce the shortest
solutions, that approach has already been analyzed to death [id://811919|previously].
&lt;/P&gt;

&lt;P&gt;
Moreover, I find drawing the clock face on the fly
morbidly fascinating for some reason, perhaps because
the 0, 11, 1, 10, 2, 9, 3, 8, 4, 7, 5, 6 sequence
is so annoying.
As you can see below, there is no avoiding this dreaded
sequence if you wish to print the clock face on the fly:
&lt;CODE&gt;
        0
   11       1

10             2

9               3

 8             4

    7       5
        6
&lt;/CODE&gt;
&lt;/P&gt;

&lt;P&gt;
Here are the three basic sequences required in this golf:
&lt;/P&gt;

&lt;P&gt;
&lt;table border="1"&gt;
 &lt;tr&gt;&lt;th&gt;Index&lt;/th&gt;&lt;th&gt;dreaded ordering&lt;/th&gt;&lt;th&gt;leading spaces&lt;/th&gt;&lt;th&gt;trailing newlines&lt;/th&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;3&lt;/td&gt;&lt;td&gt;15&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;13&lt;/td&gt;&lt;td&gt;2&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;9&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;4&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;5&lt;/td&gt;&lt;td&gt;7&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;11&lt;/td&gt;&lt;td&gt;6&lt;/td&gt;&lt;td&gt;8&lt;/td&gt;&lt;td&gt;0+&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/P&gt;

&lt;P&gt;
Notice that generating the dreaded ordering, the number of leading spaces,
and the number of trailing newlines may be thought of as three
separate sub-problems.
Indeed, it is common in any complex golf to analyze
smaller sub-problems separately before plugging them
in to form a complete solution. Divide and conquer.
&lt;/P&gt;


&lt;P&gt;&lt;B&gt;Sub-problem 1: Trailing Newlines&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
I trust the picture below clarifies the required
number of trailing newlines to be printed after
each clock face mark:
&lt;CODE&gt;
        1
    0       2

 0             2

0               2

 0             2

    0       1
        0
&lt;/CODE&gt;
Note that the last zero above,
corresponding to clock face mark six,
can be any value greater than or equal to zero
because all trailing newlines after the clock face
is drawn are ignored.
&lt;/P&gt;

&lt;P&gt;
To analyze this sub-problem as a separate, standalone golf,
simply run the following test program:
&lt;CODE&gt;
for my $i ( map {$_,11-$_} 0..5 ) {
   $x = ($i&lt;6)+($i&amp;&amp;$i&lt;5);
   printf "%2d: %d\n", $i, 0+$x;
}
&lt;/CODE&gt;
producing:
&lt;CODE&gt;
 0: 1
11: 0
 1: 2
10: 0
 2: 2
 9: 0
 3: 2
 8: 0
 4: 2
 7: 0
 5: 1
 6: 0
&lt;/CODE&gt;
which matches the required number of trailing newlines for
each clock face mark.
&lt;/P&gt;

&lt;P&gt;
In this little sub-golf, replacing &lt;C&gt;($i&lt;6)+($i&amp;&amp;$i&lt;5)&lt;/C&gt; above
with another (shorter) expression would enable you to take
the lead.
&lt;/P&gt;

&lt;P&gt;
We can easily shorten the formula above by
two strokes from 17 to 15 by eliminating
one set of parens:
&lt;CODE&gt;
12345678901234567
($i&lt;6)+($i&amp;&amp;$i&lt;5)
--$|+($i&amp;&amp;$i&lt;5)
--$|+($i&lt;5)-!$i
&lt;/CODE&gt;
where &lt;C&gt;--$|&lt;/C&gt; is
the famous [id://778841|magical flip-flop].
Can you find a shorter formula?
&lt;/P&gt;

&lt;P&gt;
Can we do better via a lookup table?
Well, noticing that the sequence changes
from &lt;C&gt;102020202010&lt;/C&gt; to &lt;C&gt;122221000000&lt;/C&gt;
when placed in index order, we can exploit
empty values for the last six values like so:
&lt;CODE&gt;
123456789012345678
substr 122221,$i,1
(1,2,2,2,2,1)[$i]
(1,(2)x4,1)[$i]
vec'XX',$i,2
&lt;/CODE&gt;
where &lt;C&gt;XX&lt;/C&gt; above is a string with ord values 169, 6.
So good ol' &lt;C&gt;vec&lt;/C&gt; looks like a winner here, weighing
in at only 12 strokes!
Generally, the &lt;C&gt;vec&lt;/C&gt; function is too often overlooked
in golf games, perhaps because it is little used outside
of golf.
&lt;/P&gt;

&lt;P&gt;
So it seems that a lookup table defeats a formula in this sub-golf ...
unless you can find a shorter formula, that is.
In the spirit of TMTOWTDI, I would be interested
to see different, even if longer, approaches to
producing this sequence.
&lt;/P&gt;

&lt;readmore&gt;

&lt;P&gt;&lt;B&gt;Sub-problem 2: The Dreaded Ordering&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
To analyze this sub-problem as a separate, standalone golf,
run the following test program:
&lt;CODE&gt;
for ( 0..11 ) {
   printf "%2d: %2d\n", $_, 0+$x;
   $x = 11-$x+$_%2;
}
&lt;/CODE&gt;
producing:
&lt;CODE&gt;
 0:  0
 1: 11
 2:  1
 3: 10
 4:  2
 5:  9
 6:  3
 7:  8
 8:  4
 9:  7
10:  5
11:  6
&lt;/CODE&gt;
which matches the dreaded ordering.
Notice that this formula exploits that an uninitialized
Perl variable, namely &lt;C&gt;$x&lt;/C&gt; above, starts out
with an empty value (undef).
&lt;/P&gt;

&lt;P&gt;
As before, we can replace &lt;C&gt;$_%2&lt;/C&gt; with
the &lt;C&gt;$|--&lt;/C&gt; [id://778841|magical flip-flop]
to produce an alternative 10-stroker:
&lt;CODE&gt;
1234567890
11-$x+$_%2
11-$x+$|--
&lt;/CODE&gt;
I can't find anything shorter though.
Can you?
&lt;/P&gt;

&lt;P&gt;
Formula versus lookup table is an over-simplification in that
sometimes you can &lt;I&gt;generate&lt;/I&gt; a sequence.
For example, the map below:
&lt;CODE&gt;
12345678901234567
map{$_,11-$_}0..5
&lt;/CODE&gt;
generates the dreaded ordering.
Though longer, this sequence generation is still
competitive in this game because it allows other
shortenings elsewhere in a complete solution,
as we shall see later.
&lt;/P&gt;

&lt;P&gt;
What about a lookup table?
Unfortunately, we need four bits,
rather than just two for the trailing newline
&lt;C&gt;vec&lt;/C&gt; encoding of the previous section,
because the dreaded ordering values have
a wider range, 0..11.
So a &lt;C&gt;vec&lt;/C&gt; lookup table solution
for the dreaded ordering looks like this:
&lt;CODE&gt;
1234567890123456
vec'XXXXXX',$i,4
&lt;/CODE&gt;
where &lt;C&gt;XXXXXX&lt;/C&gt; is a string with ord
values 176, 161, 146, 131, 116, 101 ...
which is six strokes longer than the formula.
&lt;/P&gt;

&lt;P&gt;
So this time the formula defeats the lookup string.
One all.
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Sub-problem 3: Leading Spaces&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
The on-the-fly leading space
sequence of 8, 4, 7, 1, 13, 0, 15, 1, 13, 4, 7, 8
as in:
&lt;CODE&gt;
        8
    4       7

 1            13

0              15

 1            13

    4       7
        8
&lt;/CODE&gt;
is all over the shop.
So much so that I couldn't even begin to contemplate
a short formula to produce it.
&lt;/P&gt;

&lt;P&gt;
As before though, a &lt;C&gt;vec&lt;/C&gt; lookup string can do it
easily because, luckily, all the leading space values
happen to be less than 16 and so (just) fit into four bits.
That is, running:
&lt;CODE&gt;
for my $i ( map {$_,11-$_} 0..5 ) {
   $x = vec'XXXXXX',$i,4;
   printf "%2d: %2d\n", $i, 0+$x;
}
&lt;/CODE&gt;
where &lt;C&gt;XXXXXX&lt;/C&gt; is a string with ord
values 120, 253, 125, 72, 1, 65 produces:
&lt;CODE&gt;
 0:  8
11:  4
 1:  7
10:  1
 2: 13
 9:  0
 3: 15
 8:  1
 4: 13
 7:  4
 5:  7
 6:  8
&lt;/CODE&gt;
Notice that the lookup string solutions to all
three sub-problems use a very similar &lt;C&gt;vec&lt;/C&gt;
construction, so it may be possible to combine
them in the full solution.
Golfers should always be on the lookout for
any uniformity that might be exploited.
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Complete Solutions&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
The two best on-the-fly solutions found in [id://811919|my original analysis]
were a 101 stroke magic formula solution:
&lt;CODE&gt;
print$"x(318%$_/9),(($_-$`)%12?o:x)&amp;($_%12^$'/5?o:'}'),$/x($_/85)for unpack&lt;&gt;!~/:/.C12,'XXXXXXXXXXXX'
&lt;/CODE&gt;
and a 102 stroke "baby cart" magic printf string solution:
&lt;CODE&gt;
printf"%@{[.1*vec'XXXXXXXXXXXX',$_,8]}s",($_^$`%12?g:p)&amp;($_^$'/5?g:u)|"H

"for map{$_,11-$_}&lt;&gt;!~/:/..5
&lt;/CODE&gt;
Can we improve on these two via a lookup table?
Yes!
&lt;/P&gt;

&lt;P&gt;
The first obvious attempt is to combine the
&lt;C&gt;vec&lt;/C&gt; solutions from sub-problems one, two and
three above.
When you do that, uniformly encoding 4 bits per value,
you get to 100 strokes right away:
&lt;CODE&gt;
sub k{$k=vec'AAAAAAAAAAAAAAAAAA',$i++,4}print$/x k,$"x k,(k^$`%12?o:x)&amp;($k^$'/5?o:"}")for&lt;&gt;!~/:/..11
&lt;/CODE&gt;
where &lt;C&gt;AAAAAAAAAAAAAAAAAA&lt;/C&gt; is an eighteen character string with
ord values 128,  16, 180, 112,  33, 161, 208,  34, 144, 240, 35, 129,
208,  36, 116, 112,  21, 104.
&lt;/P&gt;

&lt;P&gt;
Notice that we switched from trailing newlines to leading
newlines to save one stroke, namely a space before
the &lt;C&gt;for&lt;/C&gt; keyword.
&lt;/P&gt;

&lt;P&gt;
Here's an alternative that's just one stroke longer:
&lt;CODE&gt;
print+($/x($k=vec'AAAAAAAAAAAAAAAAAA',$_,4),$"x$k,($k^$`%12?o:x)&amp;($k^$'/5?o:"}"))[$_%3]for&lt;&gt;!~/:/..35
&lt;/CODE&gt;
&lt;/P&gt;

&lt;P&gt;
One more longer still is:
&lt;CODE&gt;
map{$k=vec'BBBBBBBBBBBBBBBBBBB',$_,4;print$_%3?($"^='*')x$k:($k^$`%12?o:x)&amp;($k^$'/5?o:"}")}&lt;&gt;=~/:/..36
&lt;/CODE&gt;
where &lt;C&gt;BBBBBBBBBBBBBBBBBBB&lt;/C&gt; is a 19 character string with ord values
0, 8, 65, 11, 23, 18, 10, 45, 2, 9, 63, 18, 8, 77, 66, 7, 87, 129, 6.
&lt;/P&gt;

&lt;P&gt;
It's possible I've overlooked a shorter way to avoid
multiple calls of &lt;C&gt;vec&lt;/C&gt;.
&lt;/P&gt;

&lt;P&gt;
Next, we can try using two separate &lt;C&gt;vec&lt;/C&gt;'s for the
leading spaces and trailing newlines respectively,
combined with our winning dreaded ordering formula:
&lt;CODE&gt;
print$"x(vec'CCCCCC',$z,4),($`%12^$z?o:x)&amp;($'/5^$z?o:"}"),$/x(vec'EEE',$z=11-$z+$|--,2)for&lt;&gt;!~/:/..11
&lt;/CODE&gt;
where &lt;C&gt;CCCCCC&lt;/C&gt; is a six character string with ord
values 120, 253, 125, 72, 1, 65
and &lt;C&gt;EEE&lt;/C&gt; is a string with ord
values 0, 144, 106.
101 strokes.
Using our &lt;C&gt;map&lt;/C&gt; generator turns out to be one stroke longer:
&lt;CODE&gt;
print$"x(vec'CCCCCC',$_,4),($`%12^$_?o:x)&amp;($'/5^$_?o:"}"),$/x(vec'FF',$_,2)for map{$_,11-$_}&lt;&gt;!~/:/..5
&lt;/CODE&gt;
where &lt;C&gt;FF&lt;/C&gt; is a string with ord
values 169, 6.
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Treating the Clock Face as a Long String&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
There is yet another promising approach to this game:
treat the clock face as a single long string.
If you do that, the character positions in the string
of each clock face mark are shown below:
&lt;CODE&gt;
        8
   14      22

 26           40

43             59

 63           77

   84      92
       102
&lt;/CODE&gt;
with newlines at character positions:
9, 23, 24, 41, 42, 60, 61, 78, 79, 93.
&lt;/P&gt;

&lt;P&gt;
By ignoring newlines, we can reduce the
string length to less than 100,
the character positions now being:
&lt;CODE&gt;
        8
   13      21

 23           37

38             54

 56           70

   75      83
       92
&lt;/CODE&gt;
&lt;/P&gt;

&lt;P&gt;
How does that help?
Well, if you place the clock face mark character
positions in a lookup string in just the right order,
you can derive the dreaded ordering from
the return value of the Perl &lt;C&gt;index&lt;/C&gt; function!
And thus avoid having to generate it.
Let's see how that might look:
&lt;CODE&gt;
print+($`%12^($x=index'GGGGGGGGGGGGGGGGGGGGGG',chr)?~$x?$x&lt;12?o:$/:$":x)&amp;($'/5^$x?o:"}")for&lt;&gt;!~/:/..102
&lt;/CODE&gt;
where &lt;C&gt;GGGGGGGGGGGGGGGGGGGGGG&lt;/C&gt; is
a 22 character string with ord
values 8, 22, 40, 59, 77, 92, 102, 84, 63, 43, 26, 14, 9, 23, 24, 41, 42, 60, 61, 78, 79, 93.
Note that the first twelve values in the string are
the (ordered) clock face mark positions while
the next ten are the position of each newline.
&lt;/P&gt;

&lt;P&gt;
This algorithm simply iterates through
the 103 character clock face string,
one character at a time,
emitting a space, a newline,
or a clock face mark (o, m, h, or x)
at each character position.
&lt;/P&gt;

&lt;P&gt;
By a fluky coincidence, this program happens to be 103 characters
in length, identical in size to the clock face string
it draws! :)
&lt;/P&gt;

&lt;P&gt;
The bitwise string operations used in this solution are a bit tricky.
Hopefully, the table below will help convince you
they are all ok.
In particular, note that SPACE (ord 32) has an especially
lucky power of two bit pattern; bitwise and'ing any
of the letters with it produces a SPACE.
&lt;/P&gt;

&lt;P&gt;
&lt;table border="1"&gt;
 &lt;tr&gt;&lt;th&gt;letter&lt;/th&gt;&lt;th&gt;ord&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;&lt;/th&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;newline&lt;/td&gt;&lt;td&gt;10&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;space&lt;/td&gt;&lt;td&gt;32&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;h&lt;/td&gt;&lt;td&gt;104&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;m&lt;/td&gt;&lt;td&gt;109&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;o&lt;/td&gt;&lt;td&gt;111&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;x&lt;/td&gt;&lt;td&gt;120&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;/tr&gt;
 &lt;tr&gt;&lt;td&gt;}&lt;/td&gt;&lt;td&gt;125&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;td&gt;0&lt;/td&gt;&lt;td&gt;1&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;
&lt;/P&gt;
&lt;P&gt;

&lt;P&gt;
By the way, this character by character approach
is especially well-suited to PHP
(which does not have a string multiply operator)
because it does not require any string multiplication.
The idea for this solution was shown to me by leading
PHP golfer ToastyX.
&lt;/P&gt;

&lt;P&gt;
Elegant though this solution is,
using 22 characters for the lookup string is a bit
extravagant. Can we shorten it somehow?
We can in Perl simply by dropping the newlines from the
lookup string and reverting to generating them via
string multiply:
&lt;CODE&gt;
print~($x=index'DDDDDDDDDDDD',chr)?($`%12^$x?g:p)&amp;($'/5^$x?g:u)|H.$/x(vec'FF',$x,2):$"for&lt;&gt;!~/:/..92
&lt;/CODE&gt;
where &lt;C&gt;DDDDDDDDDDDD&lt;/C&gt; is a twelve character string with ord
values 8, 21, 37, 54, 70, 83, 92, 75, 56, 38, 23, 13
and  &lt;C&gt;FF&lt;/C&gt; is a string with ord values 169, 6.
That reduces this approach from 103 down to 100 strokes.
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;Summary&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
As discussed above and in [id://811919|my previous analysis],
there are at least ten different ways to
solve this problem in around 100 strokes.
To me, that shows that this was a very
well designed golf.
Kudos to Arpad Ray for composing it.
&lt;/P&gt;

&lt;P&gt;
Also interesting is that from over 100 entries,
only three golfers managed to get below 110 strokes,
indicating that this was one of the more difficult golfs.
&lt;/P&gt;

&lt;P&gt;&lt;B&gt;References&lt;/B&gt;&lt;/P&gt;

&lt;P&gt;
&lt;ul&gt;
  &lt;li&gt; [id://759963]
  &lt;li&gt; [id://761053]
  &lt;li&gt; [id://762180]
  &lt;li&gt; [id://763105]
  &lt;li&gt; [id://811919]
  &lt;li&gt; [id://814900]
  &lt;li&gt; [id://816630]
  &lt;li&gt; [id://785052]
  &lt;li&gt; [id://903641]
&lt;/ul&gt;
&lt;/P&gt;

&lt;P&gt;
&lt;ul&gt;
  &lt;li&gt; &lt;a href="http://www.jakevoytko.com/blog/2008/08/25/code-golf-my-thought-process-on-saving-time/"&gt;jakevoytko Python Saving Time blog&lt;/a&gt;
  &lt;li&gt; &lt;a href="http://blachan.com/blog/code-golf-saving-time/"&gt;Abdulla Arif PHP Saving Time blog&lt;/a&gt;
  &lt;li&gt; &lt;a href="http://dinomite.net/2008/code-golf-saving-time/"&gt;Drew Stephens Perl Saving Time blog&lt;/a&gt;
  &lt;li&gt; &lt;a href="http://thingsithoughtidsharewithyou.blogspot.com/2009/07/some-code-golf.html"&gt;Tobias Lofgren Perl Saving Time blog&lt;/a&gt;
  &lt;li&gt; &lt;a href="http://codegolf.stackexchange.com/questions/3679/codegolf-com-saving-time"&gt;stackexchange saving time question&lt;/a&gt;
&lt;/ul&gt;
&lt;/P&gt;

&lt;/readmore&gt;
</field>
</data>
</node>
