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
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 matters0 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 { | } ~
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.
subroutine should print the output or return it as a string#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
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: (Golf) ranging on alphabet
by japhy (Canon) on Sep 27, 2001 at 07:59 UTC | |
by jynx (Priest) on Sep 27, 2001 at 08:46 UTC | |
by flgr (Sexton) on Sep 27, 2001 at 17:17 UTC | |
by suaveant (Parson) on Sep 27, 2001 at 17:45 UTC |