Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

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';
Output:
00102030405060708091121314151617181922324252627282933435363738394454647484955657585966768697787988990

I can get within a dozen characters of a hard-coded print statement (138 strokes):
for('00'..'89'){if($s!~/$_/){($a,$b)=/(.)(.)/;if(($s.$a)!~/$_/){if(($s.$b)!~/$_/){$s.=$_}else{$s.=$b}}else{$s.=$a}}}print$s.'90'
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

Title:
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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2014-07-10 03:35 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      When choosing user names for websites, I prefer to use:








      Results (198 votes), past polls