Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Display a sequence of digits that contains every 2-digit pair once only. A sample program is provided.

To clarify, the output must contain all 100 combinations of two digits. It must contain '01' and '10', for example, but '010' would count for both of those pairs. '0110' would count as containing '01', '11', and '10'.

A two stroke bonus will be awarded for a sequence that is not just a (00..99).

Update: I fixed (well, bodged) my solution! Also, the two-stroke bonus is rather pointless, as other solutions are shorter anyway. My lack of imagination there, I'm afraid. I should have said "for code that does not itself contain any 2-digit pairs". Is it unfair to change the rules now? I don't think it changes the running order ATM.

for ('00'..'89'){ if (index($str,$_)<0) { if (index($str.substr($_,0,1),$_)<0) { if (index($str.substr($_,1,1),$_)<0) { $str.=$_; } else { $str.=substr($_,1,1); } } else { $str.=substr($_,0,1); } } } print $str.'90';

I can get within a dozen characters of a hard-coded print statement (138 strokes):
123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678
Can you do better?

Update: Fixed dumb mistake - missing '' around ..

Update: I believe that BrowserUK is in the lead so far, but I have just discovered that my solution was flawed, as it duplicated '09'.

Update: Dragonchild has also posted a correct solution, and a checker.

Update: Someone has taken the lead with an astonishing 28 characters! Who is that masked monk?

Here is some code that you can use to test your output:

$s = (<>); for('00'..'99'){print $_." missing\n" if $s!~/$_/} for('00'..'99'){print $_." duplicated\n" if index($s,$_) >= 0 and inde +x($s,$_,index($s,$_)+1) >= 0}

In reply to Friday Golf: All 2-digit combinations by PhilHibbs

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 scrutinizing the Monastery: (6)
    As of 2017-08-18 21:25 GMT
    Find Nodes?
      Voting Booth?
      Who is your favorite scientist and why?

      Results (310 votes). Check out past polls.