Ok... I have decided to try creating a golf hole...

Given an alphabet and a list of letters create a comma separated ranged list that represents that list.

Since that probably makes little sense, write a subroutine that takes two array refs, the first array ref contains an alphabet, in it's proper order. To constrain it the alphabet will contain ther letters

0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R +S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~
that is the range of chars 0x30..0x7e. The alphabet will contain some or all of these letters, and the order they are in the array is their order in the alphabet. There will be no duplicates, case matters

The second array ref will contain any number of these characters, possibly duplicated. You're subroutine should compile them into a list, comma separated and in the order of the alphabet. Anywhere there is a run of characters in a row, you should replace it with a range. Squash any duplicates.

Here is an example.

#alphabet @alpha = split '', 'G;_0x}snafuU='; @list = split '', 'snafu_G0}U'; s(\@alpha,\@list); # prints # G,_..0,}..U # or if it is easier to , a run of 2 # G,_,0,}..U
subroutine should print the output or return it as a string

This is my first attept to create a golf hole, so forgive me if snags occur :)

Update Doh, japhy caught an error in my example... should be good now.

Update2 to be nice to japhy, your golf may return the value instead of print it...

                - Ant
                - Some of my best work - Fish Dinner


In reply to (Golf) ranging on alphabet by suaveant

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!
  • 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, details, 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, summary, 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.